This module defines the cli behaviour.
Required callback functions: cli/0.
Optional callback functions: cli/1.
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}).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 disabled default --help/-h behaviourhandler
controls which handler form is going to be used to generate
default handler, and value to use for missing argumentsWarnings 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