Skip to content

Commit 27e2ea9

Browse files
committed
Merge branch 'rs/parse-options-help-text-is-optional'
It may be tempting to leave the help text NULL for a command line option that is either hidden or too obvious, but "git subcmd -h" and "git subcmd --help-all" would have segfaulted if done so. Now the help text is optional. * rs/parse-options-help-text-is-optional: parse-options: allow omitting option help text
2 parents d814540 + cd52d9e commit 27e2ea9

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

parse-options.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,14 +1186,15 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
11861186
continue;
11871187
}
11881188

1189-
for (cp = _(opts->help); *cp; cp = np) {
1189+
for (cp = opts->help ? _(opts->help) : ""; *cp; cp = np) {
11901190
np = strchrnul(cp, '\n');
1191-
usage_padding(outfile, pos);
1192-
fprintf(outfile, "%.*s\n", (int)(np - cp), cp);
11931191
if (*np)
11941192
np++;
1193+
usage_padding(outfile, pos);
1194+
fwrite(cp, 1, np - cp, outfile);
11951195
pos = 0;
11961196
}
1197+
fputc('\n', outfile);
11971198

11981199
if (positive_name) {
11991200
if (find_option_by_long_name(all_opts, positive_name))

0 commit comments

Comments
 (0)