Skip to content

Commit 966d6a5

Browse files
committed
Fixed check for whether a subcommand was entered
1 parent 747028d commit 966d6a5

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

examples/subcommands.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ def complete_base_sport(self, text, line, begidx, endidx):
6363
@with_argparser(base_parser)
6464
def do_base(self, args):
6565
"""Base command help"""
66-
if args.func is not None:
66+
func = getattr(args, 'func', None)
67+
if func is not None:
6768
# Call whatever subcommand function was selected
68-
args.func(self, args)
69+
func(self, args)
6970
else:
7071
# No subcommand was provided, so call help
7172
self.do_help('base')

tests/test_completion.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -723,10 +723,11 @@ def base_bar(self, args):
723723
@cmd2.with_argparser(base_parser)
724724
def do_base(self, args):
725725
"""Base command help"""
726-
try:
727-
# Call whatever sub-command function was selected
728-
args.func(self, args)
729-
except AttributeError:
726+
func = getattr(args, 'func', None)
727+
if func is not None:
728+
# Call whatever subcommand function was selected
729+
func(self, args)
730+
else:
730731
# No sub-command was provided, so as called
731732
self.do_help('base')
732733

0 commit comments

Comments
 (0)