summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5acb3e5)
raw | patch | inline | side by side (parent: 5acb3e5)
author | Stephen Boyd <bebarino@gmail.com> | |
Thu, 21 May 2009 07:33:17 +0000 (00:33 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sat, 23 May 2009 05:46:04 +0000 (22:46 -0700) |
Usually, the argh element in struct option points at a placeholder value
(e.g. "val"), and is shown in the usage message as
--option=<val>
by enclosing the string inside of angle brackets.
When the option is more complex (e.g. optional arguments separated by a
comma), you would want to produce a usage message that looks like
--option=<val1>[,<val2>]
In such a case, the caller can pass a string to argh with placeholders
already enclosed in necessary angle brackets (e.g. "<val1>[,<val2>]")
and set this flag.
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
(e.g. "val"), and is shown in the usage message as
--option=<val>
by enclosing the string inside of angle brackets.
When the option is more complex (e.g. optional arguments separated by a
comma), you would want to produce a usage message that looks like
--option=<val1>[,<val2>]
In such a case, the caller can pass a string to argh with placeholders
already enclosed in necessary angle brackets (e.g. "<val1>[,<val2>]")
and set this flag.
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
parse-options.c | patch | blob | history | |
parse-options.h | patch | blob | history |
diff --git a/parse-options.c b/parse-options.c
index cf71bcffd2e1e9aeacb44df488b0825f09d54255..e8955be7b4ae0ccbf72b341130af3345f81b08c4 100644 (file)
--- a/parse-options.c
+++ b/parse-options.c
return parse_options_end(&ctx);
}
+static int usage_argh(const struct option *opts)
+{
+ const char *s;
+ int literal = opts->flags & PARSE_OPT_LITERAL_ARGHELP;
+ if (opts->flags & PARSE_OPT_OPTARG)
+ if (opts->long_name)
+ s = literal ? "[=%s]" : "[=<%s>]";
+ else
+ s = literal ? "[%s]" : "[<%s>]";
+ else
+ s = literal ? " %s" : " <%s>";
+ return fprintf(stderr, s, opts->argh);
+}
+
#define USAGE_OPTS_WIDTH 24
#define USAGE_GAP 2
break;
/* FALLTHROUGH */
case OPTION_STRING:
- if (opts->argh) {
- if (opts->flags & PARSE_OPT_OPTARG)
- if (opts->long_name)
- pos += fprintf(stderr, "[=<%s>]", opts->argh);
- else
- pos += fprintf(stderr, "[<%s>]", opts->argh);
- else
- pos += fprintf(stderr, " <%s>", opts->argh);
- } else {
+ if (opts->argh)
+ pos += usage_argh(opts);
+ else {
if (opts->flags & PARSE_OPT_OPTARG)
if (opts->long_name)
pos += fprintf(stderr, "[=...]");
diff --git a/parse-options.h b/parse-options.h
index b54eec128bcda1a8b4c4a2c33f2ce799c506ac23..910aa1e9f1827f119fb445e281e02235e6f99df3 100644 (file)
--- a/parse-options.h
+++ b/parse-options.h
PARSE_OPT_NONEG = 4,
PARSE_OPT_HIDDEN = 8,
PARSE_OPT_LASTARG_DEFAULT = 16,
+ PARSE_OPT_LITERAL_ARGHELP = 64,
};
struct option;
* PARSE_OPT_NONEG: says that this option cannot be negated
* PARSE_OPT_HIDDEN this option is skipped in the default usage, showed in
* the long one.
+ * PARSE_OPT_LITERAL_ARGHELP: says that argh shouldn't be enclosed in brackets
+ * (i.e. '<argh>') in the help message.
+ * Useful for options with multiple parameters.
*
* `callback`::
* pointer to the callback to use for OPTION_CALLBACK.