Config options which may be set on the command line or in config files.
ConfigOpts is a configuration option manager with APIs for registering option schemas, grouping options, parsing option values and retrieving the values of options.
It has built-in support for config_file and config_dir options.
Helper class.
Represents the option values of a group as a mapping and attributes.
Helper class.
Exposes opt values as a dict for string substitution.
Helper class.
Represents the name and arguments of an argparse sub-parser.
Clear the state of the object to before it was called.
Any subparsers added using the add_cli_subparsers() will also be removed as a side-effect of this method.
Clear an override an opt’s default value.
Clear a previously set override of the default value of given option.
Parameters: |
|
---|---|
Raises: | NoSuchOptError, NoSuchGroupError |
Clear an override an opt value.
Clear a previously set override of the command line, config file and default values of a given option.
Parameters: |
|
---|---|
Raises: | NoSuchOptError, NoSuchGroupError |
Locate a file located alongside the config files.
Search for a file with the supplied basename in the directories which we have already loaded config files from and other known configuration directories.
The directory, if any, supplied by the config_dir option is searched first. Then the config_file option is iterated over and each of the base directories of the config_files values are searched. Failing both of these, the standard directories searched by the module level find_config_files() function is used. The first matching file is returned.
Parameters: | name – the filename, for example ‘policy.json’ |
---|---|
Returns: | the path to a matching file, or None |
Import an option group from a module.
Import a module and check that a given option group is registered.
This is intended for use with global configuration objects like cfg.CONF where modules commonly register options with CONF at module load time. If one module requires an option group defined by another module it can use this method to explicitly declare the dependency.
Parameters: |
|
---|---|
Raises: | ImportError, NoSuchGroupError |
Import an option definition from a module.
Import a module and check that a given option is registered.
This is intended for use with global configuration objects like cfg.CONF where modules commonly register options with CONF at module load time. If one module requires an option defined by another module it can use this method to explicitly declare the dependency.
Parameters: |
|
---|---|
Raises: | NoSuchOptError, NoSuchGroupError |
List all sections from the configuration.
Returns a sorted list of all section names found in the configuration files, whether declared beforehand or not.
Log the value of all registered opts.
It’s often useful for an app to log its configuration to a log file at startup for debugging. This method dumps to the entire config state to the supplied logger at a given log level.
Parameters: |
|
---|
Reload configure files and parse all options.
Only options marked as ‘mutable’ will appear to change.
Hooks are called in a NON-DETERMINISTIC ORDER. Do not expect hooks to be called in the same order as they were added.
Return {(None or ‘group’, ‘optname’): | |
---|---|
(old_value, new_value), ... } |
:raises Error if reloading fails
Print the help message for the current program.
This method is for use after all CLI options are known registered using __call__() method. If this method is called before the __call__() is invoked, it throws NotInitializedError
Parameters: | file – the File object (if None, output is on sys.stdout) |
---|---|
Raises: | NotInitializedError |
Print the usage message for the current program.
This method is for use after all CLI options are known registered using __call__() method. If this method is called before the __call__() is invoked, it throws NotInitializedError
Parameters: | file – the File object (if None, output is on sys.stdout) |
---|---|
Raises: | NotInitializedError |
Register a CLI option schema.
CLI option schemas must be registered before the command line and config files are parsed. This is to ensure that all CLI options are shown in –help and option validation works as expected.
Parameters: |
|
---|---|
Returns: | False if the opt was already registered, True otherwise |
Raises: | DuplicateOptError, ArgsAlreadyParsedError |
Register multiple CLI option schemas at once.
Register an option group.
An option group must be registered before options can be registered with the group.
Parameters: | group – an OptGroup object |
---|
Registers a hook to be called by mutate_config_files.
Parameters: | hook – a function accepting this ConfigOpts object and a dict of config mutations, as returned by mutate_config_files. |
---|
:return None
Register an option schema.
Registering an option schema makes any option value which is previously or subsequently parsed from the command line or config files available as an attribute of this object.
Parameters: |
|
---|---|
Returns: | False if the opt was already registered, True otherwise |
Raises: | DuplicateOptError |
Register multiple option schemas at once.
Reload configure files and parse all options
:return False if reload configure files failed or else return True
Clear the object state and unset overrides and defaults.
Override an opt’s default value.
Override the default value of given option. A command line or config file value will still take precedence over this default.
Parameters: |
|
---|---|
Raises: | NoSuchOptError, NoSuchGroupError |
Override an opt value.
Override the command line, config file and default values of a given option.
Parameters: |
|
---|---|
Raises: | NoSuchOptError, NoSuchGroupError |
Unregister an option.
Parameters: |
|
---|---|
Raises: | ArgsAlreadyParsedError, NoSuchGroupError |
Unregister multiple CLI option schemas at once.