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 """
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 """
if 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',
)
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(
'-d',
'--debug',
@ -912,6 +920,11 @@ class Config: # pylint: disable=too-many-instance-attributes
if execute_callback:
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
def load_options(self, options, execute_callback=True):