diff --git a/oslo_config/_list_opts.py b/oslo_config/_list_opts.py new file mode 100644 index 00000000..0b6b27f0 --- /dev/null +++ b/oslo_config/_list_opts.py @@ -0,0 +1,25 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from oslo_config import cfg + + +def list_opts(): + default_config_files = [ + '~/.project/project.conf', + '~/project.conf', + '/etc/project/project.conf', + '/etc/project.conf', + ] + return [ + (None, cfg.ConfigOpts._make_config_options(default_config_files)), + ] diff --git a/oslo_config/cfg.py b/oslo_config/cfg.py index 55ab90fe..13e1fb7a 100644 --- a/oslo_config/cfg.py +++ b/oslo_config/cfg.py @@ -1948,17 +1948,16 @@ class ConfigOpts(collections.Mapping): return prog, default_config_files - def _setup(self, project, prog, version, usage, default_config_files): - """Initialize a ConfigOpts object for option parsing.""" - - self._config_opts = [ + @staticmethod + def _make_config_options(default_config_files): + return [ _ConfigFileOpt('config-file', default=default_config_files, metavar='PATH', help=('Path to a config file to use. Multiple ' 'config files can be specified, with values ' - 'in later files taking precedence. The ' - 'default files used are: %(default)s.')), + 'in later files taking precedence. Defaults ' + 'to %(default)s.')), _ConfigDirOpt('config-dir', metavar='DIR', help='Path to a config directory to pull *.conf ' @@ -1970,6 +1969,11 @@ class ConfigOpts(collections.Mapping): 'over-ridden options in the directory take ' 'precedence.'), ] + + def _setup(self, project, prog, version, usage, default_config_files): + """Initialize a ConfigOpts object for option parsing.""" + + self._config_opts = self._make_config_options(default_config_files) self.register_cli_opts(self._config_opts) self.project = project diff --git a/setup.cfg b/setup.cfg index 59adf916..bdef566a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,6 +30,8 @@ setup-hooks = [entry_points] console_scripts = oslo-config-generator = oslo_config.generator:main +oslo.config.opts = + oslo.config = oslo_config._list_opts:list_opts [build_sphinx] source-dir = doc/source