From 5f0df44cd79a953c287ccb598896ea7aaa2cc9e3 Mon Sep 17 00:00:00 2001 From: René Scharfe Date: Thu, 2 Aug 2018 21:18:14 +0200 Subject: parse-options: automatically infer PARSE_OPT_LITERAL_ARGHELP Parseopt wraps argument help strings in a pair of angular brackets by default, to tell users that they need to replace it with an actual value. This is useful in most cases, because most option arguments are indeed single values of a certain type. The option PARSE_OPT_LITERAL_ARGHELP needs to be used in option definitions with arguments that have multiple parts or are literal strings. Stop adding these angular brackets if special characters are present, as they indicate that we don't deal with a simple placeholder. This simplifies the code a bit and makes defining special options slightly easier. Remove the flag PARSE_OPT_LITERAL_ARGHELP in the cases where the new and more cautious handling suffices. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- parse-options.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'parse-options.c') diff --git a/parse-options.c b/parse-options.c index fca7159646..2a2b97aec9 100644 --- a/parse-options.c +++ b/parse-options.c @@ -562,7 +562,8 @@ int parse_options(int argc, const char **argv, const char *prefix, static int usage_argh(const struct option *opts, FILE *outfile) { const char *s; - int literal = (opts->flags & PARSE_OPT_LITERAL_ARGHELP) || !opts->argh; + int literal = (opts->flags & PARSE_OPT_LITERAL_ARGHELP) || + !opts->argh || !!strpbrk(opts->argh, "()<>[]|"); if (opts->flags & PARSE_OPT_OPTARG) if (opts->long_name) s = literal ? "[=%s]" : "[=<%s>]"; -- cgit 1.2.3-korg