summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2018-01-12 22:28:29 -0700
committerkotfu <kotfu@kotfu.net>2018-01-12 22:28:29 -0700
commitc26b00853633c7df8cdee0ee49b3596154bb09c1 (patch)
tree0597386fa8856c74093bb79534b394565ce24ebf /examples
parent19c0586b45204ac264038ce23da89858aefda46f (diff)
downloadcmd2-git-c26b00853633c7df8cdee0ee49b3596154bb09c1.tar.gz
new @with_argument_list decorator
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/argparse_example.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/examples/argparse_example.py b/examples/argparse_example.py
index 3574f549..40ea372c 100755
--- a/examples/argparse_example.py
+++ b/examples/argparse_example.py
@@ -14,7 +14,7 @@ verifying that the output produced matches the transcript.
import argparse
import sys
-from cmd2 import Cmd, make_option, options, with_argument_parser
+from cmd2 import Cmd, make_option, options, with_argument_parser, with_argument_list
class CmdLineApp(Cmd):
@@ -69,10 +69,20 @@ class CmdLineApp(Cmd):
argparser.add_argument('content', nargs='+', help='content to surround with tag')
@with_argument_parser(argparser)
def do_tag(self, arglist, args=None):
- self.stdout.write('<{0}>{1}</{0}>'.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
+ """create a html tag"""
+ self.poutput('<{0}>{1}</{0}>'.format(args.tag[0], ' '.join(args.content)))
+
+
+ @with_argument_list
+ def do_tagg(self, arglist):
+ """verion of creating an html tag using arglist instead of argparser"""
+ if len(arglist) >= 2:
+ tag = arglist[0]
+ content = arglist[1:]
+ self.poutput('<{0}>{1}</{0}>'.format(tag, ' '.join(content)))
+ else:
+ self.perror("tagg requires at least 2 arguments")
+
# @options uses the python optparse module which has been deprecated
# since 2011. Use @with_argument_parser instead, which utilizes the