config: add optional --reconfigure parameter
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Benjamin Renard 2023-01-09 13:34:07 +01:00
parent 508a28e5c8
commit e9477b1566

View file

@ -774,7 +774,7 @@ class Config: # pylint: disable=too-many-instance-attributes
""" Get ordered list of section names """ """ Get ordered list of section names """
return sorted(self.sections.keys(), key=lambda section: self.sections[section].order) return sorted(self.sections.keys(), key=lambda section: self.sections[section].order)
def get_arguments_parser(self, **kwargs): def get_arguments_parser(self, reconfigure=False, **kwargs):
""" Get arguments parser """ """ Get arguments parser """
if self.options_parser: if self.options_parser:
return self.options_parser return self.options_parser
@ -807,6 +807,14 @@ class Config: # pylint: disable=too-many-instance-attributes
help='Save current configuration to file', help='Save current configuration to file',
) )
if reconfigure:
self.options_parser.add_argument(
'--reconfigure',
action='store_true',
dest='mylib_config_reconfigure',
help='Reconfigure and update configuration file',
)
self.options_parser.add_argument( self.options_parser.add_argument(
'-d', '-d',
'--debug', '--debug',
@ -912,6 +920,11 @@ class Config: # pylint: disable=too-many-instance-attributes
if execute_callback: if execute_callback:
self._loaded() self._loaded()
if self.get_option('mylib_config_reconfigure', default=False):
if self.ask_values(set_it=True) and self.save():
sys.exit(0)
sys.exit(1)
return options return options
def load_options(self, options, execute_callback=True): def load_options(self, options, execute_callback=True):