config.BaseOption: add no_arg parameter
This commit is contained in:
parent
73c19816f7
commit
f8d78f6fe2
1 changed files with 6 additions and 2 deletions
|
@ -28,12 +28,13 @@ class BaseOption:
|
|||
""" Base configuration option class """
|
||||
|
||||
def __init__(self, config, section, name, default=None, comment=None,
|
||||
arg=None, short_arg=None, arg_help=None):
|
||||
arg=None, short_arg=None, arg_help=None, no_arg=False):
|
||||
self.config = config
|
||||
self.section = section
|
||||
self.name = name
|
||||
self.default = default
|
||||
self.comment = comment
|
||||
self.no_arg = no_arg
|
||||
self.arg = arg
|
||||
self.short_arg = short_arg
|
||||
self.arg_help = arg_help if arg_help else comment
|
||||
|
@ -43,6 +44,7 @@ class BaseOption:
|
|||
""" Check if option is defined in registered arguments parser options """
|
||||
return (
|
||||
self.config.options
|
||||
and not self.no_arg
|
||||
and self._from_options != self.default
|
||||
)
|
||||
|
||||
|
@ -51,7 +53,7 @@ class BaseOption:
|
|||
""" Get option from arguments parser options """
|
||||
value = (
|
||||
getattr(self.config.options, self.parser_dest)
|
||||
if self.config.options else None
|
||||
if self.config.options and not self.no_arg else None
|
||||
)
|
||||
log.debug(
|
||||
'_from_options(%s, %s) = %s',
|
||||
|
@ -139,6 +141,8 @@ class BaseOption:
|
|||
|
||||
def add_option_to_parser(self, section_opts):
|
||||
""" Add option to arguments parser """
|
||||
if self.no_arg:
|
||||
return
|
||||
args = [self.parser_argument_name]
|
||||
if self.short_arg:
|
||||
args.append(self.short_arg)
|
||||
|
|
Loading…
Reference in a new issue