From: Jonathan Nieder Date: Tue, 30 Nov 2010 16:00:59 GMT Subject: [PATCH] parse-options: always show arghelp when LITERAL_ARGHELP is set 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 " 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 [--] ... don't add, only refresh the index but more importantly, update-index can correctly advertise --cacheinfo add the specified entry to the index without unsetting PARSE_OPT_NOARG and making that '--cacheinfo=' '' ''. Noticed-by: Stephen Boyd Signed-off-by: Jonathan Nieder --- Stephen Boyd wrote: > On 11/29/10 19:15, Jonathan Nieder wrote: >> + {OPTION_LOWLEVEL_CALLBACK, 0, "cacheinfo", NULL, >> + " ", >> + "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= 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