summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xexamples/subcommands.py5
-rw-r--r--tests/test_completion.py9
2 files changed, 8 insertions, 6 deletions
diff --git a/examples/subcommands.py b/examples/subcommands.py
index 2a7e0afa..bc82b548 100755
--- a/examples/subcommands.py
+++ b/examples/subcommands.py
@@ -63,9 +63,10 @@ class SubcommandsExample(cmd2.Cmd):
@with_argparser(base_parser)
def do_base(self, args):
"""Base command help"""
- if args.func is not None:
+ func = getattr(args, 'func', None)
+ if func is not None:
# Call whatever subcommand function was selected
- args.func(self, args)
+ func(self, args)
else:
# No subcommand was provided, so call help
self.do_help('base')
diff --git a/tests/test_completion.py b/tests/test_completion.py
index 35d014cd..daeb94bf 100644
--- a/tests/test_completion.py
+++ b/tests/test_completion.py
@@ -723,10 +723,11 @@ class SubcommandsExample(cmd2.Cmd):
@cmd2.with_argparser(base_parser)
def do_base(self, args):
"""Base command help"""
- try:
- # Call whatever sub-command function was selected
- args.func(self, args)
- except AttributeError:
+ func = getattr(args, 'func', None)
+ if func is not None:
+ # Call whatever subcommand function was selected
+ func(self, args)
+ else:
# No sub-command was provided, so as called
self.do_help('base')