unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 1/2] cli: fix top level --help combined with other options
@ 2015-03-08 16:18 Jani Nikula
  2015-03-08 16:18 ` [PATCH 2/2] cli: add support for notmuch command --help Jani Nikula
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Jani Nikula @ 2015-03-08 16:18 UTC (permalink / raw)
  To: notmuch

If the top level --help is combined with other options, help
fails. For example:

    $ notmuch --version --help

    Sorry, --help is not a known command. There's not much I can do to help.

Fix this by adjusting argc and argv appropriately. The help command
ignores argv[0] anyway, so we don't have to set it to "help".
---
 notmuch.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/notmuch.c b/notmuch.c
index 0fac0997865e..1717e8b3683c 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -315,7 +315,13 @@ main (int argc, char *argv[])
     }
 
     if (print_help) {
-	ret = notmuch_help_command (NULL, argc - 1, &argv[1]);
+	/*
+	 * Pass the first positional argument as argv[1] so the help
+	 * command can give help for it. The help command ignores the
+	 * argv[0] passed to it.
+	 */
+	ret = notmuch_help_command (NULL, argc - opt_index + 1,
+				    argv + opt_index - 1);
 	goto DONE;
     }
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] cli: add support for notmuch command --help
  2015-03-08 16:18 [PATCH 1/2] cli: fix top level --help combined with other options Jani Nikula
@ 2015-03-08 16:18 ` Jani Nikula
  2015-03-09  7:14   ` David Bremner
  2015-03-09  7:06 ` [PATCH 1/2] cli: fix top level --help combined with other options David Bremner
  2015-03-11  7:16 ` David Bremner
  2 siblings, 1 reply; 7+ messages in thread
From: Jani Nikula @ 2015-03-08 16:18 UTC (permalink / raw)
  To: notmuch

Recognize 'notmuch command --help' at the top level as a special case,
and show help for the command. Note that for simplicity, --help is
only recognized as the first option for the subcommand.

---

Creeping featurism or useful? ISTR Mark wanted this.
---
 notmuch.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/notmuch.c b/notmuch.c
index 1717e8b3683c..a5b2877aee09 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -314,7 +314,9 @@ main (int argc, char *argv[])
 	goto DONE;
     }
 
-    if (print_help) {
+    /* Handle notmuch --help [command] and notmuch command --help. */
+    if (print_help ||
+	(opt_index + 1 < argc && strcmp (argv[opt_index + 1], "--help") == 0)) {
 	/*
 	 * Pass the first positional argument as argv[1] so the help
 	 * command can give help for it. The help command ignores the
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] cli: fix top level --help combined with other options
  2015-03-08 16:18 [PATCH 1/2] cli: fix top level --help combined with other options Jani Nikula
  2015-03-08 16:18 ` [PATCH 2/2] cli: add support for notmuch command --help Jani Nikula
@ 2015-03-09  7:06 ` David Bremner
  2015-03-10  8:03   ` Tomi Ollila
  2015-03-11  7:16 ` David Bremner
  2 siblings, 1 reply; 7+ messages in thread
From: David Bremner @ 2015-03-09  7:06 UTC (permalink / raw)
  To: Jani Nikula, notmuch

Jani Nikula <jani@nikula.org> writes:

> -	ret = notmuch_help_command (NULL, argc - 1, &argv[1]);
> +	/*
> +	 * Pass the first positional argument as argv[1] so the help
> +	 * command can give help for it. The help command ignores the
> +	 * argv[0] passed to it.
> +	 */
> +	ret = notmuch_help_command (NULL, argc - opt_index + 1,
> +				    argv + opt_index - 1);
>  	goto DONE;
>      }

LGTM

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] cli: add support for notmuch command --help
  2015-03-08 16:18 ` [PATCH 2/2] cli: add support for notmuch command --help Jani Nikula
@ 2015-03-09  7:14   ` David Bremner
  2015-03-10  8:06     ` Tomi Ollila
  0 siblings, 1 reply; 7+ messages in thread
From: David Bremner @ 2015-03-09  7:14 UTC (permalink / raw)
  To: Jani Nikula, notmuch

Jani Nikula <jani@nikula.org> writes:

> -    if (print_help) {
> +    /* Handle notmuch --help [command] and notmuch command --help. */
> +    if (print_help ||
> +	(opt_index + 1 < argc && strcmp (argv[opt_index + 1], "--help") == 0)) {

I like the feature, and I can live with the implementation. I'm reminded
that you once proposed a more sophisticated way of handling shared
arguments for subcommands, but that foundered on a reef of bikeshedding.

d

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] cli: fix top level --help combined with other options
  2015-03-09  7:06 ` [PATCH 1/2] cli: fix top level --help combined with other options David Bremner
@ 2015-03-10  8:03   ` Tomi Ollila
  0 siblings, 0 replies; 7+ messages in thread
From: Tomi Ollila @ 2015-03-10  8:03 UTC (permalink / raw)
  To: David Bremner, Jani Nikula, notmuch

On Mon, Mar 09 2015, David Bremner <david@tethera.net> wrote:

> Jani Nikula <jani@nikula.org> writes:
>
>> -	ret = notmuch_help_command (NULL, argc - 1, &argv[1]);
>> +	/*
>> +	 * Pass the first positional argument as argv[1] so the help
>> +	 * command can give help for it. The help command ignores the
>> +	 * argv[0] passed to it.
>> +	 */
>> +	ret = notmuch_help_command (NULL, argc - opt_index + 1,
>> +				    argv + opt_index - 1);
>>  	goto DONE;
>>      }
>
> LGTM

Also to me, too.

Tomi

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] cli: add support for notmuch command --help
  2015-03-09  7:14   ` David Bremner
@ 2015-03-10  8:06     ` Tomi Ollila
  0 siblings, 0 replies; 7+ messages in thread
From: Tomi Ollila @ 2015-03-10  8:06 UTC (permalink / raw)
  To: David Bremner, Jani Nikula, notmuch

On Mon, Mar 09 2015, David Bremner <david@tethera.net> wrote:

> Jani Nikula <jani@nikula.org> writes:
>
>> -    if (print_help) {
>> +    /* Handle notmuch --help [command] and notmuch command --help. */
>> +    if (print_help ||
>> +	(opt_index + 1 < argc && strcmp (argv[opt_index + 1], "--help") == 0)) {
>
> I like the feature, and I can live with the implementation. I'm reminded

This part above I agree :D

> that you once proposed a more sophisticated way of handling shared
> arguments for subcommands, but that foundered on a reef of bikeshedding.
>
> d

Tomi

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] cli: fix top level --help combined with other options
  2015-03-08 16:18 [PATCH 1/2] cli: fix top level --help combined with other options Jani Nikula
  2015-03-08 16:18 ` [PATCH 2/2] cli: add support for notmuch command --help Jani Nikula
  2015-03-09  7:06 ` [PATCH 1/2] cli: fix top level --help combined with other options David Bremner
@ 2015-03-11  7:16 ` David Bremner
  2 siblings, 0 replies; 7+ messages in thread
From: David Bremner @ 2015-03-11  7:16 UTC (permalink / raw)
  To: Jani Nikula, notmuch

Jani Nikula <jani@nikula.org> writes:

> If the top level --help is combined with other options, help
> fails. For example:
>
>     $ notmuch --version --help
>
>     Sorry, --help is not a known command. There's not much I can do to
>     help
pushed these two

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-03-11  7:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-08 16:18 [PATCH 1/2] cli: fix top level --help combined with other options Jani Nikula
2015-03-08 16:18 ` [PATCH 2/2] cli: add support for notmuch command --help Jani Nikula
2015-03-09  7:14   ` David Bremner
2015-03-10  8:06     ` Tomi Ollila
2015-03-09  7:06 ` [PATCH 1/2] cli: fix top level --help combined with other options David Bremner
2015-03-10  8:03   ` Tomi Ollila
2015-03-11  7:16 ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).