mirror of
https://github.com/git/git.git
synced 2024-12-03 23:14:23 +08:00
Merge branch 'jc/parse-options-short-help'
Command line parser fix, and a small parse-options API update. * jc/parse-options-short-help: short help: allow a gap smaller than USAGE_GAP remote: simplify "remote add --tags" help text short help: allow multi-line opthelp
This commit is contained in:
commit
f9712d75e6
@ -168,10 +168,9 @@ static int add(int argc, const char **argv, const char *prefix)
|
||||
struct option options[] = {
|
||||
OPT_BOOL('f', "fetch", &fetch, N_("fetch the remote branches")),
|
||||
OPT_SET_INT(0, "tags", &fetch_tags,
|
||||
N_("import all tags and associated objects when fetching"),
|
||||
N_("import all tags and associated objects when fetching\n"
|
||||
"or do not fetch any tag at all (--no-tags)"),
|
||||
TAGS_SET),
|
||||
OPT_SET_INT(0, NULL, &fetch_tags,
|
||||
N_("or do not fetch any tag at all (--no-tags)"), TAGS_UNSET),
|
||||
OPT_STRING_LIST('t', "track", &track, N_("branch"),
|
||||
N_("branch(es) to track")),
|
||||
OPT_STRING('m', "master", &master, N_("branch"), N_("master branch")),
|
||||
|
@ -1109,6 +1109,7 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
|
||||
for (; opts->type != OPTION_END; opts++) {
|
||||
size_t pos;
|
||||
int pad;
|
||||
const char *cp, *np;
|
||||
|
||||
if (opts->type == OPTION_SUBCOMMAND)
|
||||
continue;
|
||||
@ -1145,7 +1146,9 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
|
||||
!(opts->flags & PARSE_OPT_NOARG))
|
||||
pos += usage_argh(opts, outfile);
|
||||
|
||||
if (pos <= USAGE_OPTS_WIDTH)
|
||||
if (pos == USAGE_OPTS_WIDTH + 1)
|
||||
pad = -1;
|
||||
else if (pos <= USAGE_OPTS_WIDTH)
|
||||
pad = USAGE_OPTS_WIDTH - pos;
|
||||
else {
|
||||
fputc('\n', outfile);
|
||||
@ -1157,7 +1160,16 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
|
||||
(const char *)opts->value);
|
||||
continue;
|
||||
}
|
||||
fprintf(outfile, "%*s%s\n", pad + USAGE_GAP, "", _(opts->help));
|
||||
|
||||
for (cp = _(opts->help); *cp; cp = np) {
|
||||
np = strchrnul(cp, '\n');
|
||||
fprintf(outfile,
|
||||
"%*s%.*s\n", pad + USAGE_GAP, "",
|
||||
(int)(np - cp), cp);
|
||||
if (*np)
|
||||
np++;
|
||||
pad = USAGE_OPTS_WIDTH;
|
||||
}
|
||||
}
|
||||
fputc('\n', outfile);
|
||||
|
||||
|
@ -133,6 +133,8 @@ int cmd__parse_options(int argc, const char **argv)
|
||||
OPT_STRING(0, "st", &string, "st", "get another string (pervert ordering)"),
|
||||
OPT_STRING('o', NULL, &string, "str", "get another string"),
|
||||
OPT_NOOP_NOARG(0, "obsolete"),
|
||||
OPT_SET_INT_F(0, "longhelp", &integer, "help text of this entry\n"
|
||||
"spans multiple lines", 0, PARSE_OPT_NONEG),
|
||||
OPT_STRING_LIST(0, "list", &list, "str", "add str to list"),
|
||||
OPT_GROUP("Magic arguments"),
|
||||
OPT_NUMBER_CALLBACK(&integer, "set integer to NUM",
|
||||
|
@ -30,11 +30,12 @@ usage: test-tool parse-options <options>
|
||||
-F, --file <file> set file to <file>
|
||||
|
||||
String options
|
||||
-s, --string <string>
|
||||
get a string
|
||||
-s, --string <string> get a string
|
||||
--string2 <str> get another string
|
||||
--st <st> get another string (pervert ordering)
|
||||
-o <str> get another string
|
||||
--longhelp help text of this entry
|
||||
spans multiple lines
|
||||
--list <str> add str to list
|
||||
|
||||
Magic arguments
|
||||
|
Loading…
Reference in New Issue
Block a user