Command Line¶
Concourse Tools uses a custom CLI tool for easier management of command line functions.
- class concoursetools.cli.parser.CLI[source]¶
Represents a command line interface.
- register(allow_short=None)[source]¶
Decorate a function.
The decorated function will be registered as a command. Positional-only parameters will become arguments and keyword-only parameters will become options. All parameters must be one or the other.
- register_function(func, allow_short=None)[source]¶
Manually register a function.
- Parameters:
func (
Callable[...,None]) – A function to be registered as a command. Positional-only parameters will become arguments and keyword-only parameters will become options. All parameters must be one or the other.allow_short (
set[str] |None) – A set of function parameters that are allowed a one-letter alias. By default, the parametermy_parameterbecomes--my-parameter, but by includingmy_parameterin this set,-mwill also be valid on the command line.
- Return type:
- class concoursetools.cli.parser.CLICommand(name, description, inner_function, inner_parser, positional_arguments, options)[source]¶
Represents a command in a CLI.
- Parameters:
name (
str) – The name of the command.description (
str|None) – An optional description of the command.inner_function (
Callable[...,None]) – The function on which the command is based.inner_parser (
ArgumentParser) – Used to parse the arguments for the command.positional_arguments (
list[PositionalArgument[Any]]) – A list of positional arguments.
- classmethod from_function(func, allow_short=None)[source]¶
Create a new parser from a function.
- Parameters:
func (
Callable[...,None]) – A function to be registered as a command. Positional-only parameters will become arguments and keyword-only parameters will become options. All parameters must be one or the other.allow_short (
set[str] |None) – A set of function parameters that are allowed a one-letter alias. By default, the parametermy_parameterbecomes--my-parameter, but by includingmy_parameterin this set,-mwill also be valid on the command line.
- Return type:
- class concoursetools.cli.docstring.Docstring(first_line, description, parameters)[source]¶
Represents a function docstring.
- Parameters:
Parameters¶
- class concoursetools.cli.parser.PositionalArgument(name, param_type, description=None)[source]¶
Represents a positional function/CLI parameter.
- class concoursetools.cli.parser.Option(name, param_type, description=None, default=None, allow_short=False)[source]¶
Represents a generic function/CLI option.
- Parameters:
name (
str) – The name of the option.param_type (
type[TypeVar(T)]) – The Python type of the option.description (
str|None) – An optional description of the option.default (
Optional[TypeVar(T)]) – The option default, if set.allow_short (
bool) – Set toTrueto allow a short option, i.e.-oas well as--option.
- class concoursetools.cli.parser.FlagOption(name, description, default)[source]¶
Represents a generic function/CLI flag.
- class concoursetools.cli.parser.Parameter(name, param_type, description=None)[source]¶
Represents a generic function/CLI parameter.
- Parameters:
- property long_alias: str¶
The long alias for the parameter.
- Example:
>>> Option("my_option", str).long_alias '--my-option'
- property short_alias: str¶
The short alias for the parameter.
- Example:
>>> Option("my_option", str).short_alias '-m'
- abstractmethod add_to_parser(parser)[source]¶
Add the parameter to a parser.
- Parameters:
parser (
ArgumentParser) – The parser in question.- Seealso:
This is done using
argparse.ArgumentParser.add_argument().- Return type:
- classmethod yield_from_function(func, allow_short)[source]¶
Yield parameters from a function.
Parameters are parsed from the docstring using a combination of
inspect.signature()andconcoursetools.cli.docstring.Docstring.from_object().- Parameters:
- Return type: