mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-22 02:48:08 +01:00
cli: search: Convert --output to keyword-flag argument
This converts "notmuch search" to use the recently introduced keyword-flag argument parser. At this point, it only makes the code slightly less readable but following commits that add new --output keywords will profit from this.
This commit is contained in:
parent
ecc4a9a644
commit
db307459fb
1 changed files with 18 additions and 17 deletions
|
@ -23,11 +23,11 @@
|
|||
#include "string-util.h"
|
||||
|
||||
typedef enum {
|
||||
OUTPUT_SUMMARY,
|
||||
OUTPUT_THREADS,
|
||||
OUTPUT_MESSAGES,
|
||||
OUTPUT_FILES,
|
||||
OUTPUT_TAGS
|
||||
OUTPUT_SUMMARY = 1 << 0,
|
||||
OUTPUT_THREADS = 1 << 1,
|
||||
OUTPUT_MESSAGES = 1 << 2,
|
||||
OUTPUT_FILES = 1 << 3,
|
||||
OUTPUT_TAGS = 1 << 4,
|
||||
} output_t;
|
||||
|
||||
typedef struct {
|
||||
|
@ -338,7 +338,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
|
|||
notmuch_database_t *notmuch;
|
||||
search_options_t opt = {
|
||||
.sort = NOTMUCH_SORT_NEWEST_FIRST,
|
||||
.output = OUTPUT_SUMMARY,
|
||||
.output = 0,
|
||||
.offset = 0,
|
||||
.limit = -1, /* unlimited */
|
||||
.dupe = -1,
|
||||
|
@ -367,7 +367,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
|
|||
{ "text0", NOTMUCH_FORMAT_TEXT0 },
|
||||
{ 0, 0 } } },
|
||||
{ NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 },
|
||||
{ NOTMUCH_OPT_KEYWORD, &opt.output, "output", 'o',
|
||||
{ NOTMUCH_OPT_KEYWORD_FLAGS, &opt.output, "output", 'o',
|
||||
(notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },
|
||||
{ "threads", OUTPUT_THREADS },
|
||||
{ "messages", OUTPUT_MESSAGES },
|
||||
|
@ -390,6 +390,9 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
|
|||
if (opt_index < 0)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if (! opt.output)
|
||||
opt.output = OUTPUT_SUMMARY;
|
||||
|
||||
switch (format_sel) {
|
||||
case NOTMUCH_FORMAT_TEXT:
|
||||
opt.format = sprinter_text_create (config, stdout);
|
||||
|
@ -455,19 +458,17 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
|
|||
notmuch_query_set_omit_excluded (opt.query, exclude);
|
||||
}
|
||||
|
||||
switch (opt.output) {
|
||||
default:
|
||||
case OUTPUT_SUMMARY:
|
||||
case OUTPUT_THREADS:
|
||||
if (opt.output == OUTPUT_SUMMARY ||
|
||||
opt.output == OUTPUT_THREADS)
|
||||
ret = do_search_threads (&opt);
|
||||
break;
|
||||
case OUTPUT_MESSAGES:
|
||||
case OUTPUT_FILES:
|
||||
else if (opt.output == OUTPUT_MESSAGES ||
|
||||
opt.output == OUTPUT_FILES)
|
||||
ret = do_search_messages (&opt);
|
||||
break;
|
||||
case OUTPUT_TAGS:
|
||||
else if (opt.output == OUTPUT_TAGS)
|
||||
ret = do_search_tags (notmuch, &opt);
|
||||
break;
|
||||
else {
|
||||
fprintf (stderr, "Error: the combination of outputs is not supported.\n");
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
notmuch_query_destroy (opt.query);
|
||||
|
|
Loading…
Reference in a new issue