summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-02-01 19:51:09 -0500
committerTodd Leonhardt <todd.leonhardt@gmail.com>2018-02-01 19:51:09 -0500
commite60cc37ad39795622c49f354548d86d752d637bd (patch)
tree10271153129de8330059e3f7b95c1971bf821626 /README.md
parent2cdeb5c69936390cf75582f7dcb304d38d598a37 (diff)
downloadcmd2-git-e60cc37ad39795622c49f354548d86d752d637bd.tar.gz
Improved argument processing docs
Improved the documentation related to how to use the argparse decorators. Also: - Fixed a comment in cmd2.py which referred to the old decorator before the rename - Fixed README.md which had the old decorator name in it prior to the rename
Diffstat (limited to 'README.md')
-rwxr-xr-xREADME.md29
1 files changed, 16 insertions, 13 deletions
diff --git a/README.md b/README.md
index 66361375..94bc6c30 100755
--- a/README.md
+++ b/README.md
@@ -108,12 +108,15 @@ Instructions for implementing each feature follow.
- Parsing commands with `argparse`
- ```python
+ ```Python
+ import argparse
+ from cmd2 import with_argparser
+
argparser = argparse.ArgumentParser()
argparser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
argparser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')
argparser.add_argument('words', nargs='+', help='words to say')
- @with_argument_parser(argparser)
+ @with_argparser(argparser)
def do_speak(self, args):
"""Repeats what you tell me to."""
words = []
@@ -154,7 +157,7 @@ A sample application for cmd2.
import random
import argparse
-from cmd2 import Cmd, with_argument_parser
+from cmd2 import Cmd, with_argparser
class CmdLineApp(Cmd):
@@ -178,12 +181,12 @@ class CmdLineApp(Cmd):
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
Cmd.__init__(self, use_ipython=False)
- argparser = argparse.ArgumentParser()
- argparser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
- argparser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')
- argparser.add_argument('-r', '--repeat', type=int, help='output [n] times')
- argparser.add_argument('words', nargs='+', help='words to say')
- @with_argument_parser(argparser)
+ speak_parser = argparse.ArgumentParser()
+ speak_parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
+ speak_parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')
+ speak_parser.add_argument('-r', '--repeat', type=int, help='output [n] times')
+ speak_parser.add_argument('words', nargs='+', help='words to say')
+ @with_argparser(speak_parser)
def do_speak(self, args):
"""Repeats what you tell me to."""
words = []
@@ -201,10 +204,10 @@ class CmdLineApp(Cmd):
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()
- argparser.add_argument('-r', '--repeat', type=int, help='how many times to repeat')
- argparser.add_argument('words', nargs='+', help='words to say')
- @with_argument_parser(argparser)
+ mumble_parser = argparse.ArgumentParser()
+ mumble_parser.add_argument('-r', '--repeat', type=int, help='how many times to repeat')
+ mumble_parser.add_argument('words', nargs='+', help='words to say')
+ @with_argparser(mumble_parser)
def do_mumble(self, args):
"""Mumbles what you tell me to."""
repetitions = args.repeat or 1