Module cli

Command line utility behaviour.

This module defines the cli behaviour.
Required callback functions: cli/0.

Authors: Maxim Fedorov, (maximfca@gmail.com).

Description

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:

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 GitHub

Data Types

run_options()

run_options() = #{modules => all_loaded | module() | [module()], warn => suppress | warn, help => boolean(), default => term(), prefixes => [integer()], progname => string()}

Function Index

run/1Equivalent to run(Args, #{}).
run/2CLI entry point, parses arguments and executes selected function.

Function Details

run/1

run(Args::[string()]) -> term()

Equivalent to run(Args, #{}).

run/2

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