[PATCH 07/10] cli: search: Convert --output to keyword argument
Michal Sojka
sojkam1 at fel.cvut.cz
Sat Nov 1 17:49:57 PDT 2014
Now, when address related outputs are in a separate command, it makes
no sense to combine multiple --output options in search command line.
Using switch statement to handle different outputs is more readable
than a series of if statements.
---
doc/man1/notmuch-search.rst | 3 ---
notmuch-search.c | 25 +++++++++++++------------
2 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/doc/man1/notmuch-search.rst b/doc/man1/notmuch-search.rst
index e919811..e7b5ad4 100644
--- a/doc/man1/notmuch-search.rst
+++ b/doc/man1/notmuch-search.rst
@@ -78,9 +78,6 @@ Supported options for **search** include
by null characters (--format=text0), as a JSON array
(--format=json), or as an S-Expression list (--format=sexp).
- This option can be given multiple times to combine different
- outputs.
-
``--sort=``\ (**newest-first**\ \|\ **oldest-first**)
This option can be used to present results in either
chronological order (**oldest-first**) or reverse chronological
diff --git a/notmuch-search.c b/notmuch-search.c
index 7a78ecd..4b9a372 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -572,7 +572,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
int opt_index, ret;
notmuch_opt_desc_t options[] = {
- { NOTMUCH_OPT_KEYWORD_FLAGS, &ctx->output, "output", 'o',
+ { NOTMUCH_OPT_KEYWORD, &ctx->output, "output", 'o',
(notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },
{ "threads", OUTPUT_THREADS },
{ "messages", OUTPUT_MESSAGES },
@@ -586,28 +586,29 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
{ 0, 0, 0, 0, 0 }
};
+ ctx->output = OUTPUT_SUMMARY;
opt_index = parse_arguments (argc, argv, options, 1);
if (opt_index < 0)
return EXIT_FAILURE;
- if (! ctx->output)
- ctx->output = OUTPUT_SUMMARY;
-
if (_notmuch_search_prepare (ctx, config,
argc - opt_index, argv + opt_index))
return EXIT_FAILURE;
- if (ctx->output == OUTPUT_SUMMARY ||
- ctx->output == OUTPUT_THREADS)
+ switch (ctx->output) {
+ case OUTPUT_SUMMARY:
+ case OUTPUT_THREADS:
ret = do_search_threads (ctx);
- else if (ctx->output == OUTPUT_MESSAGES ||
- ctx->output == OUTPUT_FILES)
+ break;
+ case OUTPUT_MESSAGES:
+ case OUTPUT_FILES:
ret = do_search_messages (ctx);
- else if (ctx->output == OUTPUT_TAGS)
+ break;
+ case OUTPUT_TAGS:
ret = do_search_tags (ctx);
- else {
- fprintf (stderr, "Error: the combination of outputs is not supported.\n");
- ret = 1;
+ break;
+ default:
+ INTERNAL_ERROR ("Unexpected output");
}
_notmuch_search_cleanup (ctx);
--
2.1.1
More information about the notmuch
mailing list