Skip to content

Commit 7071321

Browse files
author
Ricahrd Hammond
committed
Add required args to subcommand program
1 parent be15939 commit 7071321

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

cmd2/decorators.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ def _set_parser_prog(parser: argparse.ArgumentParser, prog: str) -> None:
209209
"""
210210
# Set the prog value for this parser
211211
parser.prog = prog
212+
req_args = []
212213

213214
# Set the prog value for the parser's subcommands
214215
for action in parser._actions:
@@ -233,13 +234,18 @@ def _set_parser_prog(parser: argparse.ArgumentParser, prog: str) -> None:
233234
if subcmd_parser in processed_parsers:
234235
continue
235236

236-
subcmd_prog = parser.prog + ' ' + subcmd_name
237+
subcmd_prog = parser.prog
238+
if req_args:
239+
subcmd_prog += " " + " ".join(req_args)
240+
subcmd_prog += " " + subcmd_name
237241
_set_parser_prog(subcmd_parser, subcmd_prog)
238242
processed_parsers.append(subcmd_parser)
239243

240244
# We can break since argparse only allows 1 group of subcommands per level
241245
break
242-
246+
# need to save required args so they can be prepended to the subcommand usage
247+
elif action.required:
248+
req_args.append(action.dest)
243249

244250
#: Function signature for a Command Function that uses an argparse.ArgumentParser to process user input
245251
#: and optionally returns a boolean

0 commit comments

Comments
 (0)