From c25a2b7949c02449279f548db1c8de9d10214cdc Mon Sep 17 00:00:00 2001 From: kotfu Date: Sun, 7 Jan 2018 14:12:57 -0700 Subject: Add tests for POSIX=true and arguments containing spaces --- examples/argparse_example.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/argparse_example.py b/examples/argparse_example.py index 96f8118d..16de343c 100755 --- a/examples/argparse_example.py +++ b/examples/argparse_example.py @@ -59,6 +59,10 @@ class CmdLineApp(Cmd): # self.stdout.write is better than "print", because Cmd can be # initialized with a non-standard output destination + do_say = do_speak # now "say" is a synonym for "speak" + do_orate = do_speak # another synonym, but this one takes multi-line input + + argparser = argparse.ArgumentParser( prog='sspeak', description='Repeats what you tell me to' @@ -83,8 +87,20 @@ class CmdLineApp(Cmd): self.stdout.write('\n') # self.stdout.write is better than "print", because Cmd can be # initialized with a non-standard output destination - do_say = do_speak # now "say" is a synonym for "speak" - do_orate = do_speak # another synonym, but this one takes multi-line input + + + argparser = argparse.ArgumentParser( + prog='tag', + description='create an html tag, the first argument is the tag, the rest is the contents' + ) + argparser.add_argument('tag', nargs=1, help='tag') + argparser.add_argument('content', nargs='+', help='content to surround with tag') + @with_argument_parser(argparser) + def do_tag(self, cmdline, args=None): + self.stdout.write('<{0}>{1}'.format(args.tag[0], ' '.join(args.content))) + self.stdout.write('\n') + # self.stdout.write is better than "print", because Cmd can be + # initialized with a non-standard output destination if __name__ == '__main__': -- cgit v1.2.1