Allow usage message to be printed to stderr (default) as well as stdout
This commit is contained in:
parent
2981dfe63e
commit
ca5eb9ad09
@ -53,6 +53,8 @@
|
|||||||
ArgSpec :: arg_spec(),
|
ArgSpec :: arg_spec(),
|
||||||
Help :: string() | undefined
|
Help :: string() | undefined
|
||||||
}.
|
}.
|
||||||
|
%% Output streams
|
||||||
|
-type output_stream() :: 'standard_io' | 'standard_error'.
|
||||||
|
|
||||||
|
|
||||||
%% @doc Parse the command line options and arguments returning a list of tuples
|
%% @doc Parse the command line options and arguments returning a list of tuples
|
||||||
@ -371,34 +373,58 @@ is_float_arg([]) ->
|
|||||||
true.
|
true.
|
||||||
|
|
||||||
|
|
||||||
%% @doc Show a message on stdout indicating the command line options and
|
%% @doc Show a message on stderr indicating the command line options and
|
||||||
%% arguments that are supported by the program.
|
%% arguments that are supported by the program.
|
||||||
-spec usage([option_spec()], string()) -> ok.
|
-spec usage([option_spec()], string()) -> ok.
|
||||||
usage(OptSpecList, ProgramName) ->
|
usage(OptSpecList, ProgramName) ->
|
||||||
io:format("Usage: ~s~s~n~n~s~n",
|
usage(OptSpecList, ProgramName, standard_error).
|
||||||
[ProgramName, usage_cmd_line(OptSpecList), usage_options(OptSpecList)]).
|
|
||||||
|
|
||||||
|
|
||||||
%% @doc Show a message on stdout indicating the command line options and
|
%% @doc Show a message on stderr or stdout indicating the command line options and
|
||||||
|
%% arguments that are supported by the program.
|
||||||
|
-spec usage([option_spec()], string(), output_stream()) -> ok.
|
||||||
|
usage(OptSpecList, ProgramName, OutputStream) when is_atom(OutputStream) ->
|
||||||
|
io:format(OutputStream, "Usage: ~s~s~n~n~s~n",
|
||||||
|
[ProgramName, usage_cmd_line(OptSpecList), usage_options(OptSpecList)]);
|
||||||
|
|
||||||
|
|
||||||
|
%% @doc Show a message on stderr indicating the command line options and
|
||||||
%% arguments that are supported by the program. The CmdLineTail argument
|
%% arguments that are supported by the program. The CmdLineTail argument
|
||||||
%% is a string that is added to the end of the usage command line.
|
%% is a string that is added to the end of the usage command line.
|
||||||
-spec usage([option_spec()], string(), string()) -> ok.
|
-spec usage([option_spec()], string(), string()) -> ok.
|
||||||
usage(OptSpecList, ProgramName, CmdLineTail) ->
|
usage(OptSpecList, ProgramName, CmdLineTail) ->
|
||||||
io:format("Usage: ~s~s ~s~n~n~s~n",
|
usage(OptSpecList, ProgramName, CmdLineTail, standard_error).
|
||||||
[ProgramName, usage_cmd_line(OptSpecList), CmdLineTail, usage_options(OptSpecList)]).
|
|
||||||
|
|
||||||
|
|
||||||
%% @doc Show a message on stdout indicating the command line options and
|
%% @doc Show a message on stderr or stdout indicating the command line options and
|
||||||
|
%% arguments that are supported by the program. The CmdLineTail argument
|
||||||
|
%% is a string that is added to the end of the usage command line.
|
||||||
|
-spec usage([option_spec()], string(), string(), output_stream()) -> ok.
|
||||||
|
usage(OptSpecList, ProgramName, CmdLineTail) when is_atom(OutputStream) ->
|
||||||
|
io:format(OutputStream, "Usage: ~s~s ~s~n~n~s~n",
|
||||||
|
[ProgramName, usage_cmd_line(OptSpecList), CmdLineTail, usage_options(OptSpecList)]);
|
||||||
|
|
||||||
|
|
||||||
|
%% @doc Show a message on stderr indicating the command line options and
|
||||||
%% arguments that are supported by the program. The CmdLineTail and OptionsTail
|
%% arguments that are supported by the program. The CmdLineTail and OptionsTail
|
||||||
%% arguments are a string that is added to the end of the usage command line
|
%% arguments are a string that is added to the end of the usage command line
|
||||||
%% and a list of tuples that are added to the end of the options' help lines.
|
%% and a list of tuples that are added to the end of the options' help lines.
|
||||||
-spec usage([option_spec()], string(), string(), [{string(), string()}]) -> ok.
|
-spec usage([option_spec()], string(), string(), [{string(), string()}]) -> ok.
|
||||||
usage(OptSpecList, ProgramName, CmdLineTail, OptionsTail) ->
|
usage(OptSpecList, ProgramName, CmdLineTail, OptionsTail) ->
|
||||||
|
usage(OptSpecList, ProgramName, CmdLineTail, OptionsTail, standard_error).
|
||||||
|
|
||||||
|
|
||||||
|
%% @doc Show a message on stderr or stdout indicating the command line options and
|
||||||
|
%% arguments that are supported by the program. The CmdLineTail and OptionsTail
|
||||||
|
%% arguments are a string that is added to the end of the usage command line
|
||||||
|
%% and a list of tuples that are added to the end of the options' help lines.
|
||||||
|
-spec usage([option_spec()], string(), string(), [{string(), string()}], output_stream()) -> ok.
|
||||||
|
usage(OptSpecList, ProgramName, CmdLineTail, OptionsTail, OutputStream) ->
|
||||||
UsageOptions = lists:foldl(
|
UsageOptions = lists:foldl(
|
||||||
fun ({Prefix, Help}, Acc) ->
|
fun ({Prefix, Help}, Acc) ->
|
||||||
add_option_help(Prefix, Help, Acc)
|
add_option_help(Prefix, Help, Acc)
|
||||||
end, usage_options_reverse(OptSpecList, []), OptionsTail),
|
end, usage_options_reverse(OptSpecList, []), OptionsTail),
|
||||||
io:format("Usage: ~s~s ~s~n~n~s~n",
|
io:format(OutputStream, "Usage: ~s~s ~s~n~n~s~n",
|
||||||
[ProgramName, usage_cmd_line(OptSpecList), CmdLineTail,
|
[ProgramName, usage_cmd_line(OptSpecList), CmdLineTail,
|
||||||
lists:flatten(lists:reverse(UsageOptions))]).
|
lists:flatten(lists:reverse(UsageOptions))]).
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user