diff --git a/mylib/config.py b/mylib/config.py index 387ad96..3844add 100644 --- a/mylib/config.py +++ b/mylib/config.py @@ -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):