Reference
CLI
CLI(
title: str,
version: Optional[str] = None,
console: Optional[Console] = None,
handler: Optional[callable] = None,
description: Optional[str] = None,
usage: Optional[str] = None,
options: Optional[List[Option]] = None,
arguments: Optional[List[Argument]] = None,
help_flags: Optional[List[str]] = None,
version_flags: Optional[List[str]] = None,
global_options: Optional[List[Option]] = None,
global_arguments: Optional[List[Argument]] = None,
subcommands: Optional[List[Command]] = None,
)
Operations for displaying "help" and "version" information are handled automatically and reserve the flags ["--help", "-h"] and ["--version", "-V"] respectively.
Parameters:
-
(titlestr) –The title of the CLI tool.
-
(versionOptional[str], default:None) –The version of the CLI tool.
-
(consoleOptional[Console], default:None) –The Console object to use for displaying outputs for the CLI tool.
-
(handlerOptional[callable], default:None) –The function to execute when the base CLI command is called. If not provided, root command will only display help and version information.
-
(descriptionOptional[str], default:None) –The description of the base CLI command.
-
(usageOptional[str], default:None) –The usage information for the base CLI command. Defaults to "[SUBCOMMANDS][OPTIONS][ARGUMENTS]" if not provided.
-
(optionsOptional[List[Option]], default:None) –The options available for the base CLI command.
-
(argumentsOptional[List[Argument]], default:None) –The arguments available for the base CLI command
-
(help_flagsOptional[List[str]], default:None) –The flag overrides for CLI help operation. Defaults to ["-h", "--help"] if not provided.
-
(version_flagsOptional[List[str]], default:None) –The flag overrides for CLI version operation. Defaults to ["-V", "--version"] if not provided.
-
(global_optionsOptional[List[Option]], default:None) –The global options available for the base CLI command and any subcommands.
-
(global_argumentsOptional[List[Argument]], default:None) –The global arguments available for the base CLI command and any subcommands.
-
(subcommandsOptional[List[Command]], default:None) –The subcommands available for the base CLI command.
Methods:
-
add_argument–Add an argument to the command.
-
add_arguments–Add multiple arguments to the command.
-
add_global_argument– -
add_global_arguments– -
add_global_option– -
add_global_options– -
add_option–Add an option to the command.
-
add_options–Add multiple options to the command.
-
add_subcommand–Add a subcommand to the command.
-
add_subcommands–Add multiple subcommands to the command.
-
display_help–Display help information for the CLI tool.
-
execute– -
find_subcommand–Find a subcommand by name.
-
flag_to_option–Get an option by flag.
-
parse_cli–Return the commands and arguments parsed from the command string.
-
run–Executes CLI tool based handlers, options, and arguments in
Attributes:
-
all_argument_names(List[str]) –Gather all argument names available to the command.
-
all_arguments(List[Argument]) –Gather all arguments available to the command.
-
all_option_flags(List[str]) –Gather all option flags available to the command.
-
all_option_long_names(List[str]) –Gather all long option names available to the command.
-
all_option_names(List[str]) –Gather all option names available to the command.
-
all_option_short_names(List[str]) –Gather all short option names available to the command.
-
all_options(List[Option]) –Gather all options available to the command.
-
all_subcommand_names(List[str]) –Gather all subcommand names available to the command.
-
arguments– -
console– -
description– -
global_arguments– -
global_options– -
handler– -
help_flags– -
inherit_arguments– -
inherit_options– -
inherited_arguments(List[Argument]) –Gather arguments inherited from parent commands if inheritance is enabled.
-
inherited_options(List[Option]) –Gather options inherited from parent commands if inheritance is enabled.
-
name– -
options– -
subcommands– -
title– -
usage– -
version– -
version_flags–
Source code in saiuncli/cli.py
all_argument_names
property
Gather all argument names available to the command.
all_option_flags
property
Gather all option flags available to the command.
all_option_long_names
property
Gather all long option names available to the command.
all_option_names
property
Gather all option names available to the command.
all_option_short_names
property
Gather all short option names available to the command.
all_subcommand_names
property
Gather all subcommand names available to the command.
inherited_arguments
property
inherited_arguments: List[Argument]
Gather arguments inherited from parent commands if inheritance is enabled.
inherited_options
property
inherited_options: List[Option]
Gather options inherited from parent commands if inheritance is enabled.
add_argument
add_argument(argument: Argument)
add_arguments
add_arguments(arguments: List[Argument])
add_global_argument
add_global_argument(argument: Argument)
add_global_arguments
add_global_arguments(arguments: List[Argument])
add_global_option
add_global_option(option: Option)
add_global_options
add_global_options(options: List[Option])
add_option
add_option(option: Option)
add_options
add_options(options: List[Option])
add_subcommands
add_subcommands(subcommands: List[Command])
Add multiple subcommands to the command.
Source code in saiuncli/command.py
display_help
Display help information for the CLI tool.
Parameters:
-
(commandCommand, default:None) –The command to display help for.
Source code in saiuncli/cli.py
execute
find_subcommand
find_subcommand(name: str) -> Optional[Command]
flag_to_option
flag_to_option(flag: str) -> Optional[Option]
parse_cli
parse_cli() -> ParsedCLI
Return the commands and arguments parsed from the command string.
Returns:
-
ParsedCLI(ParsedCLI) –The parsed commands and arguments.
Source code in saiuncli/cli.py
run
run(parsed_cli: Optional[ParsedCLI] = None)
Executes CLI tool based handlers, options, and arguments in the ParsedCLI.
Parameters:
-
(parsed_cliOptional[ParsedCLI], default:None) –If not provided, CLI will be parsed by calling
self.parse_cli()
Source code in saiuncli/cli.py
ParsedCLI
ParsedCLI(
commands: List[str],
parsed_options: Dict[str, Any],
parsed_args: Dict[str, Any],
help: bool = False,
version: bool = False,
)
Parameters:
-
(commandsList[str]) –List of commands parsed from the CLI input.
-
(parsed_optionsDict[str, Any]) –Dictionary of option names and their values.
-
(parsed_argsDict[str, Any]) –Dictionary of argument names and their values.
Methods:
Attributes:
-
commands– -
help– -
parsed_args– -
parsed_options– -
version–