Define and loop on config file section
This review loop over the configuration file sections instead of taking as paremeter the section and only set the parameters by section one by one with the 'default' for default section. This avoid to set explicitely each sections as parameters. Change-Id: I068e57e18b256907ce54bf48e753d496dec5327d
This commit is contained in:
parent
5076004733
commit
c602a0843a
|
@ -30,8 +30,9 @@ from validations_libs.cli.common import ValidationHelpFormatter
|
||||||
class Base:
|
class Base:
|
||||||
"""Base class for CLI arguments management"""
|
"""Base class for CLI arguments management"""
|
||||||
config = {}
|
config = {}
|
||||||
|
config_section = ['default', 'ansible_runner', 'ansible_environment']
|
||||||
|
|
||||||
def set_argument_parser(self, vf_parser, args, section='default'):
|
def set_argument_parser(self, vf_parser, args):
|
||||||
""" Set Arguments parser depending of the precedence ordering:
|
""" Set Arguments parser depending of the precedence ordering:
|
||||||
* User CLI arguments
|
* User CLI arguments
|
||||||
* Configuration file
|
* Configuration file
|
||||||
|
@ -45,6 +46,7 @@ class Base:
|
||||||
for arg in cli_args if arg.startswith('--')]
|
for arg in cli_args if arg.startswith('--')]
|
||||||
|
|
||||||
self.config = utils.load_config(os.path.abspath(args.config))
|
self.config = utils.load_config(os.path.abspath(args.config))
|
||||||
|
for section in self.config_section:
|
||||||
config_args = self.config.get(section, {})
|
config_args = self.config.get(section, {})
|
||||||
for key, value in args._get_kwargs():
|
for key, value in args._get_kwargs():
|
||||||
if key in cli_key:
|
if key in cli_key:
|
||||||
|
@ -53,7 +55,7 @@ class Base:
|
||||||
config_args.update({key: value})
|
config_args.update({key: value})
|
||||||
elif key not in config_args.keys():
|
elif key not in config_args.keys():
|
||||||
config_args.update({key: value})
|
config_args.update({key: value})
|
||||||
return vars(args).update(**config_args)
|
vars(args).update(**config_args)
|
||||||
|
|
||||||
|
|
||||||
class BaseCommand(Command):
|
class BaseCommand(Command):
|
||||||
|
|
Loading…
Reference in New Issue