Codebase list erlang-getopt / fada7cf
Add long description option to usage. Introduce a new usage/6 that allows a long description to be specified, which allows for usage output that documents structured command lines using not just short/long options. For example, commands like the following: $ command group <group_name> create Paul Fisher 7 years ago
1 changed file(s) with 17 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
1111 -author('juanjo@comellas.org').
1212
1313 -export([parse/2, check/2, parse_and_check/2, format_error/2,
14 usage/2, usage/3, usage/4, tokenize/1]).
14 usage/2, usage/3, usage/4, usage/6, tokenize/1]).
1515 -export([usage_cmd_line/2]).
1616
1717 -define(LINE_LENGTH, 75).
572572 usage(OptSpecList, ProgramName, CmdLineTail, OptionsTail, OutputStream) ->
573573 io:format(OutputStream, "~ts~n~n~ts~n",
574574 [unicode:characters_to_list(usage_cmd_line(ProgramName, OptSpecList, CmdLineTail)), unicode:characters_to_list(usage_options(OptSpecList, OptionsTail))]).
575
576 %% @doc Show a message on standard_error or standard_io indicating the
577 %% command line options and arguments that are supported by the
578 %% program. The Description allows for structured command line usage
579 %% that works in addition to the standard options, and appears between
580 %% the usage_cmd_line and usage_options sections. The CmdLineTail and
581 %% OptionsTail arguments are a string that is added to the end of the
582 %% usage command line and a list of tuples that are added to the end of
583 %% the options' help lines.
584 -spec usage([option_spec()], ProgramName :: string(), CmdLineTail :: string(),
585 Description :: string(),
586 [{OptionName :: string(), Help :: string()}],
587 output_stream()) -> ok.
588 usage(OptSpecList, ProgramName, CmdLineTail, Description, OptionsTail, OutputStream) ->
589 io:format(OutputStream, "~ts~n~n~ts~n~n~ts~n",
590 [unicode:characters_to_list(usage_cmd_line(ProgramName, OptSpecList, CmdLineTail)), Description, unicode:characters_to_list(usage_options(OptSpecList, OptionsTail))]).
575591
576592
577593 -spec usage_cmd_line(ProgramName :: string(), [option_spec()]) -> iolist().