PositionalArgument/NamedArgument
NamedArgument UDA is used to declare an argument that has a name (usually starting with - or --).
PositionalArgument UDA is used to declare an argument that has specific position in the command line.
Signature
Parameters
positionZero-based position of the argument. If it's omitted then positional arguments have an order of their declaration.
placeholderName of this argument that is shown in help text. By default, the name of data member is used.
namesName(s) of this argument that can be used in command line. By default, the name of data member is used.
shortNamesShort name(s) of this argument that can be used in command line.
longNamesLong name(s) of this argument that can be used in command line.
Public members
Description
Description can be used to provide a description of the argument. This text is printed next to the argument in the argument list section of a help message.
Signature
Parameters
textText that contains argument description or a function that returns such text.
Usage example
Hidden
Hidden can be used to indicate that the argument should not be printed in help message or returned in shell completion.
Signature
Parameters
hideIf
truethen argument is not printed in help message.
Usage example
Placeholder
Placeholder provides custom text that is used to indicate the value of the argument in help message.
Signature
Parameters
valueText that is used as a placeholder for a value of an argument in help message.
Usage example
Required
Mark an argument as required so if it is not provided in command line, argparse will error out.
By default all positional arguments are required.
Signature
Usage example
Optional
Mark an argument as optional so it can be omitted in command line without causing errors.
By default all named arguments are optional.
Signature
Usage example
NumberOfValues
NumberOfValues is used to limit number of values that an argument can accept.
Signature
Parameters
minMinimum number of values.
maxMaximum number of values.
numExact number of values.
Usage example
MinNumberOfValues
MinNumberOfValues is used to set minimum number of values that an argument can accept.
Signature
Parameters
minMinimum number of values.
Usage example
MaxNumberOfValues
MaxNumberOfValues is used to set maximum number of values that an argument can accept.
Signature
Parameters
maxMaximum number of values.
Usage example
AllowNoValue
AllowNoValue allows an argument to not have a value in the command line - in this case, the value provided to this function will be used.
Signature
Parameters
valueToUseValue that is used when argument has no value specified in command line.
Usage example
ForceNoValue
ForceNoValue forces an argument to have no value in the command line. The argument is behaving like a boolean flag but instead of true/false values, there can be either a value provided to ForceNoValue or a default one (.init).
Signature
Parameters
valueToUseValue that is used when argument is specified in command line.
Usage example
AllowedValues
AllowedValues can be used to restrict what value can be provided in the command line for an argument.
Signature
Parameters
valuesList of values that an argument can have.
Usage example
Counter
Counter can be used to mark an argument that tracks the number of times it's specified in the command line.
Signature
Usage example
PreValidation
PreValidation can be used to customize the validation of raw string values.
Signature
Parameters
funcFunction that is called to validate raw value. See parsing customization for details.
Usage example
Parse
Parse can be used to provide custom conversion from raw string to a value.
Signature
Parameters
funcFunction that is called to convert raw value. See parsing customization for details.
Usage example
Validation
Validation can be used to validate parsed value.
Signature
Parameters
funcFunction that is called to validate the value. See parsing customization for details.
Usage example
Action
Action can be used to customize a logic of how "destination" should be changed based on parsed argument value.
Signature
Parameters
funcFunction that is called to update the destination. See parsing customization for details.
Usage example