@@ -281,13 +281,13 @@ def __init__(self, dummy):
281281 @cmd2 .with_argparser (cut_parser )
282282 def do_cut (self , cmd : cmd2 .Cmd , ns : argparse .Namespace ):
283283 """Cut something"""
284- func = getattr ( ns , 'handler' , None )
285- if func is not None :
284+ handler = ns . get_handler ( )
285+ if handler is not None :
286286 # Call whatever subcommand function was selected
287- func (ns )
287+ handler (ns )
288288 else :
289289 # No subcommand was provided, so call help
290- cmd .poutput ('This command does nothing without sub-parsers registered' )
290+ cmd .pwarning ('This command does nothing without sub-parsers registered' )
291291 cmd .do_help ('cut' )
292292
293293
@@ -297,13 +297,13 @@ def do_cut(self, cmd: cmd2.Cmd, ns: argparse.Namespace):
297297 @cmd2 .with_argparser (stir_parser )
298298 def do_stir (self , cmd : cmd2 .Cmd , ns : argparse .Namespace ):
299299 """Stir something"""
300- func = getattr ( ns , 'handler' , None )
301- if func is not None :
300+ handler = ns . get_handler ( )
301+ if handler is not None :
302302 # Call whatever subcommand function was selected
303- func (ns )
303+ handler (ns )
304304 else :
305305 # No subcommand was provided, so call help
306- cmd .poutput ('This command does nothing without sub-parsers registered' )
306+ cmd .pwarning ('This command does nothing without sub-parsers registered' )
307307 cmd .do_help ('stir' )
308308
309309 stir_pasta_parser = cmd2 .Cmd2ArgumentParser ('pasta' , add_help = False )
@@ -312,10 +312,10 @@ def do_stir(self, cmd: cmd2.Cmd, ns: argparse.Namespace):
312312
313313 @cmd2 .as_subcommand_to ('stir' , 'pasta' , stir_pasta_parser )
314314 def stir_pasta (self , cmd : cmd2 .Cmd , ns : argparse .Namespace ):
315- func = getattr ( ns , 'handler' , None )
316- if func is not None :
315+ handler = ns . get_handler ( )
316+ if handler is not None :
317317 # Call whatever subcommand function was selected
318- func (ns )
318+ handler (ns )
319319 else :
320320 cmd .poutput ('Stir pasta haphazardly' )
321321
@@ -327,10 +327,10 @@ def __init__(self, dummy):
327327
328328 def do_cut (self , cmd : cmd2 .Cmd , ns : argparse .Namespace ):
329329 """Cut something"""
330- func = getattr ( ns , 'handler' , None )
331- if func is not None :
330+ handler = ns . get_handler ( )
331+ if handler is not None :
332332 # Call whatever subcommand function was selected
333- func (ns )
333+ handler (ns )
334334 else :
335335 # No subcommand was provided, so call help
336336 cmd .poutput ('This command does nothing without sub-parsers registered' )
@@ -417,6 +417,9 @@ def test_subcommands(command_sets_manual):
417417 with pytest .raises (CommandSetRegistrationError ):
418418 command_sets_manual ._register_subcommands (fruit_cmds )
419419
420+ cmd_result = command_sets_manual .app_cmd ('cut' )
421+ assert 'This command does nothing without sub-parsers registered' in cmd_result .stderr
422+
420423 # verify that command set install without problems
421424 command_sets_manual .install_command_set (fruit_cmds )
422425 command_sets_manual .install_command_set (veg_cmds )
@@ -433,6 +436,9 @@ def test_subcommands(command_sets_manual):
433436 # check that the alias shows up correctly
434437 assert ['banana' , 'bananer' , 'bokchoy' ] == command_sets_manual .completion_matches
435438
439+ cmd_result = command_sets_manual .app_cmd ('cut banana discs' )
440+ assert 'cutting banana: discs' in cmd_result .stdout
441+
436442 text = ''
437443 line = 'cut bokchoy {}' .format (text )
438444 endidx = len (line )
@@ -546,10 +552,10 @@ def __init__(self, *args, **kwargs):
546552 @cmd2 .with_argparser (cut_parser )
547553 def do_cut (self , ns : argparse .Namespace ):
548554 """Cut something"""
549- func = getattr ( ns , 'handler' , None )
550- if func is not None :
555+ handler = ns . get_handler ( )
556+ if handler is not None :
551557 # Call whatever subcommand function was selected
552- func (ns )
558+ handler (ns )
553559 else :
554560 # No subcommand was provided, so call help
555561 self .poutput ('This command does nothing without sub-parsers registered' )
0 commit comments