]> rtime.felk.cvut.cz Git - notmuch.git/blobdiff - notmuch-search.c
cli: search: Convert --output to keyword argument
[notmuch.git] / notmuch-search.c
index 69938d67be154302df04481329a8ba9124c7ac30..e084d258996cd97880969f81450a3af52300f332 100644 (file)
@@ -587,7 +587,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 },
@@ -607,13 +607,11 @@ 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 (ctx->output != OUTPUT_FILES && ctx->output != OUTPUT_MESSAGES &&
        ctx->dupe != -1) {
         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))
        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);