summaryrefslogtreecommitdiff
path: root/examples/subcommands.py
diff options
context:
space:
mode:
authorEric Lin <anselor@gmail.com>2018-04-20 15:50:53 -0400
committerEric Lin <anselor@gmail.com>2018-04-20 15:50:53 -0400
commit85c2c6bba46900af6012b54c31e650095194b1aa (patch)
tree4519d86d44f5c40376a820f530b69fa2ee745de3 /examples/subcommands.py
parenta0a46f9396a72f440f65e46d7170a0d366796574 (diff)
downloadcmd2-git-85c2c6bba46900af6012b54c31e650095194b1aa.tar.gz
Changed cmd2 to use autocompleter by default for all argparse commands. Not all tests are passing yet.
Diffstat (limited to 'examples/subcommands.py')
-rwxr-xr-xexamples/subcommands.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/examples/subcommands.py b/examples/subcommands.py
index 031b17b2..03088c93 100755
--- a/examples/subcommands.py
+++ b/examples/subcommands.py
@@ -53,15 +53,22 @@ class SubcommandsExample(cmd2.Cmd):
# create the parser for the "bar" subcommand
parser_bar = base_subparsers.add_parser('bar', help='bar help')
- parser_bar.add_argument('z', help='string')
parser_bar.set_defaults(func=base_bar)
+ bar_subparsers = parser_bar.add_subparsers(title='layer3', help='help for 3rd layer of commands')
+ parser_bar.add_argument('z', help='string')
+
+ bar_subparsers.add_parser('apple', help='apple help')
+ bar_subparsers.add_parser('artichoke', help='artichoke help')
+ bar_subparsers.add_parser('cranberries', help='cranberries help')
+
# create the parser for the "sport" subcommand
parser_sport = base_subparsers.add_parser('sport', help='sport help')
- parser_sport.add_argument('sport', help='Enter name of a sport')
+ sport_arg = parser_sport.add_argument('sport', help='Enter name of a sport')
+ setattr(sport_arg, 'arg_choices', sport_item_strs)
# Set both a function and tab completer for the "sport" subcommand
- parser_sport.set_defaults(func=base_sport, completer=complete_base_sport)
+ parser_sport.set_defaults(func=base_sport)
@with_argparser(base_parser)
def do_base(self, args):
@@ -75,7 +82,7 @@ class SubcommandsExample(cmd2.Cmd):
self.do_help('base')
# Enable tab completion of base to make sure the subcommands' completers get called.
- complete_base = cmd2.Cmd.cmd_with_subs_completer
+ # complete_base = cmd2.Cmd.cmd_with_subs_completer
if __name__ == '__main__':