summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-01-21 22:24:09 -0500
committerTodd Leonhardt <todd.leonhardt@gmail.com>2018-01-21 22:24:09 -0500
commitc9f7c012bda012b4df7a8c5e853bd5d3e6d99b1b (patch)
treee2e2f7f6ade5e61a625a3737106918e5e4362aaa /examples
parent711d6380d347260a99d9ed77ce0afa7cdae67da7 (diff)
downloadcmd2-git-c9f7c012bda012b4df7a8c5e853bd5d3e6d99b1b.tar.gz
Renamed @with_argument_parser decorator to @with_argparser
Also: - Reanamed foo and bar subcommand methods to base_foo and base_bar
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/arg_print.py4
-rwxr-xr-xexamples/argparse_example.py6
-rwxr-xr-xexamples/example.py6
-rwxr-xr-xexamples/pirate.py4
-rwxr-xr-xexamples/subcommands.py12
5 files changed, 16 insertions, 16 deletions
diff --git a/examples/arg_print.py b/examples/arg_print.py
index 1b18cdf0..8b02bc51 100755
--- a/examples/arg_print.py
+++ b/examples/arg_print.py
@@ -14,7 +14,7 @@ import argparse
import cmd2
import pyparsing
-from cmd2 import with_argument_list, with_argument_parser, with_argparser_and_unknown_args
+from cmd2 import with_argument_list, with_argparser, with_argparser_and_unknown_args
class ArgumentAndOptionPrinter(cmd2.Cmd):
@@ -47,7 +47,7 @@ class ArgumentAndOptionPrinter(cmd2.Cmd):
oprint_parser.add_argument('-r', '--repeat', type=int, help='output [n] times')
oprint_parser.add_argument('words', nargs='+', help='words to print')
- @with_argument_parser(oprint_parser)
+ @with_argparser(oprint_parser)
def do_oprint(self, args):
"""Print the options and argument list this options command was called with."""
print('oprint was called with the following\n\toptions: {!r}'.format(args))
diff --git a/examples/argparse_example.py b/examples/argparse_example.py
index 9f6548de..fbb2b1dc 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, options, with_argument_parser, with_argument_list
+from cmd2 import Cmd, options, with_argparser, with_argument_list
from optparse import make_option
@@ -47,7 +47,7 @@ class CmdLineApp(Cmd):
speak_parser.add_argument('-r', '--repeat', type=int, help='output [n] times')
speak_parser.add_argument('words', nargs='+', help='words to say')
- @with_argument_parser(speak_parser)
+ @with_argparser(speak_parser)
def do_speak(self, args):
"""Repeats what you tell me to."""
words = []
@@ -68,7 +68,7 @@ class CmdLineApp(Cmd):
tag_parser.add_argument('tag', help='tag')
tag_parser.add_argument('content', nargs='+', help='content to surround with tag')
- @with_argument_parser(tag_parser)
+ @with_argparser(tag_parser)
def do_tag(self, args):
"""create a html tag"""
self.poutput('<{0}>{1}</{0}>'.format(args.tag, ' '.join(args.content)))
diff --git a/examples/example.py b/examples/example.py
index 4ba0d29a..c66f0e60 100755
--- a/examples/example.py
+++ b/examples/example.py
@@ -14,7 +14,7 @@ the transcript.
import random
import argparse
-from cmd2 import Cmd, with_argument_parser
+from cmd2 import Cmd, with_argparser
class CmdLineApp(Cmd):
@@ -44,7 +44,7 @@ class CmdLineApp(Cmd):
speak_parser.add_argument('-r', '--repeat', type=int, help='output [n] times')
speak_parser.add_argument('words', nargs='+', help='words to say')
- @with_argument_parser(speak_parser)
+ @with_argparser(speak_parser)
def do_speak(self, args):
"""Repeats what you tell me to."""
words = []
@@ -66,7 +66,7 @@ class CmdLineApp(Cmd):
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_argument_parser(mumble_parser)
+ @with_argparser(mumble_parser)
def do_mumble(self, args):
"""Mumbles what you tell me to."""
repetitions = args.repeat or 1
diff --git a/examples/pirate.py b/examples/pirate.py
index 06fdb61b..cfe545d6 100755
--- a/examples/pirate.py
+++ b/examples/pirate.py
@@ -7,7 +7,7 @@ presented as part of her PyCon 2010 talk.
It demonstrates many features of cmd2.
"""
import argparse
-from cmd2 import Cmd, with_argument_parser
+from cmd2 import Cmd, with_argparser
class Pirate(Cmd):
@@ -78,7 +78,7 @@ class Pirate(Cmd):
yo_parser.add_argument('-c', '--commas', action='store_true', help='Intersperse commas')
yo_parser.add_argument('beverage', help='beverage to drink with the chant')
- @with_argument_parser(yo_parser)
+ @with_argparser(yo_parser)
def do_yo(self, args):
"""Compose a yo-ho-ho type chant with flexible options."""
chant = ['yo'] + ['ho'] * args.ho
diff --git a/examples/subcommands.py b/examples/subcommands.py
index 67b06e18..e77abc61 100755
--- a/examples/subcommands.py
+++ b/examples/subcommands.py
@@ -9,7 +9,7 @@ and provides separate contextual help.
import argparse
import cmd2
-from cmd2 import with_argument_parser
+from cmd2 import with_argparser
class SubcommandsExample(cmd2.Cmd):
@@ -19,11 +19,11 @@ class SubcommandsExample(cmd2.Cmd):
cmd2.Cmd.__init__(self)
# sub-command functions for the base command
- def foo(self, args):
+ def base_foo(self, args):
"""foo subcommand of base command"""
self.poutput(args.x * args.y)
- def bar(self, args):
+ def base_bar(self, args):
"""bar sucommand of base command"""
self.poutput('((%s))' % args.z)
@@ -35,17 +35,17 @@ class SubcommandsExample(cmd2.Cmd):
parser_foo = base_subparsers.add_parser('foo', help='foo help')
parser_foo.add_argument('-x', type=int, default=1, help='integer')
parser_foo.add_argument('y', type=float, help='float')
- parser_foo.set_defaults(func=foo)
+ parser_foo.set_defaults(func=base_foo)
# create the parser for the "bar" sub-command
parser_bar = base_subparsers.add_parser('bar', help='bar help')
parser_bar.add_argument('z', help='string')
- parser_bar.set_defaults(func=bar)
+ parser_bar.set_defaults(func=base_bar)
# Create a list of subcommand names, which is used to enable tab-completion of sub-commands
subcommands = ['foo', 'bar']
- @with_argument_parser(base_parser, subcommands)
+ @with_argparser(base_parser, subcommands)
def do_base(self, args):
"""Base command help"""
try: