Skip to content

Commit

Permalink
Merge branch 'sg2342/argparse_regression/OTP-19400' into maint
Browse files Browse the repository at this point in the history
* sg2342/argparse_regression/OTP-19400:
  stdlib: Fix argparse:format_help/2 crash on 'hidden' command
  • Loading branch information
garazdawi committed Dec 17, 2024
2 parents e51ff0c + b2b2331 commit e049e87
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/stdlib/src/argparse.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,8 @@ collect_options(CmdName, Command, [Cmd|Tail], Args) ->
collect_options(CmdName ++ " " ++ Cmd, SubCmd, Tail, Args ++ maps:get(arguments, Command, [])).

%% gets help for sub-command
get_help(#{help := hidden}, []) ->
"";
get_help(Command, []) ->
maps:get(help, Command, "");
get_help(Command, [Cmd|Tail]) ->
Expand Down
16 changes: 16 additions & 0 deletions lib/stdlib/test/argparse_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,22 @@ usage(Config) when is_list(Config) ->
" ---extra extra option very deep\n",
?assertEqual(CrawlerStatus, unicode:characters_to_list(argparse:help(Cmd,
#{progname => "erl", command => ["erl", "status", "crawler"]}))),
RestartCmd = "Usage:\n erl restart [-rfv] [--force] [-i <interval>] [--req <weird>] [--float <float>]\n"
" [-d <duo>] [--duo <duo>] <server>\n"
"\n"
"Arguments:\n"
" server server to restart\n"
"\n"
"Optional arguments:\n"
" -r recursive\n"
" -f, --force force\n"
" -v verbosity level\n"
" -i interval set (int >= 1)\n"
" --req required optional, right?\n"
" --float floating-point long form argument (float), default: 3.14\n"
" -d, --duo dual option\n",
?assertEqual(RestartCmd, unicode:characters_to_list(argparse:help(Cmd,
#{progname => "erl", command => ["restart"]}))),
ok.

usage_required_args() ->
Expand Down

0 comments on commit e049e87

Please sign in to comment.