11#!/usr/bin/env python3
22# coding=utf-8
3- """A simple example demonstracting modular subcommand loading through CommandSets
3+ """A simple example demonstrating modular subcommand loading through CommandSets
44
55In this example, there are loadable CommandSets defined. Each CommandSet has 1 subcommand defined that will be
66attached to the 'cut' command.
@@ -23,10 +23,11 @@ def __init__(self):
2323 def do_apple (self , cmd : cmd2 .Cmd , _ : cmd2 .Statement ):
2424 cmd .poutput ('Apple' )
2525
26- banana_parser = cmd2 .Cmd2ArgumentParser (add_help = False )
26+ banana_description = "Cut a banana"
27+ banana_parser = cmd2 .Cmd2ArgumentParser (add_help = False , description = banana_description )
2728 banana_parser .add_argument ('direction' , choices = ['discs' , 'lengthwise' ])
2829
29- @cmd2 .as_subcommand_to ('cut' , 'banana' , banana_parser )
30+ @cmd2 .as_subcommand_to ('cut' , 'banana' , banana_parser , help = banana_description . lower () )
3031 def cut_banana (self , cmd : cmd2 .Cmd , ns : argparse .Namespace ):
3132 """Cut banana"""
3233 cmd .poutput ('cutting banana: ' + ns .direction )
@@ -40,10 +41,11 @@ def __init__(self):
4041 def do_arugula (self , cmd : cmd2 .Cmd , _ : cmd2 .Statement ):
4142 cmd .poutput ('Arugula' )
4243
43- bokchoy_parser = cmd2 .Cmd2ArgumentParser (add_help = False )
44+ bokchoy_description = "Cut some bokchoy"
45+ bokchoy_parser = cmd2 .Cmd2ArgumentParser (add_help = False , description = bokchoy_description )
4446 bokchoy_parser .add_argument ('style' , choices = ['quartered' , 'diced' ])
4547
46- @cmd2 .as_subcommand_to ('cut' , 'bokchoy' , bokchoy_parser )
48+ @cmd2 .as_subcommand_to ('cut' , 'bokchoy' , bokchoy_parser , help = bokchoy_description . lower () )
4749 def cut_bokchoy (self , cmd : cmd2 .Cmd , _ : cmd2 .Statement ):
4850 cmd .poutput ('Bok Choy' )
4951
@@ -95,9 +97,9 @@ def do_unload(self, ns: argparse.Namespace):
9597
9698 @with_argparser (cut_parser )
9799 def do_cut (self , ns : argparse .Namespace ):
100+ # Call handler for whatever subcommand was selected
98101 handler = ns .get_handler ()
99102 if handler is not None :
100- # Call whatever subcommand function was selected
101103 handler (ns )
102104 else :
103105 # No subcommand was provided, so call help
0 commit comments