Skip to content

Commit

Permalink
argparse: Make formatting of argument descriptions less ambiguous
Browse files Browse the repository at this point in the history
  • Loading branch information
jhogberg committed Jul 11, 2023
1 parent 11e2308 commit 6cf78b4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/stdlib/src/argparse.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1252,17 +1252,21 @@ format_description(#{help := {_Short, Desc}} = Opt) ->
String
end, Desc
);
%% default format: "desc", "desc (type)", "desc (default)", "desc (type, default)"
%% default format:
%% "desc"
%% "desc (type)"
%% "desc, default: abc"
%% "desc (type), default: abc"
format_description(#{name := Name} = Opt) ->
NameStr = maps:get(help, Opt, io_lib:format("~ts", [Name])),
case {NameStr, format_type(Opt), format_default(Opt)} of
{"", "", Type} -> Type;
{"", Default, ""} -> Default;
{Desc, "", ""} -> Desc;
{Desc, "", Default} -> [Desc, " (", Default, ")"];
{Desc, "", Default} -> [Desc, " , default: ", Default];
{Desc, Type, ""} -> [Desc, " (", Type, ")"];
{"", Type, Default} -> [Type, ", ", Default];
{Desc, Type, Default} -> [Desc, " (", Type, ", ", Default, ")"]
{"", Type, Default} -> [Type, ", default: ", Default];
{Desc, Type, Default} -> [Desc, " (", Type, "), default: ", Default]
end.

%% option formatting helpers
Expand Down

0 comments on commit 6cf78b4

Please sign in to comment.