@@ -37,6 +37,18 @@ def do_say(self, cmdline, args=None):
3737 self .stdout .write (' ' .join (words ))
3838 self .stdout .write ('\n ' )
3939
40+ argparser = argparse .ArgumentParser (
41+ prog = 'tag' ,
42+ description = 'create an html tag, the first argument is the tag, the rest is the contents'
43+ )
44+ argparser .add_argument ('tag' , nargs = 1 , help = 'tag' )
45+ argparser .add_argument ('content' , nargs = '+' , help = 'content to surround with tag' )
46+ @cmd2 .with_argument_parser (argparser )
47+ def do_tag (self , cmdline , args = None ):
48+ self .stdout .write ('<{0}>{1}</{0}>' .format (args .tag [0 ], ' ' .join (args .content )))
49+ self .stdout .write ('\n ' )
50+
51+
4052@pytest .fixture
4153def argparse_app ():
4254 app = ArgparseApp ()
@@ -53,8 +65,18 @@ def test_argparse_quoted_arguments(argparse_app):
5365 out = run_cmd (argparse_app , 'say "hello there"' )
5466 assert out == ['hello there' ]
5567
56- def test_pargparse_quoted_arguments_too_many (argparse_app ):
68+ def test_argparse_quoted_arguments_multiple (argparse_app ):
5769 argparse_app .POSIX = False
5870 argparse_app .STRIP_QUOTES_FOR_NON_POSIX = True
59- out = run_cmd (argparse_app , 'say "hello there" morty' )
60- assert out == ['hello there morty' ]
71+ out = run_cmd (argparse_app , 'say "hello there" "rick & morty"' )
72+ assert out == ['hello there rick & morty' ]
73+
74+ def test_argparse_quoted_arguments_posix (argparse_app ):
75+ argparse_app .POSIX = True
76+ out = run_cmd (argparse_app , 'tag strong this should be loud' )
77+ assert out == ['<strong>this should be loud</strong>' ]
78+
79+ def test_argparse_quoted_arguments_posix_multiple (argparse_app ):
80+ argparse_app .POSIX = True
81+ out = run_cmd (argparse_app , 'tag strong this "should be" loud' )
82+ assert out == ['<strong>this should be loud</strong>' ]
0 commit comments