PositionalArgument/NamedArgument
PositionalArgument
UDA is used to declare an argument that has specific position in the command line.
Signature
Parameters
position
Zero-based unsigned position of the argument.
placeholder
Name of this argument that is shown in help text. By default, the name of data member is used.
names
Name(s) of this argument that can be used in command line. By default, the name of data member is used.
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
text
Text 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
hide
If
true
then 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
value
Text 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
min
Minimum number of values.
max
Maximum number of values.
num
Exact number of values.
Usage example
MinNumberOfValues
MinNumberOfValues
is used to set minimum number of values that an argument can accept.
Signature
Parameters
min
Minimum number of values.
Usage example
MaxNumberOfValues
MaxNumberOfValues
is used to set maximum number of values that an argument can accept.
Signature
Parameters
max
Maximum 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
valueToUse
Value that is used when argument has no value specified in command line.
Usage example
RequireNoValue
RequireNoValue
requires 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 this function or a default one (.init
).
Signature
Parameters
valueToUse
Value 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
values
List 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
func
Function 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
func
Function 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
func
Function 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
func
Function that is called to update the destination. See parsing customization for details.
Usage example