Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2023-08-04 20:52:31 +0300
committerJunio C Hamano <gitster@pobox.com>2023-08-04 20:52:31 +0300
commitf9712d75e6389866efbe6ad918dc9773a8a880ad (patch)
tree7ac7b2ac560e3be83b5131207c47adcd11c17a7b
parent23b20fff3ab28b31678d23e67de328ac24801f18 (diff)
parentc512643e67d33673933fa3d245be28b08b974755 (diff)
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
-rw-r--r--builtin/remote.c5
-rw-r--r--parse-options.c16
-rw-r--r--t/helper/test-parse-options.c2
-rwxr-xr-xt/t0040-parse-options.sh5
4 files changed, 21 insertions, 7 deletions
diff --git a/builtin/remote.c b/builtin/remote.c
index 479a5191d4..d91bbe728d 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -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")),
diff --git a/parse-options.c b/parse-options.c
index f8a155ee13..87c9fae634 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -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);
diff --git a/t/helper/test-parse-options.c b/t/helper/test-parse-options.c
index 00fa281a9c..a4f6e24b0c 100644
--- a/t/helper/test-parse-options.c
+++ b/t/helper/test-parse-options.c
@@ -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",
diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
index 7d7ecfd571..e19a199636 100755
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
@@ -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