Positionals Module

Positional Parameters

author:

Doug Skrypa

class cli_command_parser.parameters.positionals.Positional(nargs: NargsValue = None, action: Literal['store', 'append'] = None, type: InputTypeFunc = None, default: Any = <object object>, *, default_cb: DefaultFunc = None, choices: ChoicesType = None, allow_leading_dash: LeadingDash = None, **kwargs)[source]

Bases: BasePositional

A parameter that must be provided positionally.

Parameters:
  • nargs – The number of values that are expected/required for this parameter. Defaults to 1. Use a value that allows 0 values to have the same effect as making this parameter not required (the required option is not supported for Positional parameters). Only the last Positional parameter in a given Command may allow a variable / unbound number of arguments. See Nargs for more info.

  • action – The action to take on individual parsed values. Actions must be defined as methods in classes that extend Parameter, and must be registered via parameter_action. Defaults to store when nargs=1, and to append otherwise. A single value will be stored when action='store', and a list of values will be stored when action='append'.

  • type – A callable (function, class, etc.) that accepts a single string argument, which should be called on every value for this parameter to transform the value. By default, no transformation is performed, and values will be strings. If not specified, but a type annotation is detected, then that annotation will be used as if it was provided here. When both are present, this argument takes precedence.

  • default – Only supported when 0 values are allowed by the specified nargs. If not specified and action='store', then this will default to None; if action='append', and no values are provided, then an empty list will be returned for this Parameter.

  • choices – A container that holds the specific values that users must pick from. By default, any value is allowed.

  • allow_leading_dash – Whether string values may begin with a dash (-). By default, if a value begins with a dash, it is only accepted if it appears to be a negative numeric value. Use True / always / AllowLeadingDash.ALWAYS to allow any value that begins with a dash (as long as it is not an option string for an Option/Flag/etc). To reject all values beginning with a dash, including numbers, use False / never / AllowLeadingDash.NEVER.

  • kwargs – Additional keyword arguments to pass to BasePositional.

allow_leading_dash: AllowLeadingDash

Custom value normalizer/validator for the allow_leading_dash property of Positional and Option classes.