[PATCH v3 06/10] cli: Introduce "notmuch address" command
On Wed, Nov 05 2014, Michal Sojka wrote: > This moves address-related functionality from search command to the > new address command. The implementation shares almost all code and > some command line options. > > Options --offset and --limit were intentionally not included in the > address command, because they refer to messages numbers, which users > do not see in the output. This could confuse users because, for > example, they could see more addresses in the output that what was > specified with --limit. This functionality can be correctly > reimplemented for address subcommand later. > > Also useless values of --exclude flag were not included in the address > command. > > This was inspired by a patch from Jani Nikula. > --- > completion/notmuch-completion.bash | 42 - > completion/notmuch-completion.zsh | 10 +++- > doc/man1/notmuch-address.rst | 89 > doc/man1/notmuch-search.rst| 20 +--- > doc/man1/notmuch.rst | 7 +-- > notmuch-client.h | 3 ++ > notmuch-search.c | 93 > +++--- > notmuch.c | 2 + > 8 files changed, 216 insertions(+), 50 deletions(-) > create mode 100644 doc/man1/notmuch-address.rst > > [ nnn lines removed ] > > + > +int > +notmuch_address_command (notmuch_config_t *config, int argc, char *argv[]) > +{ > +search_context_t *ctx = &search_context; > +int opt_index, ret; > + > +notmuch_opt_desc_t options[] = { > + { NOTMUCH_OPT_KEYWORD_FLAGS, &ctx->output, "output", 'o', > + (notmuch_keyword_t []){ { "sender", OUTPUT_SENDER }, > + { "recipients", OUTPUT_RECIPIENTS }, > + { 0, 0 } } }, > + { NOTMUCH_OPT_KEYWORD, &ctx->exclude, "exclude", 'x', > + (notmuch_keyword_t []){ { "true", NOTMUCH_EXCLUDE_TRUE }, > + { "false", NOTMUCH_EXCLUDE_FALSE }, > + { 0, 0 } } }, > + { NOTMUCH_OPT_INHERIT, &common_options, NULL, 0, 0 }, > + { 0, 0, 0, 0, 0 } > +}; > + > +opt_index = parse_arguments (argc, argv, options, 1); > +if (opt_index < 0) > + return EXIT_FAILURE; > + > +if (! ctx->output) > + ctx->output = OUTPUT_SENDER | OUTPUT_RECIPIENTS; If no --output options are given, the default could be just to OUTPUT_SENDER (for the speed and as this behaviour is not documented) (this can be also addressed in later patch, provided that this functionality gets more "votes" from the community) Tomi > + > +if (_notmuch_search_prepare (ctx, config, > + argc - opt_index, argv + opt_index)) > + return EXIT_FAILURE; > + > +ret = do_search_messages (ctx); > + > +_notmuch_search_cleanup (ctx); > + > +return ret ? EXIT_FAILURE : EXIT_SUCCESS; > +}
Re: [PATCH v3 06/10] cli: Introduce "notmuch address" command
On Wed, Nov 05 2014, Michal Sojka wrote: > This moves address-related functionality from search command to the > new address command. The implementation shares almost all code and > some command line options. > > Options --offset and --limit were intentionally not included in the > address command, because they refer to messages numbers, which users > do not see in the output. This could confuse users because, for > example, they could see more addresses in the output that what was > specified with --limit. This functionality can be correctly > reimplemented for address subcommand later. > > Also useless values of --exclude flag were not included in the address > command. > > This was inspired by a patch from Jani Nikula. > --- > completion/notmuch-completion.bash | 42 - > completion/notmuch-completion.zsh | 10 +++- > doc/man1/notmuch-address.rst | 89 > doc/man1/notmuch-search.rst| 20 +--- > doc/man1/notmuch.rst | 7 +-- > notmuch-client.h | 3 ++ > notmuch-search.c | 93 > +++--- > notmuch.c | 2 + > 8 files changed, 216 insertions(+), 50 deletions(-) > create mode 100644 doc/man1/notmuch-address.rst > > [ nnn lines removed ] > > + > +int > +notmuch_address_command (notmuch_config_t *config, int argc, char *argv[]) > +{ > +search_context_t *ctx = &search_context; > +int opt_index, ret; > + > +notmuch_opt_desc_t options[] = { > + { NOTMUCH_OPT_KEYWORD_FLAGS, &ctx->output, "output", 'o', > + (notmuch_keyword_t []){ { "sender", OUTPUT_SENDER }, > + { "recipients", OUTPUT_RECIPIENTS }, > + { 0, 0 } } }, > + { NOTMUCH_OPT_KEYWORD, &ctx->exclude, "exclude", 'x', > + (notmuch_keyword_t []){ { "true", NOTMUCH_EXCLUDE_TRUE }, > + { "false", NOTMUCH_EXCLUDE_FALSE }, > + { 0, 0 } } }, > + { NOTMUCH_OPT_INHERIT, &common_options, NULL, 0, 0 }, > + { 0, 0, 0, 0, 0 } > +}; > + > +opt_index = parse_arguments (argc, argv, options, 1); > +if (opt_index < 0) > + return EXIT_FAILURE; > + > +if (! ctx->output) > + ctx->output = OUTPUT_SENDER | OUTPUT_RECIPIENTS; If no --output options are given, the default could be just to OUTPUT_SENDER (for the speed and as this behaviour is not documented) (this can be also addressed in later patch, provided that this functionality gets more "votes" from the community) Tomi > + > +if (_notmuch_search_prepare (ctx, config, > + argc - opt_index, argv + opt_index)) > + return EXIT_FAILURE; > + > +ret = do_search_messages (ctx); > + > +_notmuch_search_cleanup (ctx); > + > +return ret ? EXIT_FAILURE : EXIT_SUCCESS; > +} ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
[PATCH v3 06/10] cli: Introduce "notmuch address" command
This moves address-related functionality from search command to the new address command. The implementation shares almost all code and some command line options. Options --offset and --limit were intentionally not included in the address command, because they refer to messages numbers, which users do not see in the output. This could confuse users because, for example, they could see more addresses in the output that what was specified with --limit. This functionality can be correctly reimplemented for address subcommand later. Also useless values of --exclude flag were not included in the address command. This was inspired by a patch from Jani Nikula. --- completion/notmuch-completion.bash | 42 - completion/notmuch-completion.zsh | 10 +++- doc/man1/notmuch-address.rst | 89 doc/man1/notmuch-search.rst| 20 +--- doc/man1/notmuch.rst | 7 +-- notmuch-client.h | 3 ++ notmuch-search.c | 93 +++--- notmuch.c | 2 + 8 files changed, 216 insertions(+), 50 deletions(-) create mode 100644 doc/man1/notmuch-address.rst diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash index cfbd389..94ea2d5 100644 --- a/completion/notmuch-completion.bash +++ b/completion/notmuch-completion.bash @@ -294,7 +294,7 @@ _notmuch_search() return ;; --output) - COMPREPLY=( $( compgen -W "summary threads messages files tags sender recipients" -- "${cur}" ) ) + COMPREPLY=( $( compgen -W "summary threads messages files tags" -- "${cur}" ) ) return ;; --sort) @@ -320,6 +320,44 @@ _notmuch_search() esac } +_notmuch_address() +{ +local cur prev words cword split +_init_completion -s || return + +$split && +case "${prev}" in + --format) + COMPREPLY=( $( compgen -W "json sexp text text0" -- "${cur}" ) ) + return + ;; + --output) + COMPREPLY=( $( compgen -W "sender recipients" -- "${cur}" ) ) + return + ;; + --sort) + COMPREPLY=( $( compgen -W "newest-first oldest-first" -- "${cur}" ) ) + return + ;; + --exclude) + COMPREPLY=( $( compgen -W "true false flag all" -- "${cur}" ) ) + return + ;; +esac + +! $split && +case "${cur}" in + -*) + local options="--format= --output= --sort= --exclude=" + compopt -o nospace + COMPREPLY=( $(compgen -W "$options" -- ${cur}) ) + ;; + *) + _notmuch_search_terms + ;; +esac +} + _notmuch_show() { local cur prev words cword split @@ -393,7 +431,7 @@ _notmuch_tag() _notmuch() { -local _notmuch_commands="compact config count dump help insert new reply restore search setup show tag" +local _notmuch_commands="compact config count dump help insert new reply restore search address setup show tag" local arg cur prev words cword split # require bash-completion with _init_completion diff --git a/completion/notmuch-completion.zsh b/completion/notmuch-completion.zsh index 3e52a00..c606b75 100644 --- a/completion/notmuch-completion.zsh +++ b/completion/notmuch-completion.zsh @@ -10,6 +10,7 @@ _notmuch_commands() 'setup:interactively set up notmuch for first use' 'new:find and import any new message to the database' 'search:search for messages matching the search terms, display matching threads as results' +'address:get addresses from messages matching the given search terms' 'reply:constructs a reply template for a set of messages' 'show:show all messages matching the search terms' 'tag:add or remove tags for all messages matching the search terms' @@ -53,7 +54,14 @@ _notmuch_search() '--max-threads=[display only the first x threads from the search results]:number of threads to show: ' \ '--first=[omit the first x threads from the search results]:number of threads to omit: ' \ '--sort=[sort results]:sorting:((newest-first\:"reverse chronological order" oldest-first\:"chronological order"))' \ -'--output=[select what to output]:output:((summary threads messages files tags sender recipients))' +'--output=[select what to output]:output:((summary threads messages files tags))' +} + +_notmuch_address() +{ + _arguments -s : \ +'--sort=[sort results]:sorting:((newest-first\:"reverse chronological order" oldest-first\:"chronological order"))' \ +'--output=[select what to output]:output:((sender recipients))' } _notmuch() diff --git a/doc/man1/notmuch-address.rst b/doc/man1/notmuch-address.rst new file mode 100644 index 000..d349237 --- /dev/null +++ b/doc/man1/notmuch-address.rst @@ -0,0 +1,89 @@ +=== +notmuch-address +=== + +SYNOPSIS + +
[PATCH v3 06/10] cli: Introduce "notmuch address" command
This moves address-related functionality from search command to the new address command. The implementation shares almost all code and some command line options. Options --offset and --limit were intentionally not included in the address command, because they refer to messages numbers, which users do not see in the output. This could confuse users because, for example, they could see more addresses in the output that what was specified with --limit. This functionality can be correctly reimplemented for address subcommand later. Also useless values of --exclude flag were not included in the address command. This was inspired by a patch from Jani Nikula. --- completion/notmuch-completion.bash | 42 - completion/notmuch-completion.zsh | 10 +++- doc/man1/notmuch-address.rst | 89 doc/man1/notmuch-search.rst| 20 +--- doc/man1/notmuch.rst | 7 +-- notmuch-client.h | 3 ++ notmuch-search.c | 93 +++--- notmuch.c | 2 + 8 files changed, 216 insertions(+), 50 deletions(-) create mode 100644 doc/man1/notmuch-address.rst diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash index cfbd389..94ea2d5 100644 --- a/completion/notmuch-completion.bash +++ b/completion/notmuch-completion.bash @@ -294,7 +294,7 @@ _notmuch_search() return ;; --output) - COMPREPLY=( $( compgen -W "summary threads messages files tags sender recipients" -- "${cur}" ) ) + COMPREPLY=( $( compgen -W "summary threads messages files tags" -- "${cur}" ) ) return ;; --sort) @@ -320,6 +320,44 @@ _notmuch_search() esac } +_notmuch_address() +{ +local cur prev words cword split +_init_completion -s || return + +$split && +case "${prev}" in + --format) + COMPREPLY=( $( compgen -W "json sexp text text0" -- "${cur}" ) ) + return + ;; + --output) + COMPREPLY=( $( compgen -W "sender recipients" -- "${cur}" ) ) + return + ;; + --sort) + COMPREPLY=( $( compgen -W "newest-first oldest-first" -- "${cur}" ) ) + return + ;; + --exclude) + COMPREPLY=( $( compgen -W "true false flag all" -- "${cur}" ) ) + return + ;; +esac + +! $split && +case "${cur}" in + -*) + local options="--format= --output= --sort= --exclude=" + compopt -o nospace + COMPREPLY=( $(compgen -W "$options" -- ${cur}) ) + ;; + *) + _notmuch_search_terms + ;; +esac +} + _notmuch_show() { local cur prev words cword split @@ -393,7 +431,7 @@ _notmuch_tag() _notmuch() { -local _notmuch_commands="compact config count dump help insert new reply restore search setup show tag" +local _notmuch_commands="compact config count dump help insert new reply restore search address setup show tag" local arg cur prev words cword split # require bash-completion with _init_completion diff --git a/completion/notmuch-completion.zsh b/completion/notmuch-completion.zsh index 3e52a00..c606b75 100644 --- a/completion/notmuch-completion.zsh +++ b/completion/notmuch-completion.zsh @@ -10,6 +10,7 @@ _notmuch_commands() 'setup:interactively set up notmuch for first use' 'new:find and import any new message to the database' 'search:search for messages matching the search terms, display matching threads as results' +'address:get addresses from messages matching the given search terms' 'reply:constructs a reply template for a set of messages' 'show:show all messages matching the search terms' 'tag:add or remove tags for all messages matching the search terms' @@ -53,7 +54,14 @@ _notmuch_search() '--max-threads=[display only the first x threads from the search results]:number of threads to show: ' \ '--first=[omit the first x threads from the search results]:number of threads to omit: ' \ '--sort=[sort results]:sorting:((newest-first\:"reverse chronological order" oldest-first\:"chronological order"))' \ -'--output=[select what to output]:output:((summary threads messages files tags sender recipients))' +'--output=[select what to output]:output:((summary threads messages files tags))' +} + +_notmuch_address() +{ + _arguments -s : \ +'--sort=[sort results]:sorting:((newest-first\:"reverse chronological order" oldest-first\:"chronological order"))' \ +'--output=[select what to output]:output:((sender recipients))' } _notmuch() diff --git a/doc/man1/notmuch-address.rst b/doc/man1/notmuch-address.rst new file mode 100644 index 000..d349237 --- /dev/null +++ b/doc/man1/notmuch-address.rst @@ -0,0 +1,89 @@ +=== +notmuch-address +=== + +SYNOPSIS +==