diff options
author | Ilya Bobyr <ilya.bobyr@gmail.com> | 2014-03-22 02:47:34 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-03-23 17:28:03 -0700 |
commit | 9bab5b6061f1bc8ca54f8ac145f4f88c644e3bc4 (patch) | |
tree | eaa52a5624ceb7be5177a4ffc2f809019865138b /builtin/rev-parse.c | |
parent | 3f09db07b3dc0758756fad73c96abd0e47cbcd1b (diff) | |
download | git-9bab5b6061f1bc8ca54f8ac145f4f88c644e3bc4.tar.gz git-9bab5b6061f1bc8ca54f8ac145f4f88c644e3bc4.tar.xz |
rev-parse --parseopt: option argument name hints
Built-in commands can specify names for option arguments when usage text
is generated for a command. sh based commands should be able to do the
same.
Option argument name hint is any text that comes after [*=?!] after the
argument name up to the first whitespace.
Signed-off-by: Ilya Bobyr <ilya.bobyr@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/rev-parse.c')
-rw-r--r-- | builtin/rev-parse.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 45901df37..1a6122d3a 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -395,9 +395,10 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix) usage[unb++] = strbuf_detach(&sb, NULL); } - /* parse: (<short>|<short>,<long>|<long>)[=?]? SP+ <help> */ + /* parse: (<short>|<short>,<long>|<long>)[*=?!]*<arghint>? SP+ <help> */ while (strbuf_getline(&sb, stdin, '\n') != EOF) { const char *s; + const char *end; struct option *o; if (!sb.len) @@ -419,6 +420,16 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix) o->value = &parsed; o->flags = PARSE_OPT_NOARG; o->callback = &parseopt_dump; + + /* Possible argument name hint */ + end = s; + while (s > sb.buf && strchr("*=?!", s[-1]) == NULL) + --s; + if (s != sb.buf && s != end) + o->argh = xmemdupz(s, end - s); + if (s == sb.buf) + s = end; + while (s > sb.buf && strchr("*=?!", s[-1])) { switch (*--s) { case '=': |