@@ -281,13 +281,13 @@ def __init__(self, dummy):
281
281
@cmd2 .with_argparser (cut_parser )
282
282
def do_cut (self , cmd : cmd2 .Cmd , ns : argparse .Namespace ):
283
283
"""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 :
286
286
# Call whatever subcommand function was selected
287
- func (ns )
287
+ handler (ns )
288
288
else :
289
289
# 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' )
291
291
cmd .do_help ('cut' )
292
292
293
293
@@ -297,13 +297,13 @@ def do_cut(self, cmd: cmd2.Cmd, ns: argparse.Namespace):
297
297
@cmd2 .with_argparser (stir_parser )
298
298
def do_stir (self , cmd : cmd2 .Cmd , ns : argparse .Namespace ):
299
299
"""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 :
302
302
# Call whatever subcommand function was selected
303
- func (ns )
303
+ handler (ns )
304
304
else :
305
305
# 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' )
307
307
cmd .do_help ('stir' )
308
308
309
309
stir_pasta_parser = cmd2 .Cmd2ArgumentParser ('pasta' , add_help = False )
@@ -312,10 +312,10 @@ def do_stir(self, cmd: cmd2.Cmd, ns: argparse.Namespace):
312
312
313
313
@cmd2 .as_subcommand_to ('stir' , 'pasta' , stir_pasta_parser )
314
314
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 :
317
317
# Call whatever subcommand function was selected
318
- func (ns )
318
+ handler (ns )
319
319
else :
320
320
cmd .poutput ('Stir pasta haphazardly' )
321
321
@@ -327,10 +327,10 @@ def __init__(self, dummy):
327
327
328
328
def do_cut (self , cmd : cmd2 .Cmd , ns : argparse .Namespace ):
329
329
"""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 :
332
332
# Call whatever subcommand function was selected
333
- func (ns )
333
+ handler (ns )
334
334
else :
335
335
# No subcommand was provided, so call help
336
336
cmd .poutput ('This command does nothing without sub-parsers registered' )
@@ -417,6 +417,9 @@ def test_subcommands(command_sets_manual):
417
417
with pytest .raises (CommandSetRegistrationError ):
418
418
command_sets_manual ._register_subcommands (fruit_cmds )
419
419
420
+ cmd_result = command_sets_manual .app_cmd ('cut' )
421
+ assert 'This command does nothing without sub-parsers registered' in cmd_result .stderr
422
+
420
423
# verify that command set install without problems
421
424
command_sets_manual .install_command_set (fruit_cmds )
422
425
command_sets_manual .install_command_set (veg_cmds )
@@ -433,6 +436,9 @@ def test_subcommands(command_sets_manual):
433
436
# check that the alias shows up correctly
434
437
assert ['banana' , 'bananer' , 'bokchoy' ] == command_sets_manual .completion_matches
435
438
439
+ cmd_result = command_sets_manual .app_cmd ('cut banana discs' )
440
+ assert 'cutting banana: discs' in cmd_result .stdout
441
+
436
442
text = ''
437
443
line = 'cut bokchoy {}' .format (text )
438
444
endidx = len (line )
@@ -546,10 +552,10 @@ def __init__(self, *args, **kwargs):
546
552
@cmd2 .with_argparser (cut_parser )
547
553
def do_cut (self , ns : argparse .Namespace ):
548
554
"""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 :
551
557
# Call whatever subcommand function was selected
552
- func (ns )
558
+ handler (ns )
553
559
else :
554
560
# No subcommand was provided, so call help
555
561
self .poutput ('This command does nothing without sub-parsers registered' )
0 commit comments