Skip to content

Commit

Permalink
Merge branch 'master' into 3.0.0 - Use add_subparsers() 'required' ke…
Browse files Browse the repository at this point in the history
…yword argument
  • Loading branch information
kmvanbrunt committed Nov 5, 2024
2 parents 29c8d11 + 9fc5683 commit b911a0b
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 12 deletions.
3 changes: 1 addition & 2 deletions cmd2/cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3278,8 +3278,7 @@ def _cmdloop(self) -> None:
def _build_alias_parser() -> Cmd2ArgumentParser:
alias_description = "Manage aliases."
alias_parser = argparse_custom.DEFAULT_ARGUMENT_PARSER(description=alias_description)
alias_subparsers = alias_parser.add_subparsers(dest='subcommand', metavar='SUBCOMMAND')
alias_subparsers.required = True
alias_parser.add_subparsers(dest='subcommand', metavar='SUBCOMMAND', required=True)

return alias_parser

Expand Down
6 changes: 2 additions & 4 deletions tests/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,7 @@ def test_preservelist(argparse_app):

def _build_has_subcmd_parser() -> cmd2.Cmd2ArgumentParser:
has_subcmds_parser = cmd2.Cmd2ArgumentParser(description="Tests as_subcmd_to decorator")
has_subcmds_subparsers = has_subcmds_parser.add_subparsers(dest='subcommand', metavar='SUBCOMMAND')
has_subcmds_subparsers.required = True
has_subcmds_parser.add_subparsers(dest='subcommand', metavar='SUBCOMMAND', required=True)
return has_subcmds_parser


Expand All @@ -271,8 +270,7 @@ def base_helpless(self, args):

# create the top-level parser for the base command
base_parser = cmd2.Cmd2ArgumentParser()
base_subparsers = base_parser.add_subparsers(dest='subcommand', metavar='SUBCOMMAND')
base_subparsers.required = True
base_subparsers = base_parser.add_subparsers(dest='subcommand', metavar='SUBCOMMAND', required=True)

# create the parser for the "foo" subcommand
parser_foo = base_subparsers.add_parser('foo', help='foo help')
Expand Down
3 changes: 1 addition & 2 deletions tests/test_argparse_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1249,8 +1249,7 @@ def do_custom_completer(self, args: argparse.Namespace) -> None:

# Test as_subcommand_to decorator with custom completer
top_parser = Cmd2ArgumentParser(description="Top Command")
top_subparsers = top_parser.add_subparsers(dest='subcommand', metavar='SUBCOMMAND')
top_subparsers.required = True
top_parser.add_subparsers(dest='subcommand', metavar='SUBCOMMAND', required=True)

@with_argparser(top_parser)
def do_top(self, args: argparse.Namespace) -> None:
Expand Down
3 changes: 1 addition & 2 deletions tests_isolated/test_commandset/test_argparse_subcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ def base_helpless(self, args):

# create the top-level parser for the base command
base_parser = cmd2.Cmd2ArgumentParser()
base_subparsers = base_parser.add_subparsers(dest='subcommand', metavar='SUBCOMMAND')
base_subparsers.required = True
base_subparsers = base_parser.add_subparsers(dest='subcommand', metavar='SUBCOMMAND', required=True)

# create the parser for the "foo" subcommand
parser_foo = base_subparsers.add_parser('foo', help='foo help')
Expand Down
3 changes: 1 addition & 2 deletions tests_isolated/test_commandset/test_commandset.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ def do_elderberry(self, ns: argparse.Namespace):
# Test that CommandSet with as_subcommand_to decorator successfully loads
# during `cmd2.Cmd.__init__()`.
main_parser = cmd2.Cmd2ArgumentParser(description="Main Command")
main_subparsers = main_parser.add_subparsers(dest='subcommand', metavar='SUBCOMMAND')
main_subparsers.required = True
main_parser.add_subparsers(dest='subcommand', metavar='SUBCOMMAND', required=True)

@cmd2.with_category('Alone')
@cmd2.with_argparser(main_parser)
Expand Down

0 comments on commit b911a0b

Please sign in to comment.