summaryrefslogtreecommitdiff
path: root/examples/subcommands.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-01-21 22:24:09 -0500
committerTodd Leonhardt <todd.leonhardt@gmail.com>2018-01-21 22:24:09 -0500
commitc9f7c012bda012b4df7a8c5e853bd5d3e6d99b1b (patch)
treee2e2f7f6ade5e61a625a3737106918e5e4362aaa /examples/subcommands.py
parent711d6380d347260a99d9ed77ce0afa7cdae67da7 (diff)
downloadcmd2-git-c9f7c012bda012b4df7a8c5e853bd5d3e6d99b1b.tar.gz
Renamed @with_argument_parser decorator to @with_argparser
Also: - Reanamed foo and bar subcommand methods to base_foo and base_bar
Diffstat (limited to 'examples/subcommands.py')
-rwxr-xr-xexamples/subcommands.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/examples/subcommands.py b/examples/subcommands.py
index 67b06e18..e77abc61 100755
--- a/examples/subcommands.py
+++ b/examples/subcommands.py
@@ -9,7 +9,7 @@ and provides separate contextual help.
import argparse
import cmd2
-from cmd2 import with_argument_parser
+from cmd2 import with_argparser
class SubcommandsExample(cmd2.Cmd):
@@ -19,11 +19,11 @@ class SubcommandsExample(cmd2.Cmd):
cmd2.Cmd.__init__(self)
# sub-command functions for the base command
- def foo(self, args):
+ def base_foo(self, args):
"""foo subcommand of base command"""
self.poutput(args.x * args.y)
- def bar(self, args):
+ def base_bar(self, args):
"""bar sucommand of base command"""
self.poutput('((%s))' % args.z)
@@ -35,17 +35,17 @@ class SubcommandsExample(cmd2.Cmd):
parser_foo = base_subparsers.add_parser('foo', help='foo help')
parser_foo.add_argument('-x', type=int, default=1, help='integer')
parser_foo.add_argument('y', type=float, help='float')
- parser_foo.set_defaults(func=foo)
+ parser_foo.set_defaults(func=base_foo)
# create the parser for the "bar" sub-command
parser_bar = base_subparsers.add_parser('bar', help='bar help')
parser_bar.add_argument('z', help='string')
- parser_bar.set_defaults(func=bar)
+ parser_bar.set_defaults(func=base_bar)
# Create a list of subcommand names, which is used to enable tab-completion of sub-commands
subcommands = ['foo', 'bar']
- @with_argument_parser(base_parser, subcommands)
+ @with_argparser(base_parser, subcommands)
def do_base(self, args):
"""Base command help"""
try: