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 givenCommand
may allow a variable / unbound number of arguments. SeeNargs
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 tostore
whennargs=1
, and toappend
otherwise. A single value will be stored whenaction='store'
, and a list of values will be stored whenaction='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 andaction='store'
, then this will default toNone
; ifaction='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. UseTrue
/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, useFalse
/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 ofPositional
andOption
classes.