Argument: CLI arguments/flags

class invoke.parser.argument.Argument(name=None, names=(), kind=<type 'str'>, default=None, help=None, positional=False, optional=False, attr_name=None)

A command-line argument/flag.

Parameters:
  • name – Syntactic sugar for names=[<name>]. Giving both name and names is invalid.
  • names – List of valid identifiers for this argument. For example, a “help” argument may be defined with a name list of ['-h', '--help'].
  • kind – Type factory & parser hint. E.g. int will turn the default text value parsed, into a Python integer; and bool will tell the parser not to expect an actual value but to treat the argument as a toggle/flag.
  • default – Default value made available to the parser if no value is given on the command line.
  • help – Help text, intended for use with --help.
  • positional – Whether or not this argument’s value may be given positionally. When False (default) arguments must be explicitly named.
  • optional – Whether or not this (non-bool) argument requires a value.
  • attr_name – A Python identifier/attribute friendly name, typically filled in with the underscored version when name/names contain dashes.
name

The canonical attribute-friendly name for this argument.

Will be attr_name (if given to constructor) or the first name in names otherwise.

set_value(value, cast=True)

Actual explicit value-setting API call.

Sets self.raw_value to value directly.

Sets self.value to self.kind(value), unless cast=False in which case the raw value is also used.

Previous topic

parser: Command-line parser

Next topic

Context: Task-oriented parser context

This Page