cli: search: Convert --output to keyword argument

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.
This commit is contained in:
Michal Sojka 2014-11-05 01:25:56 +01:00 committed by David Bremner
parent 5c27136e64
commit 5c32365d87
2 changed files with 13 additions and 15 deletions

View file

@ -78,9 +78,6 @@ Supported options for **search** include
by null characters (--format=text0), as a JSON array by null characters (--format=text0), as a JSON array
(--format=json), or as an S-Expression list (--format=sexp). (--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**) ``--sort=``\ (**newest-first**\ \|\ **oldest-first**)
This option can be used to present results in either This option can be used to present results in either
chronological order (**oldest-first**) or reverse chronological chronological order (**oldest-first**) or reverse chronological

View file

@ -587,7 +587,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
int opt_index, ret; int opt_index, ret;
notmuch_opt_desc_t options[] = { 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 }, (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },
{ "threads", OUTPUT_THREADS }, { "threads", OUTPUT_THREADS },
{ "messages", OUTPUT_MESSAGES }, { "messages", OUTPUT_MESSAGES },
@ -607,13 +607,11 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
{ 0, 0, 0, 0, 0 } { 0, 0, 0, 0, 0 }
}; };
ctx->output = OUTPUT_SUMMARY;
opt_index = parse_arguments (argc, argv, options, 1); opt_index = parse_arguments (argc, argv, options, 1);
if (opt_index < 0) if (opt_index < 0)
return EXIT_FAILURE; return EXIT_FAILURE;
if (! ctx->output)
ctx->output = OUTPUT_SUMMARY;
if (ctx->output != OUTPUT_FILES && ctx->output != OUTPUT_MESSAGES && if (ctx->output != OUTPUT_FILES && ctx->output != OUTPUT_MESSAGES &&
ctx->dupe != -1) { ctx->dupe != -1) {
fprintf (stderr, "Error: --duplicate=N is only supported with --output=files and --output=messages.\n"); fprintf (stderr, "Error: --duplicate=N is only supported with --output=files and --output=messages.\n");
@ -624,17 +622,20 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
argc - opt_index, argv + opt_index)) argc - opt_index, argv + opt_index))
return EXIT_FAILURE; return EXIT_FAILURE;
if (ctx->output == OUTPUT_SUMMARY || switch (ctx->output) {
ctx->output == OUTPUT_THREADS) case OUTPUT_SUMMARY:
case OUTPUT_THREADS:
ret = do_search_threads (ctx); ret = do_search_threads (ctx);
else if (ctx->output == OUTPUT_MESSAGES || break;
ctx->output == OUTPUT_FILES) case OUTPUT_MESSAGES:
case OUTPUT_FILES:
ret = do_search_messages (ctx); ret = do_search_messages (ctx);
else if (ctx->output == OUTPUT_TAGS) break;
case OUTPUT_TAGS:
ret = do_search_tags (ctx); ret = do_search_tags (ctx);
else { break;
fprintf (stderr, "Error: the combination of outputs is not supported.\n"); default:
ret = 1; INTERNAL_ERROR ("Unexpected output");
} }
_notmuch_search_cleanup (ctx); _notmuch_search_cleanup (ctx);