aboutsummaryrefslogtreecommitdiffhomepage
path: root/notmuch-count.c
diff options
context:
space:
mode:
authorGravatar Jani Nikula <jani@nikula.org>2011-11-15 22:08:51 +0200
committerGravatar David Bremner <bremner@debian.org>2011-11-15 19:20:27 -0400
commit386ad3d6a1a4aff086a87c04c225aba4fa85fb4c (patch)
tree6d58875aa6d92a7a45d0eac278834ce822c98df4 /notmuch-count.c
parente7328d7b006cc54d2cff249a601b114ee341b1db (diff)
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>
Diffstat (limited to 'notmuch-count.c')
-rw-r--r--notmuch-count.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/notmuch-count.c b/notmuch-count.c
index a35be404..20ce3342 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -29,6 +29,7 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
notmuch_query_t *query;
char *query_str;
int i;
+ notmuch_bool_t output_messages = TRUE;
argc--; argv++; /* skip subcommand argument */
@@ -37,7 +38,17 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
i++;
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]);
return 1;
}
@@ -71,7 +82,10 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
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_database_close (notmuch);