git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] api-parse-options.txt: document OPT_CMDMODE()
@ 2016-03-24  9:07 Pranit Bauva
  2016-03-24 16:07 ` Junio C Hamano
  2016-03-25 18:58 ` [PATCH v2] " Pranit Bauva
  0 siblings, 2 replies; 9+ messages in thread
From: Pranit Bauva @ 2016-03-24  9:07 UTC (permalink / raw)
  To: git

OPT_CMDMODE() was introduced in the release of 1.8.5 which makes the use
of subcommands in the form of arguments a lot cleaner and easier.
---
 Documentation/technical/api-parse-options.txt | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/technical/api-parse-options.txt b/Documentation/technical/api-parse-options.txt
index 5f0757d..8130d26 100644
--- a/Documentation/technical/api-parse-options.txt
+++ b/Documentation/technical/api-parse-options.txt
@@ -231,6 +231,12 @@ There are some macros to easily define options:
 	pass the command-line option, which can be specified multiple times,
 	to another command.
 
+`OPT_CMDMODE(short, long, &int_var, description, enum_val)`::
+	Introduce an option for subcommands. It is useful when you want to use
+	the command with a particular sub command only and ignore other sub
+	commands it has. It will set `int_var` to enum_val if the argument is
+	invoked.
+
 
 The last element of the array must be `OPT_END()`.
 

--
https://github.com/git/git/pull/219

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

* Re: [PATCH] api-parse-options.txt: document OPT_CMDMODE()
  2016-03-24  9:07 [PATCH] api-parse-options.txt: document OPT_CMDMODE() Pranit Bauva
@ 2016-03-24 16:07 ` Junio C Hamano
  2016-03-24 16:55   ` Pranit Bauva
  2016-03-25 18:58 ` [PATCH v2] " Pranit Bauva
  1 sibling, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2016-03-24 16:07 UTC (permalink / raw)
  To: Pranit Bauva; +Cc: git

Pranit Bauva <pranit.bauva@gmail.com> writes:

> OPT_CMDMODE() was introduced in the release of 1.8.5 which makes the use
> of subcommands in the form of arguments a lot cleaner and easier.
> ---

Sign-off?

>  Documentation/technical/api-parse-options.txt | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/Documentation/technical/api-parse-options.txt b/Documentation/technical/api-parse-options.txt
> index 5f0757d..8130d26 100644
> --- a/Documentation/technical/api-parse-options.txt
> +++ b/Documentation/technical/api-parse-options.txt
> @@ -231,6 +231,12 @@ There are some macros to easily define options:
>  	pass the command-line option, which can be specified multiple times,
>  	to another command.
>  
> +`OPT_CMDMODE(short, long, &int_var, description, enum_val)`::
> +	Introduce an option for subcommands. It is useful when you want to use
> +	the command with a particular sub command only and ignore other sub
> +	commands it has. It will set `int_var` to enum_val if the argument is
> +	invoked.
> +

Sorry, but I do not get what "when you want to... ignore other sub
command it has" wants to say.

CMDMODE is a mechanism to actively notice when multiple "operation
mode" options that specify mutually incompatible operation modes are
given and error out without the user of parse_options() to implement
that mutual exclusion herself.  That is, if you have 'add', 'remove'
and 'edit' operation modes, with OPT_BOOL(), you would have to say:

	options[] = {
                OPT_BOOL('a', "add", &add, ...),
                OPT_BOOL('r', "remove", &remove, ...),
                OPT_BOOL('e', "edit", &edit, ...),
                ...
	};
        parse_options(ac, av, prefix, options, ...);

	if (!!add + !!remove + !!edit > 1)
        	die("at most one add/remove/edit can be used at a time");

	if (add)
        	do_add();
	if (remove)
        	do_remove();
	if (edit)
        	do_edit();

but with CMDMODE, you can do:

	options[] = {
                OPT_BOOL('a', "add", &mode, ...),
                OPT_BOOL('r', "remove", &mode, ...),
                OPT_BOOL('e', "edit", &mode, ...),
                ...
	};
        parse_options(ac, av, prefix, options, ...);

        switch (mode) {
        case 'a': do_add(); break;
        case 'r': do_remove(); break;
        case 'e': do_edit(); break;
		...
	}

and parse_options notices that "mode" is shared across these three
options, and implements the mutual-exclusion itself.

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

* Re: [PATCH] api-parse-options.txt: document OPT_CMDMODE()
  2016-03-24 16:07 ` Junio C Hamano
@ 2016-03-24 16:55   ` Pranit Bauva
  2016-03-24 17:16     ` Junio C Hamano
  0 siblings, 1 reply; 9+ messages in thread
From: Pranit Bauva @ 2016-03-24 16:55 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git List

On Thu, Mar 24, 2016 at 9:37 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Pranit Bauva <pranit.bauva@gmail.com> writes:
>
>> OPT_CMDMODE() was introduced in the release of 1.8.5 which makes the use
>> of subcommands in the form of arguments a lot cleaner and easier.
>> ---
>
> Sign-off?

Will include this.

>>  Documentation/technical/api-parse-options.txt | 6 ++++++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/Documentation/technical/api-parse-options.txt b/Documentation/technical/api-parse-options.txt
>> index 5f0757d..8130d26 100644
>> --- a/Documentation/technical/api-parse-options.txt
>> +++ b/Documentation/technical/api-parse-options.txt
>> @@ -231,6 +231,12 @@ There are some macros to easily define options:
>>       pass the command-line option, which can be specified multiple times,
>>       to another command.
>>
>> +`OPT_CMDMODE(short, long, &int_var, description, enum_val)`::
>> +     Introduce an option for subcommands. It is useful when you want to use
>> +     the command with a particular sub command only and ignore other sub
>> +     commands it has. It will set `int_var` to enum_val if the argument is
>> +     invoked.
>> +
>
> Sorry, but I do not get what "when you want to... ignore other sub
> command it has" wants to say.

What I meant by this statement is that (your example), let's say we
have "add", "remove" and "edit" sub commands. Now the user has to pick
between the three. He cannot choose more than 1 from these.

> CMDMODE is a mechanism to actively notice when multiple "operation
> mode" options that specify mutually incompatible operation modes are
> given and error out without the user of parse_options() to implement
> that mutual exclusion herself.  That is, if you have 'add', 'remove'
> and 'edit' operation modes, with OPT_BOOL(), you would have to say:
>
>         options[] = {
>                 OPT_BOOL('a', "add", &add, ...),
>                 OPT_BOOL('r', "remove", &remove, ...),
>                 OPT_BOOL('e', "edit", &edit, ...),
>                 ...
>         };
>         parse_options(ac, av, prefix, options, ...);
>
>         if (!!add + !!remove + !!edit > 1)
>                 die("at most one add/remove/edit can be used at a time");
>
>         if (add)
>                 do_add();
>         if (remove)
>                 do_remove();
>         if (edit)
>                 do_edit();
>
> but with CMDMODE, you can do:
>
>         options[] = {
>                 OPT_BOOL('a', "add", &mode, ...),
>                 OPT_BOOL('r', "remove", &mode, ...),
>                 OPT_BOOL('e', "edit", &mode, ...),
>                 ...
>         };
>         parse_options(ac, av, prefix, options, ...);
>
>         switch (mode) {
>         case 'a': do_add(); break;
>         case 'r': do_remove(); break;
>         case 'e': do_edit(); break;
>                 ...
>         }
>
> and parse_options notices that "mode" is shared across these three
> options, and implements the mutual-exclusion itself.

Thanks for taking time to explain all the details behind it. I can
include these bits in the documentation. :)

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

* Re: [PATCH] api-parse-options.txt: document OPT_CMDMODE()
  2016-03-24 16:55   ` Pranit Bauva
@ 2016-03-24 17:16     ` Junio C Hamano
  2016-03-24 18:04       ` Pranit Bauva
  0 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2016-03-24 17:16 UTC (permalink / raw)
  To: Pranit Bauva; +Cc: Git List

Pranit Bauva <pranit.bauva@gmail.com> writes:

>>> +`OPT_CMDMODE(short, long, &int_var, description, enum_val)`::
>>> +     Introduce an option for subcommands. It is useful when you want to use
>>> +     the command with a particular sub command only and ignore other sub
>>> +     commands it has. It will set `int_var` to enum_val if the argument is
>>> +     invoked.
>>> +
>>
>> Sorry, but I do not get what "when you want to... ignore other sub
>> command it has" wants to say.
>
> What I meant by this statement is that (your example), let's say we
> have "add", "remove" and "edit" sub commands. Now the user has to pick
> between the three. He cannot choose more than 1 from these.

Then I find the word "ignore others" misleading.  Quite the
contrary, the user has to be aware of the others and not to give
them.

	Define an "operating mode" option, only one of which in the
	same group of "operating mode" options that share the same
	`int_var` can be given by the user.  `enum_val` is set to
	`int_var` when the option is used, but an error is reported
        if other "operating mode" option has already set its value
        to the same `int_var`.

or something?

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

* Re: [PATCH] api-parse-options.txt: document OPT_CMDMODE()
  2016-03-24 17:16     ` Junio C Hamano
@ 2016-03-24 18:04       ` Pranit Bauva
  0 siblings, 0 replies; 9+ messages in thread
From: Pranit Bauva @ 2016-03-24 18:04 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git List

On Thu, Mar 24, 2016 at 10:46 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Pranit Bauva <pranit.bauva@gmail.com> writes:
>
>>>> +`OPT_CMDMODE(short, long, &int_var, description, enum_val)`::
>>>> +     Introduce an option for subcommands. It is useful when you want to use
>>>> +     the command with a particular sub command only and ignore other sub
>>>> +     commands it has. It will set `int_var` to enum_val if the argument is
>>>> +     invoked.
>>>> +
>>>
>>> Sorry, but I do not get what "when you want to... ignore other sub
>>> command it has" wants to say.
>>
>> What I meant by this statement is that (your example), let's say we
>> have "add", "remove" and "edit" sub commands. Now the user has to pick
>> between the three. He cannot choose more than 1 from these.
>
> Then I find the word "ignore others" misleading.  Quite the
> contrary, the user has to be aware of the others and not to give
> them.
>
>         Define an "operating mode" option, only one of which in the
>         same group of "operating mode" options that share the same
>         `int_var` can be given by the user.  `enum_val` is set to
>         `int_var` when the option is used, but an error is reported
>         if other "operating mode" option has already set its value
>         to the same `int_var`.
>
> or something?

Seems a crystal clear explanation to me. Thanks. I was unaware that it
throws an error.

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

* [PATCH v2] api-parse-options.txt: document OPT_CMDMODE()
  2016-03-24  9:07 [PATCH] api-parse-options.txt: document OPT_CMDMODE() Pranit Bauva
  2016-03-24 16:07 ` Junio C Hamano
@ 2016-03-25 18:58 ` Pranit Bauva
  2016-03-25 19:08   ` Pranit Bauva
  2016-03-25 20:14   ` [PATCH v3] " Pranit Bauva
  1 sibling, 2 replies; 9+ messages in thread
From: Pranit Bauva @ 2016-03-25 18:58 UTC (permalink / raw)
  To: git

OPT_CMDMODE mechanism was introduced in the release of 1.8.5 to actively
notice when multiple "operation mode" options that specify mutually
incompatible operation modes are given.

Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com>
---
 Documentation/technical/api-parse-options.txt | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/Documentation/technical/api-parse-options.txt b/Documentation/technical/api-parse-options.txt
index 5f0757d..695bd4b 100644
--- a/Documentation/technical/api-parse-options.txt
+++ b/Documentation/technical/api-parse-options.txt
@@ -231,6 +231,13 @@ There are some macros to easily define options:
 	pass the command-line option, which can be specified multiple times,
 	to another command.
 
+`OPT_CMDMODE(short, long, &int_var, description, enum_val)`::
+	Define an "operation mode" option, only one of which in the same
+	group of "operating mode" options that share the same `int_var`
+	can be given by the user. `enum_val` is set to `int_var` when the
+	option is used, but an error is reported if other "operating mode"
+	option has already set its value to the same `int_var`.
+
 
 The last element of the array must be `OPT_END()`.
 

--
https://github.com/git/git/pull/219

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

* Re: [PATCH v2] api-parse-options.txt: document OPT_CMDMODE()
  2016-03-25 18:58 ` [PATCH v2] " Pranit Bauva
@ 2016-03-25 19:08   ` Pranit Bauva
  2016-03-25 21:24     ` Junio C Hamano
  2016-03-25 20:14   ` [PATCH v3] " Pranit Bauva
  1 sibling, 1 reply; 9+ messages in thread
From: Pranit Bauva @ 2016-03-25 19:08 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

I have used bits from your email. I forgot to add "Helped-by: Junio C
Hamano <gitster@pobox.com>" . Could you squash it in?

On Sat, Mar 26, 2016 at 12:28 AM, Pranit Bauva <pranit.bauva@gmail.com> wrote:
> OPT_CMDMODE mechanism was introduced in the release of 1.8.5 to actively
> notice when multiple "operation mode" options that specify mutually
> incompatible operation modes are given.
>
> Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com>
> ---
>  Documentation/technical/api-parse-options.txt | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/Documentation/technical/api-parse-options.txt b/Documentation/technical/api-parse-options.txt
> index 5f0757d..695bd4b 100644
> --- a/Documentation/technical/api-parse-options.txt
> +++ b/Documentation/technical/api-parse-options.txt
> @@ -231,6 +231,13 @@ There are some macros to easily define options:
>         pass the command-line option, which can be specified multiple times,
>         to another command.
>
> +`OPT_CMDMODE(short, long, &int_var, description, enum_val)`::
> +       Define an "operation mode" option, only one of which in the same
> +       group of "operating mode" options that share the same `int_var`
> +       can be given by the user. `enum_val` is set to `int_var` when the
> +       option is used, but an error is reported if other "operating mode"
> +       option has already set its value to the same `int_var`.
> +
>
>  The last element of the array must be `OPT_END()`.
>
>
> --
> https://github.com/git/git/pull/219
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH v3] api-parse-options.txt: document OPT_CMDMODE()
  2016-03-25 18:58 ` [PATCH v2] " Pranit Bauva
  2016-03-25 19:08   ` Pranit Bauva
@ 2016-03-25 20:14   ` Pranit Bauva
  1 sibling, 0 replies; 9+ messages in thread
From: Pranit Bauva @ 2016-03-25 20:14 UTC (permalink / raw)
  To: git

OPT_CMDMODE mechanism was introduced in the release of 1.8.5 to actively
notice when multiple "operation mode" options that specify mutually
incompatible operation modes are given.

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com>
---
 Documentation/technical/api-parse-options.txt | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/Documentation/technical/api-parse-options.txt b/Documentation/technical/api-parse-options.txt
index 5f0757d..695bd4b 100644
--- a/Documentation/technical/api-parse-options.txt
+++ b/Documentation/technical/api-parse-options.txt
@@ -231,6 +231,13 @@ There are some macros to easily define options:
 	pass the command-line option, which can be specified multiple times,
 	to another command.
 
+`OPT_CMDMODE(short, long, &int_var, description, enum_val)`::
+	Define an "operation mode" option, only one of which in the same
+	group of "operating mode" options that share the same `int_var`
+	can be given by the user. `enum_val` is set to `int_var` when the
+	option is used, but an error is reported if other "operating mode"
+	option has already set its value to the same `int_var`.
+
 
 The last element of the array must be `OPT_END()`.
 

--
https://github.com/git/git/pull/219

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

* Re: [PATCH v2] api-parse-options.txt: document OPT_CMDMODE()
  2016-03-25 19:08   ` Pranit Bauva
@ 2016-03-25 21:24     ` Junio C Hamano
  0 siblings, 0 replies; 9+ messages in thread
From: Junio C Hamano @ 2016-03-25 21:24 UTC (permalink / raw)
  To: Pranit Bauva; +Cc: Git List

Pranit Bauva <pranit.bauva@gmail.com> writes:

> I have used bits from your email. I forgot to add "Helped-by: Junio C
> Hamano <gitster@pobox.com>" . Could you squash it in?

It's OK to omit such a credit for a patch this small.  After
understanding the issues, you would have written essentially the
same thing yourself.

Thanks, queued v2 already.

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

end of thread, other threads:[~2016-03-25 21:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-24  9:07 [PATCH] api-parse-options.txt: document OPT_CMDMODE() Pranit Bauva
2016-03-24 16:07 ` Junio C Hamano
2016-03-24 16:55   ` Pranit Bauva
2016-03-24 17:16     ` Junio C Hamano
2016-03-24 18:04       ` Pranit Bauva
2016-03-25 18:58 ` [PATCH v2] " Pranit Bauva
2016-03-25 19:08   ` Pranit Bauva
2016-03-25 21:24     ` Junio C Hamano
2016-03-25 20:14   ` [PATCH v3] " Pranit Bauva

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

	https://80x24.org/mirrors/git.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).