glance help <subcommand>: Clearly specify which options are mandatory

Earlier glance help <subcommand> 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 <STORE_ID> <IMAGE_ID>

Delete image from specific store.

Positional arguments:
  <IMAGE_ID>          ID of image to update.

Optional arguments:
  --store <STORE_ID>  Store to delete image from.

After this change:
usage: glance stores-delete --store <STORE_ID> <IMAGE_ID>

Delete image from specific store.

Positional arguments:
  <IMAGE_ID>          ID of image to update.

Required arguments:
  --store <STORE_ID>  Store to delete image from.

Change-Id: I51ea4c43fa62164ed43e78d1ae0fb0cb2521fc83
Closes-Bug: #1933390
This commit is contained in:
Cyril Roelandt
2021-06-23 23:18:49 +02:00
committed by Abhishek Kekane
parent 8aac1597cd
commit 91ae9347db
2 changed files with 16 additions and 1 deletions
+5 -1
View File
@@ -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):