@@ -39,7 +39,7 @@ def namespace_provider(self) -> argparse.Namespace:
39
39
ns .custom_stuff = "custom"
40
40
return ns
41
41
42
- say_parser = argparse . ArgumentParser ()
42
+ say_parser = cmd2 . Cmd2ArgumentParser ()
43
43
say_parser .add_argument ('-p' , '--piglatin' , action = 'store_true' , help = 'atinLay' )
44
44
say_parser .add_argument ('-s' , '--shout' , action = 'store_true' , help = 'N00B EMULATION MODE' )
45
45
say_parser .add_argument ('-r' , '--repeat' , type = int , help = 'output [n] times' )
@@ -65,7 +65,7 @@ def do_say(self, args, *, keyword_arg: Optional[str] = None):
65
65
if keyword_arg is not None :
66
66
print (keyword_arg )
67
67
68
- tag_parser = argparse . ArgumentParser (description = 'create a html tag' )
68
+ tag_parser = cmd2 . Cmd2ArgumentParser (description = 'create a html tag' )
69
69
tag_parser .add_argument ('tag' , help = 'tag' )
70
70
tag_parser .add_argument ('content' , nargs = '+' , help = 'content to surround with tag' )
71
71
@@ -74,7 +74,7 @@ def do_tag(self, args):
74
74
self .stdout .write ('<{0}>{1}</{0}>' .format (args .tag , ' ' .join (args .content )))
75
75
self .stdout .write ('\n ' )
76
76
77
- @cmd2 .with_argparser (argparse . ArgumentParser (), ns_provider = namespace_provider )
77
+ @cmd2 .with_argparser (cmd2 . Cmd2ArgumentParser (), ns_provider = namespace_provider )
78
78
def do_test_argparse_ns (self , args ):
79
79
self .stdout .write ('{}' .format (args .custom_stuff ))
80
80
@@ -92,7 +92,7 @@ def do_arglist(self, arglist, *, keyword_arg: Optional[str] = None):
92
92
def do_preservelist (self , arglist ):
93
93
self .stdout .write ('{}' .format (arglist ))
94
94
95
- known_parser = argparse . ArgumentParser ()
95
+ known_parser = cmd2 . Cmd2ArgumentParser ()
96
96
known_parser .add_argument ('-p' , '--piglatin' , action = 'store_true' , help = 'atinLay' )
97
97
known_parser .add_argument ('-s' , '--shout' , action = 'store_true' , help = 'N00B EMULATION MODE' )
98
98
known_parser .add_argument ('-r' , '--repeat' , type = int , help = 'output [n] times' )
@@ -117,11 +117,11 @@ def do_speak(self, args, extra, *, keyword_arg: Optional[str] = None):
117
117
if keyword_arg is not None :
118
118
print (keyword_arg )
119
119
120
- @cmd2 .with_argparser (argparse . ArgumentParser (), preserve_quotes = True , with_unknown_args = True )
120
+ @cmd2 .with_argparser (cmd2 . Cmd2ArgumentParser (), preserve_quotes = True , with_unknown_args = True )
121
121
def do_test_argparse_with_list_quotes (self , args , extra ):
122
122
self .stdout .write ('{}' .format (' ' .join (extra )))
123
123
124
- @cmd2 .with_argparser (argparse . ArgumentParser (), ns_provider = namespace_provider , with_unknown_args = True )
124
+ @cmd2 .with_argparser (cmd2 . Cmd2ArgumentParser (), ns_provider = namespace_provider , with_unknown_args = True )
125
125
def do_test_argparse_with_list_ns (self , args , extra ):
126
126
self .stdout .write ('{}' .format (args .custom_stuff ))
127
127
@@ -208,14 +208,14 @@ def test_argparse_quoted_arguments_multiple(argparse_app):
208
208
209
209
def test_argparse_help_docstring (argparse_app ):
210
210
out , err = run_cmd (argparse_app , 'help say' )
211
- assert out [0 ].startswith ('usage : say' )
211
+ assert out [0 ].startswith ('Usage : say' )
212
212
assert out [1 ] == ''
213
213
assert out [2 ] == 'Repeat what you tell me to.'
214
214
215
215
216
216
def test_argparse_help_description (argparse_app ):
217
217
out , err = run_cmd (argparse_app , 'help tag' )
218
- assert out [0 ].startswith ('usage : tag' )
218
+ assert out [0 ].startswith ('Usage : tag' )
219
219
assert out [1 ] == ''
220
220
assert out [2 ] == 'create a html tag'
221
221
@@ -263,7 +263,7 @@ def base_helpless(self, args):
263
263
self .poutput ('((%s))' % args .z )
264
264
265
265
# create the top-level parser for the base command
266
- base_parser = argparse . ArgumentParser ()
266
+ base_parser = cmd2 . Cmd2ArgumentParser ()
267
267
base_subparsers = base_parser .add_subparsers (dest = 'subcommand' , metavar = 'SUBCOMMAND' )
268
268
base_subparsers .required = True
269
269
@@ -338,60 +338,60 @@ def test_subcommand_bar(subcommand_app):
338
338
339
339
def test_subcommand_invalid (subcommand_app ):
340
340
out , err = run_cmd (subcommand_app , 'base baz' )
341
- assert err [0 ].startswith ('usage : base' )
342
- assert err [1 ].startswith ("base: error : argument SUBCOMMAND: invalid choice: 'baz'" )
341
+ assert err [0 ].startswith ('Usage : base' )
342
+ assert err [1 ].startswith ("Error : argument SUBCOMMAND: invalid choice: 'baz'" )
343
343
344
344
345
345
def test_subcommand_base_help (subcommand_app ):
346
346
out , err = run_cmd (subcommand_app , 'help base' )
347
- assert out [0 ].startswith ('usage : base' )
347
+ assert out [0 ].startswith ('Usage : base' )
348
348
assert out [1 ] == ''
349
349
assert out [2 ] == 'Base command help'
350
350
351
351
352
352
def test_subcommand_help (subcommand_app ):
353
353
# foo has no aliases
354
354
out , err = run_cmd (subcommand_app , 'help base foo' )
355
- assert out [0 ].startswith ('usage : base foo' )
355
+ assert out [0 ].startswith ('Usage : base foo' )
356
356
assert out [1 ] == ''
357
357
assert out [2 ] == 'positional arguments:'
358
358
359
359
# bar has aliases (usage should never show alias name)
360
360
out , err = run_cmd (subcommand_app , 'help base bar' )
361
- assert out [0 ].startswith ('usage : base bar' )
361
+ assert out [0 ].startswith ('Usage : base bar' )
362
362
assert out [1 ] == ''
363
363
assert out [2 ] == 'positional arguments:'
364
364
365
365
out , err = run_cmd (subcommand_app , 'help base bar_1' )
366
- assert out [0 ].startswith ('usage : base bar' )
366
+ assert out [0 ].startswith ('Usage : base bar' )
367
367
assert out [1 ] == ''
368
368
assert out [2 ] == 'positional arguments:'
369
369
370
370
out , err = run_cmd (subcommand_app , 'help base bar_2' )
371
- assert out [0 ].startswith ('usage : base bar' )
371
+ assert out [0 ].startswith ('Usage : base bar' )
372
372
assert out [1 ] == ''
373
373
assert out [2 ] == 'positional arguments:'
374
374
375
375
# helpless has aliases and no help text (usage should never show alias name)
376
376
out , err = run_cmd (subcommand_app , 'help base helpless' )
377
- assert out [0 ].startswith ('usage : base helpless' )
377
+ assert out [0 ].startswith ('Usage : base helpless' )
378
378
assert out [1 ] == ''
379
379
assert out [2 ] == 'positional arguments:'
380
380
381
381
out , err = run_cmd (subcommand_app , 'help base helpless_1' )
382
- assert out [0 ].startswith ('usage : base helpless' )
382
+ assert out [0 ].startswith ('Usage : base helpless' )
383
383
assert out [1 ] == ''
384
384
assert out [2 ] == 'positional arguments:'
385
385
386
386
out , err = run_cmd (subcommand_app , 'help base helpless_2' )
387
- assert out [0 ].startswith ('usage : base helpless' )
387
+ assert out [0 ].startswith ('Usage : base helpless' )
388
388
assert out [1 ] == ''
389
389
assert out [2 ] == 'positional arguments:'
390
390
391
391
392
392
def test_subcommand_invalid_help (subcommand_app ):
393
393
out , err = run_cmd (subcommand_app , 'help base baz' )
394
- assert out [0 ].startswith ('usage : base' )
394
+ assert out [0 ].startswith ('Usage : base' )
395
395
396
396
397
397
def test_add_another_subcommand (subcommand_app ):
0 commit comments