Skip to content

Commit

Permalink
Merge branch 'rs/parse-options-help-text-is-optional'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gitster committed Sep 5, 2023
2 parents d814540 + cd52d9e commit 27e2ea9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions parse-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -1186,14 +1186,15 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
continue;
}

for (cp = _(opts->help); *cp; cp = np) {
for (cp = opts->help ? _(opts->help) : ""; *cp; cp = np) {
np = strchrnul(cp, '\n');
usage_padding(outfile, pos);
fprintf(outfile, "%.*s\n", (int)(np - cp), cp);
if (*np)
np++;
usage_padding(outfile, pos);
fwrite(cp, 1, np - cp, outfile);
pos = 0;
}
fputc('\n', outfile);

if (positive_name) {
if (find_option_by_long_name(all_opts, positive_name))
Expand Down

0 comments on commit 27e2ea9

Please sign in to comment.