config: add ask_values and execute_callback parameters to parse_arguments_options

This commit is contained in:
Benjamin Renard 2021-11-23 12:35:40 +01:00
parent 2e829c4cc3
commit 6601891f9d

View file

@ -752,7 +752,8 @@ class Config:
return self.options_parser return self.options_parser
def parse_arguments_options(self, argv=None, parser=None, create=True, exit_after_created=True): def parse_arguments_options(self, argv=None, parser=None, create=True, ask_values=True,
exit_after_created=True, execute_callback=True):
""" """
Parse arguments options Parse arguments options
@ -761,8 +762,12 @@ class Config:
(default: generated by self.get_arguments_parser()) (default: generated by self.get_arguments_parser())
:param create: If True, configuration file will be created if it does not exits :param create: If True, configuration file will be created if it does not exits
(default: True) (default: True)
:param ask_values: If True, ask user to enter valor of each configuration options
(default: True)
:param exit_after_created: If True, script will end after configuration file :param exit_after_created: If True, script will end after configuration file
creation (default: True) creation (default: True)
:param execute_callback: Sections's loaded callbacks will be executed only if True
(default: True)
""" """
parser = parser if parser else self.get_arguments_parser() parser = parser if parser else self.get_arguments_parser()
argcomplete.autocomplete(parser) argcomplete.autocomplete(parser)
@ -778,6 +783,8 @@ class Config:
"Configuration file is missing, generate it (%s)", "Configuration file is missing, generate it (%s)",
options.config options.config
) )
if ask_values:
self.ask_values(set_it=True)
self.save(options.config) self.save(options.config)
if exit_after_created: if exit_after_created:
sys.exit(0) sys.exit(0)
@ -802,7 +809,8 @@ class Config:
console_handler = logging.StreamHandler(sys.stdout) console_handler = logging.StreamHandler(sys.stdout)
logging.getLogger().addHandler(console_handler) logging.getLogger().addHandler(console_handler)
self._loaded() if execute_callback:
self._loaded()
return options return options