arg_map() = #{argument_name() => term()}
Arguments map: argument name to a term, produced by parser. Supplied to the command handler
arg_type() = boolean | float | {float, Choice::[float()]} | {float, [{min, float()} | {max, float()}]} | integer | {integer, Choices::[integer()]} | {integer, [{min, integer()} | {max, integer()}]} | string | {string, Choices::[string()]} | {string, Re::string()} | {string, Re::string(), ReOptions::[term()]} | binary | {binary, Choices::[binary()]} | {binary, Re::binary()} | {binary, Re::binary(), ReOptions::[term()]} | atom | {atom, Choices::[atom()]} | {atom, unsafe} | {custom, fun((string()) -> term())}
Built-in types include basic validation abilities String and binary validation may use regex match (ignoring captured value). For float, integer, string, binary and atom type, it is possible to specify available choices instead of regex/min/max.
argument() = #{name := argument_name(), short => char(), long => string(), required => boolean(), default => term(), type => arg_type(), action => store | {store, term()} | append | {append, term()} | count | extend, nargs => pos_integer() | 'maybe' | {'maybe', term()} | list | nonempty_list | all, help => hidden | unicode:chardata() | argument_help()}
argument_help() = {unicode:chardata(), [unicode:chardata() | type | default] | fun(() -> unicode:chardata())}
Help template definition for argument. Short and long forms exist for every argument. Short form is printed together with command definition, e.g. "usage: rm [--force]", while long description is printed in detailed section below: "--force forcefully remove".
argument_name() = atom() | string() | binary()
cmd_path() = [string()]
Command path, for nested commands
command() = #{commands => #{string() => command()}, arguments => [argument()], help => hidden | unicode:chardata() | command_help(), handler => handler()}
command_help() = [unicode:chardata() | usage | commands | arguments | options]
Template for the command help/usage message.
handler() = optional | fun((arg_map()) -> term()) | {module(), Fn::atom()} | {fun(() -> term()), term()} | {module(), atom(), term()}
parse_result() = {ok, arg_map(), Path::cmd_path(), command()} | {error, parser_error()}
Parser result: argument map, path leading to successfully matching command (contains only ["progname"] if there were no subcommands matched), and a matching command.
parser_error() = {Path::cmd_path(), Expected::argument() | undefined, Actual::string() | undefined, Details::unicode:chardata()}
Returned from parse/2,3 when command spec is valid, but the command line
cannot be parsed using the spec.
When Expected is undefined, but Actual is not, it means that the input contains
an unexpected argument which cannot be parsed according to command spec.
When Expected is an argument, and Actual is undefined, it means that a mandatory
argument is not provided in the command line.
When both Expected and Actual are defined, it means that the supplied argument
is failing validation.
When both are undefined, there is some logical issue (e.g. a sub-command is required,
but was not selected).
parser_options() = #{prefixes => [char()], default => term(), progname => string() | atom(), command => cmd_path(), columns => pos_integer()}
validator_error() = {otpbp_argparse, command | argument, cmd_path(), Field::atom(), Detail::unicode:chardata()}
| format_error/1 | Basic formatter for the parser error reason. |
| format_error/2 | Transforms exception thrown by validate/1,2 according to EEP54. |
| help/1 | Equivalent to help(Command, #{}).
|
| help/2 | Returns help for Command formatted according to Options specified. |
| parse/2 | Equivalent to parse(Args, Command, #{}).
|
| parse/3 | Parses supplied arguments according to expected command specification. |
| run/3 | |
| validate/1 | Equivalent to validate(Command, #{}).
|
| validate/2 | Validate command specification, taking Options into account. |
format_error(Reason::parser_error()) -> unicode:chardata()
Basic formatter for the parser error reason.
format_error(Reason::validator_error(), X2::erlang:stacktrace()) -> map()
Transforms exception thrown by validate/1,2 according to EEP54.
Use erl_error:format_exception/3,4 to get the shell-like output.
help(Command::command()) -> string()
Equivalent to help(Command, #{}).
help(Command::command(), Options::parser_options()) -> unicode:chardata()
Returns help for Command formatted according to Options specified
parse(Args::[string()], Command::command()) -> parse_result()
Equivalent to parse(Args, Command, #{}).
parse(Args::[string()], Command::command(), Options::parser_options()) -> parse_result()
Args: command line arguments (e.g. init:get_plain_arguments())
returns: argument map, or argument map with deepest matched command definition.
Parses supplied arguments according to expected command specification.
run(Args::[string()], Command::command(), Options::parser_options()) -> term()
validate(Command::command()) -> Progname::string()
Equivalent to validate(Command, #{}).
validate(Command::command(), Options::parser_options()) -> Progname::string()
Validate command specification, taking Options into account. Raises an error if the command specification is invalid.
Generated by EDoc