Actions Module

Parameter actions define how Parameters behave when processing values that were provided via CLI or environment variables.

class cli_command_parser.parameters.actions.ParamAction(param: Param)[source]

Bases: ABC

name: str
default: TD = <object object>
accepts_values: bool = False
accepts_consts: bool = False
classmethod __init_subclass__(default: ~cli_command_parser.parameters.actions.TD = <object object>, accepts_values: bool = None, accepts_consts: bool = None, **kwargs)[source]
param
abstract property default_nargs: Nargs[source]
abstract add_value(value: str, *, combo: bool = False, joined: bool = False, env_var: str = None) int | NoReturn[source]

Execute this action for the given Parameter and value.

Parameters:
  • value – The value that was provided, if any.

  • combo – Only True when a short option was provided, where the option string was combined with either a real value or a sequence of 1-char combinable versions of short option strings.

  • joined – True if the value was provided as --option=value, False otherwise.

  • env_var – The name of the environment variable that was used as the source of the given value, if applicable.

Returns:

The number of new values discovered

add_env_value(value: str, env_var: str) int | NoReturn[source]
add_const(*, opt: str = None, combo: bool = False) int | NoReturn[source]
would_accept(value: str, combo: bool = False) bool[source]
get_maybe_poppable_counts() list[int][source]
Returns:

The indexes on which the parsed values may be split such that the remaining number of values will still be acceptable for the Parameter’s nargs.

can_reset() bool[source]
get_default(command: CommandObj | None = None, missing_default=<object object>)[source]
finalize_default(value)[source]
finalize_value(value)[source]
class cli_command_parser.parameters.actions.ValueMixin[source]

Bases: object

param: Param
get_default: Callable
set_value(value)[source]
append_value(value)[source]
class cli_command_parser.parameters.actions.ConstMixin[source]

Bases: object

param: Param
get_default: Callable
add_const: Callable
add_value: Callable
classmethod __init_subclass__(append: bool = False, **kwargs)[source]
set_const(const)[source]
append_const(const)[source]
add_env_value(value: str, env_var: str) int | NoReturn[source]
class cli_command_parser.parameters.actions.Store(param: Param)[source]

Bases: ValueMixin, ParamAction

default_nargs = Nargs(1)
add_value(value: str, *, combo: bool = False, joined: Bool = False, env_var: str = None) Found[source]
would_accept(value: str, combo: bool = False) bool[source]
accepts_values: bool = True
default: TD = None
name: str = 'store'
class cli_command_parser.parameters.actions.Append(param: Param)[source]

Bases: ValueMixin, ParamAction

default_nargs = Nargs('+')
add_value(value: str, *, combo: bool = False, joined: Bool = False, env_var: str = None) Found[source]
would_accept(value: str, combo: bool = False) bool[source]
get_maybe_poppable_counts() list[int][source]
Returns:

The indexes on which the parsed values may be split such that the remaining number of values will still be acceptable for the Parameter’s nargs.

can_reset() bool[source]
get_default(command: CommandObj | None = None, missing_default=<object object>)[source]
finalize_default(value)[source]
finalize_value(value)[source]
accepts_values: bool = True
name: str = 'append'
class cli_command_parser.parameters.actions.BasicConstAction(param: Param)[source]

Bases: ConstMixin, ParamAction, ABC

default_nargs = Nargs(0)
add_value(value: str, *, combo: bool = False, joined: Bool = False, env_var: str = None) Found[source]
would_accept(value: str, combo: bool = False) bool[source]
accepts_consts: bool = True
name: str = 'basic_const_action'
class cli_command_parser.parameters.actions.StoreConst(param: Param)[source]

Bases: BasicConstAction

add_const(*, opt: str = None, combo: bool = False) int | NoReturn[source]
default: TD = None
name: str = 'store_const'
class cli_command_parser.parameters.actions.AppendConst(param: Param)[source]

Bases: BasicConstAction

add_const(*, opt: str = None, combo: bool = False) int | NoReturn[source]
get_default(command: CommandObj | None = None, missing_default=<object object>)[source]
name: str = 'append_const'
class cli_command_parser.parameters.actions.Count(param: Param)[source]

Bases: ParamAction

default_nargs = Nargs('?')
add_const(*, opt: str = None, combo: bool = False) int | NoReturn[source]
add_value(value: str, *, combo: bool = False, joined: Bool = False, env_var: str = None) Found[source]
accepts_consts: bool = True
accepts_values: bool = True
name: str = 'count'
class cli_command_parser.parameters.actions.Concatenate(param: Param)[source]

Bases: Append

add_value(value: str, *, combo: bool = False, joined: Bool = False, env_var: str = None) Found[source]
finalize_default(value)[source]
finalize_value(value)[source]
name: str = 'concatenate'
class cli_command_parser.parameters.actions.StoreAll(param: Param)[source]

Bases: Store

default_nargs = Nargs('REMAINDER')
add_values(values: list[str], *, combo: bool = False) int | NoReturn[source]
name: str = 'store_all'