Re: [PATCH] tag: Use OPT_BOOL instead of OPT_BOOLEAN to allow one action multiple times
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jul 30, 2013, 22:22 UTC
- Message-ID
- <7vmwp3vgaq.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <51F82E83.30203@googlemail.com>
Stefan Beller <stefanbeller@googlemail.com> writes:
Show 8 quoted lines
> Your approach seems more like what we really want, however I'd have > some points: > * Is it a good idea to have so many different OPT_MODE or > OPTION_MODE defines? In my attempts I tried to reuse existing > OPTION_s to not pollute the parsing infrastructure with more > lines of code. ;) > > * You can only have one OPTION_CMDMODE in one argv vector right?
That is not what I intended, at least.
int one = 0, two = 0;
struct option options[] = {
OPT_CMDMODE('a', NULL, &one, N_("set one to a"), 'a'),
OPT_CMDMODE('b', NULL, &one, N_("set one to b"), 'b'),
OPT_CMDMODE('c', NULL, &two, N_("set two to c"), 'c'),
OPT_CMDMODE('d', NULL, &two, N_("set two to d"), 'd'),
OPT_END()
}should give you two independent sets of modes, one and two.
The only reason I needed to add an extra parameter to get_value() was so that I can tell the former two and the latter two belong to different groups, and that is done by looking at the address of the variable. In opt_command_mode_error(), opt->value == that->value is used as a condition to see if the other option is possibly the one that was used previously, which conflicted with us.