Base class for all configuration options.
An Opt object has no public methods, but has a number of public string properties:
- name:
- the name of the option, which may include hyphens
- type:
- a callable object that takes string and returns converted and validated value
- dest:
- the (hyphen-less) ConfigOpts property which contains the option value
- short:
- a single character CLI option name
- default:
- the default value of the option
- sample_default:
- a sample default value string to include in sample config files
- positional:
- True if the option is a positional CLI argument
- metavar:
- the name shown as the argument to a CLI option in –help output
- help:
- an string explaining how the options value is used
Option with String type (for backward compatibility).
Parameters: | choices – Optional sequence of valid values. |
---|
Boolean options.
Bool opts are set to True or False on the command line using –optname or –noopttname respectively.
In config files, boolean values are cast with Boolean type.
Opt with Integer type (for backward compatibility).
Opt with Float type (for backward compatibility).
Opt with List(String) type (for backward compatibility).
Opt with Dict(String) type (for backward compatibility).
Multi opt with MultiString item type (for backward compatibility).
Opt with IPAddress type (either IPv4, IPv6 or both).
Represents a Deprecated option.
Here’s how you can use it:
oldopts = [cfg.DeprecatedOpt('oldfoo', group='oldgroup'),
cfg.DeprecatedOpt('oldfoo2', group='oldgroup2')]
cfg.CONF.register_group(cfg.OptGroup('blaa'))
cfg.CONF.register_opt(cfg.StrOpt('foo', deprecated_opts=oldopts),
group='blaa')
Multi-value options will return all new and deprecated options. For single options, if the new option is present (“[blaa]/foo” above) it will override any deprecated options present. If the new option is not present and multiple deprecated options are present, the option corresponding to the first element of deprecated_opts will be chosen.
If group is None, the DeprecatedOpt lookup will happen within the same group the new option is in. For example:
oldopts = [cfg.DeprecatedOpt('oldfoo'),
cfg.DeprecatedOpt('oldfoo2', group='DEFAULT')]
cfg.CONF.register_group(cfg.OptGroup('blaa'))
cfg.CONF.register_opt(cfg.StrOpt('foo', deprecated_opts=oldopts),
group='blaa')
In the example above, oldfoo will be looked up in the blaa group and oldfoo2 in the DEFAULT group.
Sub-command options.
Sub-command options allow argparse sub-parsers to be used to parse additional command line arguments.
The handler argument to the SubCommandOpt constructor is a callable which is supplied an argparse subparsers object. Use this handler callable to add sub-parsers.
The opt value is SubCommandAttr object with the name of the chosen sub-parser stored in the ‘name’ attribute and the values of other sub-parser arguments available as additional attributes.
Represents a group of opts.
CLI opts in the group are automatically prefixed with the group name.
Each group corresponds to a section in config files.
An OptGroup object has no public methods, but has a number of public string properties:
- name:
- the name of the group
- title:
- the group title as displayed in –help
- help:
- the group description as displayed in –help