cli
cli_integration_token(integration, env_var)
¶
Return a function that takes in a parser.
This generated function registers a token argument in the parser which looks for its value in the environment variables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
integration |
str
|
The name of the integration. |
required |
env_var |
str
|
The environment variable name. |
required |
Returns:
Type | Description |
---|---|
cli_global_option
|
A function to add arguments to an argparse parser. |
Source code in m/cli/cli.py
exec_cli(cli_commands)
¶
Execute the cli application.
usage::
def create_cli_commands() -> CliCommands:
# We may import CliCommand objects from other projects and create
# a new one with them.
return import_cli_commands('cli.command.module')
def main():
cli_commands = create_cli_commands()
exec_cli(cli_commands)
This is the preferred way to execute the cli application as it will allow other potential applications to use the cli commands.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cli_commands |
CliCommands
|
The cli commands to execute. |
required |
Source code in m/cli/cli.py
run_cli(commands_module, add_args=None)
¶
Run the cli application.
Deprecated, use exec_cli
instead.
usage::
def add_args(argp):
argp.add_argument(...)
def main():
run_cli('m.cli.commands', add_args)
We only need add_args
if we need to gain access to the
argparse.ArgumentParser
instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
commands_module |
str | None
|
The full name of the module containing the commands. |
required |
add_args |
Callable[[ArgumentParser], None] | None
|
Optional callback to gain access to the ArgumentParser. |
None
|
Source code in m/cli/cli.py
run_main(callback, result_handler=default_result_handler, issue_handler=default_issue_handler)
¶
Run the callback and print the returned value.
To change how the result or an issue should be display provide the optional
arguments handle_result
and handle_issue
. For instance, to display the
raw value provide the print
function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
callback |
Callable[[], OneOf[Issue, Any]]
|
A function that returns a |
required |
result_handler |
Callable[[Any], None]
|
A function that takes in the Good result. |
default_result_handler
|
issue_handler |
Callable[[Issue], None]
|
A function that takes in the Issue. |
default_issue_handler
|
Returns:
Type | Description |
---|---|
int
|
0 if the callback is a |