config: add optional --reconfigure parameter
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
508a28e5c8
commit
e9477b1566
1 changed files with 14 additions and 1 deletions
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue