[PATCH] parse-options: always show arghelp when LITERAL_ARGHELP is set
- From
Jonathan Nieder <jrnieder@gmail.com>
- Date
- Nov 30, 2010, 16:00 UTC
- Message-ID
- <20101130160059.GA31844@burratino>
- In-Reply-To
- <4CF4B234.9060206@gmail.com>
The PARSE_OPT_LITERAL_ARGHELP flag allows a program to override the usual "<argument> for mandatory, [argument] for optional" markup in its help message. Extend it by allowing the usual "no text for disallowed" to be overridden, too (for options with PARSE_OPT_NOARG | PARSE_OPT_LITERAL_ARGHELP, which was previously an unsupported combination).
So now a person can impose ugly usage messages like
--refresh [--] <pathspec>... don't add, only refresh the index
but more importantly, update-index can correctly advertise
--cacheinfo <mode> <object> <path> add the specified entry to the index
without unsetting PARSE_OPT_NOARG and making that '--cacheinfo=<mode>' '<object>' '<path>'.
Noticed-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> --- Stephen Boyd wrote:
Show 9 quoted lines
> On 11/29/10 19:15, Jonathan Nieder wrote:
>> + {OPTION_LOWLEVEL_CALLBACK, 0, "cacheinfo", NULL,
>> + "<mode> <object> <path>",
>> + "add the specified entry to the index",
>> + PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP,
>> + (parse_opt_cb *) cacheinfo_callback},
>
> Doesn't this take arguments and thus shouldn't be marked
> PARSE_OPT_NOARG? Confused.Yes, that deserves a comment.
PARSE_OPT_NOARG | /* disallow sticky --cacheinfo=<mode> form */ PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP,
>> @@ -602,151 +799,48 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
[...]
>> + parse_options_start(&ctx, argc, argv, prefix, >> + PARSE_OPT_STOP_AT_NON_OPTION); > > This will need to take options too, sorry.
That would just be a merge artifact, no? :) Thanks for a pointer.
If all goes well, I'll reroll the series with your patch later today.
parse-options.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/parse-options.c b/parse-options.c index df8299c..71ebd9e 100644 --- a/parse-options.c +++ b/parse-options.c @@ -552,7 +552,8 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx, if (opts->type == OPTION_NUMBER) pos += fprintf(outfile, "-NUM"); - if (!(opts->flags & PARSE_OPT_NOARG)) + if ((opts->flags & PARSE_OPT_LITERAL_ARGHELP) || + !(opts->flags & PARSE_OPT_NOARG)) pos += usage_argh(opts, outfile); if (pos <= USAGE_OPTS_WIDTH)
-- 1.7.2.3