mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-22 02:48:08 +01:00
cli: add support for --output parameter in notmuch count
Add support for --output=messages (which remains the default) and --output=threads to notmuch count. Signed-off-by: Jani Nikula <jani@nikula.org>
This commit is contained in:
parent
e7328d7b00
commit
386ad3d6a1
4 changed files with 62 additions and 10 deletions
5
NEWS
5
NEWS
|
@ -28,6 +28,11 @@ Add "notmuch search" --offset and --limit options
|
||||||
The search command now takes options --offset=[-]N and --limit=N to limit
|
The search command now takes options --offset=[-]N and --limit=N to limit
|
||||||
the number of results shown.
|
the number of results shown.
|
||||||
|
|
||||||
|
Add "notmuch count --output" option
|
||||||
|
|
||||||
|
The count command is now capable of counting threads in addition to
|
||||||
|
messages. This is selected using the new --output=(threads|messages) option.
|
||||||
|
|
||||||
Optimizations
|
Optimizations
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
|
||||||
notmuch_query_t *query;
|
notmuch_query_t *query;
|
||||||
char *query_str;
|
char *query_str;
|
||||||
int i;
|
int i;
|
||||||
|
notmuch_bool_t output_messages = TRUE;
|
||||||
|
|
||||||
argc--; argv++; /* skip subcommand argument */
|
argc--; argv++; /* skip subcommand argument */
|
||||||
|
|
||||||
|
@ -37,7 +38,17 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
|
||||||
i++;
|
i++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
{
|
if (STRNCMP_LITERAL (argv[i], "--output=") == 0) {
|
||||||
|
const char *opt = argv[i] + sizeof ("--output=") - 1;
|
||||||
|
if (strcmp (opt, "threads") == 0) {
|
||||||
|
output_messages = FALSE;
|
||||||
|
} else if (strcmp (opt, "messages") == 0) {
|
||||||
|
output_messages = TRUE;
|
||||||
|
} else {
|
||||||
|
fprintf (stderr, "Invalid value for --output: %s\n", opt);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
|
fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -71,7 +82,10 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf ("%u\n", notmuch_query_count_messages(query));
|
if (output_messages)
|
||||||
|
printf ("%u\n", notmuch_query_count_messages (query));
|
||||||
|
else
|
||||||
|
printf ("%u\n", notmuch_query_count_threads (query));
|
||||||
|
|
||||||
notmuch_query_destroy (query);
|
notmuch_query_destroy (query);
|
||||||
notmuch_database_close (notmuch);
|
notmuch_database_close (notmuch);
|
||||||
|
|
29
notmuch.1
29
notmuch.1
|
@ -372,14 +372,35 @@ section below for details of the supported syntax for <search-terms>.
|
||||||
.RE
|
.RE
|
||||||
.RS 4
|
.RS 4
|
||||||
.TP 4
|
.TP 4
|
||||||
.BR count " <search-term>..."
|
.BR count " [options...] <search-term>..."
|
||||||
|
|
||||||
Count messages matching the search terms.
|
Count messages matching the search terms.
|
||||||
|
|
||||||
The number of matching messages is output to stdout.
|
The number of matching messages (or threads) is output to stdout.
|
||||||
|
|
||||||
With no search terms, a count of all messages in the database will be
|
With no search terms, a count of all messages (or threads) in the database will
|
||||||
displayed.
|
be displayed.
|
||||||
|
|
||||||
|
Supported options for
|
||||||
|
.B count
|
||||||
|
include
|
||||||
|
.RS 4
|
||||||
|
.TP 4
|
||||||
|
.B \-\-output=(messages|threads)
|
||||||
|
|
||||||
|
.RS 4
|
||||||
|
.TP 4
|
||||||
|
.B messages
|
||||||
|
|
||||||
|
Output the number of matching messages. This is the default.
|
||||||
|
.RE
|
||||||
|
.RS 4
|
||||||
|
.TP 4
|
||||||
|
.B threads
|
||||||
|
|
||||||
|
Output the number of matching threads.
|
||||||
|
.RE
|
||||||
|
.RE
|
||||||
.RE
|
.RE
|
||||||
.RE
|
.RE
|
||||||
|
|
||||||
|
|
20
notmuch.c
20
notmuch.c
|
@ -328,12 +328,24 @@ static command_t commands[] = {
|
||||||
"\tSee \"notmuch help search-terms\" for details of the search\n"
|
"\tSee \"notmuch help search-terms\" for details of the search\n"
|
||||||
"\tterms syntax." },
|
"\tterms syntax." },
|
||||||
{ "count", notmuch_count_command,
|
{ "count", notmuch_count_command,
|
||||||
"<search-terms> [...]",
|
"[options...] <search-terms> [...]",
|
||||||
"Count messages matching the search terms.",
|
"Count messages matching the search terms.",
|
||||||
"\tThe number of matching messages is output to stdout.\n"
|
"\tThe number of matching messages (or threads) is output to stdout.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"\tWith no search terms, a count of all messages in the database\n"
|
"\tWith no search terms, a count of all messages (or threads) in\n"
|
||||||
"\twill be displayed.\n"
|
"\tthe database will be displayed.\n"
|
||||||
|
"\n"
|
||||||
|
"\tSupported options for count include:\n"
|
||||||
|
"\n"
|
||||||
|
"\t--output=(messages|threads)\n"
|
||||||
|
"\n"
|
||||||
|
"\t\tmessages (default)\n"
|
||||||
|
"\n"
|
||||||
|
"\t\tOutput the number of matching messages.\n"
|
||||||
|
"\n"
|
||||||
|
"\t\tthreads\n"
|
||||||
|
"\n"
|
||||||
|
"\t\tOutput the number of matching threads.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"\tSee \"notmuch help search-terms\" for details of the search\n"
|
"\tSee \"notmuch help search-terms\" for details of the search\n"
|
||||||
"\tterms syntax." },
|
"\tterms syntax." },
|
||||||
|
|
Loading…
Reference in a new issue