From 51b0d4ca58f70fdd887dd053bfae1b2c918c33ba Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Mon, 18 Nov 2019 11:36:20 -0500 Subject: [PATCH] Print help if nova-manage subcommand is not specified If a nova-manage command is executed without the -h option or a subcommand the user gets an ugly traceback. This is easily recreated: $ tox -e venv -- nova-manage db Make the action argument required, so we get a helpful error message instead. $ nova-manage db usage: nova-manage db [-h] {archive_deleted_rows,ironic_flavor_migration, null_instance_uuid_scan,online_data_migrations, purge,sync,version} ... nova-manage db: error: the following arguments are required: action Note that unit tests appear to be impossible for this, since doing so attempts to initialize an oslo.config 'CONF' singleton and this is something we've already done in 'nova.test' and can't do again. Change-Id: I24d03eed3aa3b882c49916938f4c25d76fd4e831 Closes-Bug: #1837199 Co-Authored-By: Stephen Finucane --- doc/source/cli/nova-manage.rst | 2 +- nova/cmd/common.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/cli/nova-manage.rst b/doc/source/cli/nova-manage.rst index 08e1440e92cd..a59eff8464d2 100644 --- a/doc/source/cli/nova-manage.rst +++ b/doc/source/cli/nova-manage.rst @@ -34,7 +34,7 @@ Run without arguments to see a list of available command categories:: nova-manage -You can also run with a category argument such as user to see a list of all +You can also run with a category argument such as ``db`` to see a list of all commands in that category:: nova-manage db diff --git a/nova/cmd/common.py b/nova/cmd/common.py index 684ae7ba2626..ab7b7c3ca205 100644 --- a/nova/cmd/common.py +++ b/nova/cmd/common.py @@ -124,6 +124,7 @@ def add_command_parsers(subparsers, categories): parser.set_defaults(command_object=command_object) category_subparsers = parser.add_subparsers(dest='action') + category_subparsers.required = True for (action, action_fn) in methods_of(command_object): parser = category_subparsers.add_parser(