Re: [PATCHv2] Add an optional argument for --color options
- From
Stephen Boyd <bebarino@gmail.com>
- Date
- Feb 18, 2010, 09:56 UTC
- Message-ID
- <4B7D0EDC.8070309@gmail.com>
- In-Reply-To
- <1266382558-26325-1-git-send-email-lodatom@gmail.com>
On 02/16/2010 08:55 PM, Mark Lodato wrote:
Show 11 quoted lines
> @@ -599,6 +600,22 @@ int parse_opt_approxidate_cb(const struct option *opt, const char *arg,
> return 0;
> }
>
> +int parse_opt_color_flag_cb(const struct option *opt, const char *arg,
> + int unset)
> +{
> + int value;
> + if (unset && arg)
> + return opterror(opt, "takes no value", OPT_UNSET);
> We can't have unset and arg both set at the same time. This exact case is handled by get_value() in parse-options.c (did you copy that?)
> + if (!arg) > + arg = unset ? "never" : (const char *)opt->defval; >
I've always been annoyed that the OPTION_CALLBACK doesn't set the option's value to the defval before calling the callback when it's PARSE_OPT_OPTARG. If it did we could drop half of this if condition too.
Here's something to squash --->8----
diff --git a/parse-options.c b/parse-options.c index 22da9be..0986314 100644 --- a/parse-options.c +++ b/parse-options.c @@ -604,8 +604,6 @@ int parse_opt_color_flag_cb(const struct option *opt, const int unset) { int value; - if (unset && arg) - return opterror(opt, "takes no value", OPT_UNSET); if (!arg) arg = unset ? "never" : (const char *)opt->defval; value = git_config_colorbool(NULL, arg, -1);