[PATCH] parse-options: always show arghelp when LITERAL_ARGHELP is set

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
---
Stephen Boyd wrote:
> 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]