From 91ae9347dbc125a19fedd107df5cc013e018e7e1 Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Wed, 23 Jun 2021 23:18:49 +0200 Subject: glance help : Clearly specify which options are mandatory Earlier glance help was listing required arguments as optional arguments in help text. Added new argument group to list required argument properly. $ glance help stores-delete Example before this change: usage: glance stores-delete --store Delete image from specific store. Positional arguments: ID of image to update. Optional arguments: --store Store to delete image from. After this change: usage: glance stores-delete --store Delete image from specific store. Positional arguments: ID of image to update. Required arguments: --store Store to delete image from. Change-Id: I51ea4c43fa62164ed43e78d1ae0fb0cb2521fc83 Closes-Bug: #1933390 --- glanceclient/shell.py | 6 +++++- glanceclient/tests/unit/test_shell.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/glanceclient/shell.py b/glanceclient/shell.py index 3a32bfb..4a505a5 100644 --- a/glanceclient/shell.py +++ b/glanceclient/shell.py @@ -224,8 +224,12 @@ class OpenStackImagesShell(object): help=argparse.SUPPRESS, ) self.subcommands[command] = subparser + required_args = subparser.add_argument_group('Required arguments') for (args, kwargs) in arguments: - subparser.add_argument(*args, **kwargs) + if kwargs.get('required', False): + required_args.add_argument(*args, **kwargs) + else: + subparser.add_argument(*args, **kwargs) subparser.set_defaults(func=callback) def _add_bash_completion_subparser(self, subparsers): diff --git a/glanceclient/tests/unit/test_shell.py b/glanceclient/tests/unit/test_shell.py index 129b127..6b9472e 100644 --- a/glanceclient/tests/unit/test_shell.py +++ b/glanceclient/tests/unit/test_shell.py @@ -600,6 +600,17 @@ class ShellTest(testutils.TestCase): self.assertEqual(glance_logger.getEffectiveLevel(), logging.DEBUG) conf.assert_called_with(level=logging.DEBUG) + def test_subcommand_help(self): + # Ensure that main works with sub command help + stdout, stderr = self.shell('help stores-delete') + + expected = 'usage: glance stores-delete --store ' \ + '\n\nDelete image from specific store.' \ + '\n\nPositional arguments:\n ' \ + 'ID of image to update.\n\nRequired arguments:\n ' \ + '--store Store to delete image from.\n' + self.assertEqual(expected, stdout) + class ShellTestWithKeystoneV3Auth(ShellTest): # auth environment to use -- cgit v1.2.1