Separate opt registration from command running
In some scenarios, it is useful for the caller of upgradecheck to be responsible for parsing the conf (see [1]). Since registering command line options must come before parsing, we must separate registation from running the commands. This change enables that by making `register_cli_options` public and extracting a public `run` method. `main` continues to work as before by calling these new methods. [1] I2eea00343d1bbdf486985daeaf6707358b6a2708 Change-Id: I3d7e28d2432f5b04d4154793025786dc289b0cb2
This commit is contained in:
parent
226d9b14d3
commit
fd6bd23457
|
@ -141,7 +141,7 @@ class UpgradeCommands(object):
|
|||
return return_code
|
||||
|
||||
|
||||
def _register_cli_options(conf, upgrade_command):
|
||||
def register_cli_options(conf, upgrade_command):
|
||||
"""Set up the command line options.
|
||||
|
||||
Adds a subcommand to support 'upgrade check' on the command line.
|
||||
|
@ -156,6 +156,16 @@ def _register_cli_options(conf, upgrade_command):
|
|||
conf.register_cli_opt(opt)
|
||||
|
||||
|
||||
def run(conf):
|
||||
"""Run the requested command."""
|
||||
try:
|
||||
return conf.command.action_fn()
|
||||
except Exception:
|
||||
print(_('Error:\n%s') % traceback.format_exc())
|
||||
# This is 255 so it's not confused with the upgrade check exit codes.
|
||||
return 255
|
||||
|
||||
|
||||
def main(conf, project, upgrade_command,
|
||||
argv=sys.argv[1:],
|
||||
default_config_files=None):
|
||||
|
@ -177,7 +187,7 @@ def main(conf, project, upgrade_command,
|
|||
the search behavior in oslo.config.
|
||||
|
||||
"""
|
||||
_register_cli_options(conf, upgrade_command)
|
||||
register_cli_options(conf, upgrade_command)
|
||||
|
||||
conf(
|
||||
args=argv,
|
||||
|
@ -185,9 +195,4 @@ def main(conf, project, upgrade_command,
|
|||
default_config_files=default_config_files,
|
||||
)
|
||||
|
||||
try:
|
||||
return conf.command.action_fn()
|
||||
except Exception:
|
||||
print(_('Error:\n%s') % traceback.format_exc())
|
||||
# This is 255 so it's not confused with the upgrade check exit codes.
|
||||
return 255
|
||||
return run(conf)
|
||||
|
|
Loading…
Reference in New Issue