This module defines the cli behaviour.
Required callback functions: cli/0.
Authors: Maxim Fedorov, (maximfca@gmail.com).
Command line utility behaviour. Usage example:
From an escript main/1 function (requires-mode(compile)):
cli:run(Args).Or, to limit cli behaviour discovery,
cli:run(Args, #{modules => ?MODULE, progname => ?MODULE}).
Other options available for run/2:
modules:all_loaded - search all loaded modules (code:all_loaded()) for cli behaviourmodule() - use this module (must export cli/0)cli/0)warn: set to suppress suppresses warnings loggedhelp: set to false suppresses printing usage when parser produces
an error, and disables default --help/-h behaviourdefault: deprecated, value to use for cli/1 callback in a positional formprefixes: prefixes passed to argparseprogname: specifies executable name instead of 'erl'Warnings are printed to OTP logger, unless suppressed.
cli framework attempts to create a handler for each command exported, including intermediate (non-leaf) commands, if it can find function exported with suitable signature.
cli examples are available on GitHubrun_options() = #{modules => all_loaded | module() | [module()], warn => suppress | warn, help => boolean(), default => term(), prefixes => [integer()], progname => string()}
| run/1 | Equivalent to run(Args, #{}). |
| run/2 | CLI entry point, parses arguments and executes selected function. |
run(Args::[string()]) -> term()
Equivalent to run(Args, #{}).
run(Args::[string()], Options::run_options()) -> term()
Args: arguments used to run CLI, e.g. init:get_plain_arguments().
returns: callback result, ok 'ok' when help/error message printed.
CLI entry point, parses arguments and executes selected function. Finds all modules loaded, and implementing cli behaviour, then matches a command and runs handler defined for a command.
Generated by EDoc