diff options
author | Jani Nikula <jani@nikula.org> | 2017-10-01 23:53:11 +0300 |
---|---|---|
committer | David Bremner <david@tethera.net> | 2017-10-04 22:00:42 -0300 |
commit | 4a6721970a42a9f86149fb5d395d1001fed2d305 (patch) | |
tree | 7ee198f5d38f841a580f9b9e30cce5999e8e74cd /notmuch-show.c | |
parent | d57da17fcd30a5cbe191ccd42906e489dd2bd6a3 (diff) |
cli: use designated initializers for opt desc
Several changes at once, just to not have to change the same lines
several times over:
- Use designated initializers to initialize opt desc arrays.
- Only initialize the needed fields.
- Remove arg_id (short options) as unused.
- Replace opt_type and output_var with several type safe output
variables, where the output variable being non-NULL determines the
type. Introduce checks to ensure only one is set. The downside is
some waste of const space per argument; this could be saved by
retaining opt_type and using a union, but that's still pretty
verbose.
- Fix some variables due to the type safety. Mostly a good thing, but
leads to some enums being changed to ints. This is pedantically
correct, but somewhat annoying. We could also cast, but that defeats
the purpose a bit.
- Terminate the opt desc arrays using {}.
The output variable type safety and the ability to add new fields for
just some output types or arguments are the big wins. For example, if
we wanted to add a variable to set when the argument is present, we
could do so for just the arguments that need it.
Beauty is in the eye of the beholder, but I think this looks nice when
defining the arguments, and reduces some of the verbosity we have
there.
Diffstat (limited to 'notmuch-show.c')
-rw-r--r-- | notmuch-show.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/notmuch-show.c b/notmuch-show.c index cdcc2a98..367536ff 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -1093,23 +1093,23 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) notmuch_bool_t single_message; notmuch_opt_desc_t options[] = { - { NOTMUCH_OPT_KEYWORD, &format, "format", 'f', + { .opt_keyword = &format, .name = "format", .keywords = (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON }, { "text", NOTMUCH_FORMAT_TEXT }, { "sexp", NOTMUCH_FORMAT_SEXP }, { "mbox", NOTMUCH_FORMAT_MBOX }, { "raw", NOTMUCH_FORMAT_RAW }, { 0, 0 } } }, - { NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 }, - { NOTMUCH_OPT_BOOLEAN, &exclude, "exclude", 'x', 0 }, - { NOTMUCH_OPT_BOOLEAN, &entire_thread, "entire-thread", 't', 0 }, - { NOTMUCH_OPT_INT, ¶ms.part, "part", 'p', 0 }, - { NOTMUCH_OPT_BOOLEAN, ¶ms.crypto.decrypt, "decrypt", 'd', 0 }, - { NOTMUCH_OPT_BOOLEAN, ¶ms.crypto.verify, "verify", 'v', 0 }, - { NOTMUCH_OPT_BOOLEAN, ¶ms.output_body, "body", 'b', 0 }, - { NOTMUCH_OPT_BOOLEAN, ¶ms.include_html, "include-html", 0, 0 }, - { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 }, - { 0, 0, 0, 0, 0 } + { .opt_int = ¬much_format_version, .name = "format-version" }, + { .opt_bool = &exclude, .name = "exclude" }, + { .opt_bool = &entire_thread, .name = "entire-thread" }, + { .opt_int = ¶ms.part, .name = "part" }, + { .opt_bool = ¶ms.crypto.decrypt, .name = "decrypt" }, + { .opt_bool = ¶ms.crypto.verify, .name = "verify" }, + { .opt_bool = ¶ms.output_body, .name = "body" }, + { .opt_bool = ¶ms.include_html, .name = "include-html" }, + { .opt_inherit = notmuch_shared_options }, + { } }; opt_index = parse_arguments (argc, argv, options, 1); |