From f8d78f6fe2dd60545390d465b5cf18261a423040 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Sat, 6 Nov 2021 15:14:06 +0100 Subject: [PATCH] config.BaseOption: add no_arg parameter --- mylib/config.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mylib/config.py b/mylib/config.py index ab94297..a94e0c0 100644 --- a/mylib/config.py +++ b/mylib/config.py @@ -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)