config.BooleanOption: fix handling argparse options
The argparse option now reverse the default value set in configuration file instead of only the default value set on adding the configuration option.
This commit is contained in:
parent
0a0fae3e90
commit
bca3f4f347
1 changed files with 27 additions and 2 deletions
|
@ -78,6 +78,14 @@ class BaseOption: # pylint: disable=too-many-instance-attributes
|
|||
""" Get option value from ConfigParser """
|
||||
return self.config.config_parser.get(self.section.name, self.name)
|
||||
|
||||
@property
|
||||
def _default_in_config(self):
|
||||
""" Get option default value considering current value from configuration """
|
||||
return (
|
||||
self._from_config if self._isset_in_config_file
|
||||
else self.default
|
||||
)
|
||||
|
||||
def isset(self):
|
||||
""" Check if option is defined in the loaded configuration file """
|
||||
return self._isset_in_config_file or self._isset_in_options
|
||||
|
@ -243,9 +251,26 @@ class BooleanOption(BaseOption):
|
|||
""" Format value as stored in configuration file """
|
||||
return super().to_config(value).lower()
|
||||
|
||||
@property
|
||||
def _isset_in_options(self):
|
||||
""" Check if option is defined in registered arguments parser options """
|
||||
return (
|
||||
self.config.options
|
||||
and not self.no_arg
|
||||
and getattr(self.config.options, self.parser_dest)
|
||||
)
|
||||
|
||||
@property
|
||||
def _from_options(self):
|
||||
""" Get option from arguments parser options """
|
||||
return (
|
||||
not self._default_in_config if self._isset_in_options
|
||||
else self._default_in_config
|
||||
)
|
||||
|
||||
@property
|
||||
def parser_action(self):
|
||||
return "store_" + str(bool(not self.default)).lower()
|
||||
return "store_true"
|
||||
|
||||
@property
|
||||
def parser_type(self):
|
||||
|
@ -258,7 +283,7 @@ class BooleanOption(BaseOption):
|
|||
self.arg if self.arg else
|
||||
'--{0}-{1}-{2}'.format(
|
||||
self.section.name,
|
||||
'enable' if not self.default else 'disable',
|
||||
'enable' if not self._default_in_config else 'disable',
|
||||
self.name
|
||||
).lower().replace('_', '-')
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue