summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2019-03-17 10:53:21 -0400
committerGitHub <noreply@github.com>2019-03-17 10:53:21 -0400
commite28bce263802b94a79c974ddc2540075eb5301a2 (patch)
treeb1fba35bc42562fd2cfa63b69059a666cfd5d558 /examples
parent3b6ed1151bc417633d2207d9ed1e20b491a4ef24 (diff)
parent47dce297681f799c51a65b3e8420bf0c551c779b (diff)
downloadcmd2-git-e28bce263802b94a79c974ddc2540075eb5301a2.tar.gz
Merge branch 'master' into attributes
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/decorator_example.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/examples/decorator_example.py b/examples/decorator_example.py
index cf948d1d..d8088c0a 100755
--- a/examples/decorator_example.py
+++ b/examples/decorator_example.py
@@ -12,6 +12,7 @@ verifying that the output produced matches the transcript.
"""
import argparse
import sys
+from typing import List
import cmd2
@@ -46,7 +47,7 @@ class CmdLineApp(cmd2.Cmd):
speak_parser.add_argument('words', nargs='+', help='words to say')
@cmd2.with_argparser(speak_parser)
- def do_speak(self, args):
+ def do_speak(self, args: argparse.Namespace):
"""Repeats what you tell me to."""
words = []
for word in args.words:
@@ -67,13 +68,18 @@ class CmdLineApp(cmd2.Cmd):
tag_parser.add_argument('content', nargs='+', help='content to surround with tag')
@cmd2.with_argparser(tag_parser)
- def do_tag(self, args):
- """create a html tag"""
+ def do_tag(self, args: argparse.Namespace):
+ """create an html tag"""
+ # The Namespace always includes the Statement object created when parsing the command line
+ statement = args.__statement__
+
+ self.poutput("The command line you ran was: {}".format(statement.command_and_args))
+ self.poutput("It generated this tag:")
self.poutput('<{0}>{1}</{0}>'.format(args.tag, ' '.join(args.content)))
@cmd2.with_argument_list
- def do_tagg(self, arglist):
- """verion of creating an html tag using arglist instead of argparser"""
+ def do_tagg(self, arglist: List[str]):
+ """version of creating an html tag using arglist instead of argparser"""
if len(arglist) >= 2:
tag = arglist[0]
content = arglist[1:]