diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-03-17 00:52:34 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-03-17 00:52:34 -0400 |
commit | 40f75f7453c3df83d8e74a281ec1311d53b23eec (patch) | |
tree | 58ef97822a095b085fb700c28ed7de9ba6e9ea0f /examples | |
parent | 7db2786706e3f4b5cfbf90c88c29ba1ee1f1f39c (diff) | |
download | cmd2-git-40f75f7453c3df83d8e74a281ec1311d53b23eec.tar.gz |
Updated docs and example
Diffstat (limited to 'examples')
-rwxr-xr-x | examples/decorator_example.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/examples/decorator_example.py b/examples/decorator_example.py index 5d127619..79bd7633 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:] |