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>
This commit is contained in:

committed by
Junio C Hamano

parent
3f09db07b3
commit
9bab5b6061
@ -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 '=':
|
||||
|
Reference in New Issue
Block a user