Skip to content

Commit 496933d

Browse files
committed
Fix import stragglers
1 parent da0e211 commit 496933d

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

examples/arg_print.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
# coding=utf-8
33
"""A simple example demonstrating the following:
44
1) How arguments and options get parsed and passed to commands
5-
2) How to change what syntax get parsed as a comment and stripped from the arguments
5+
2) How to change what syntax get parsed as a comment and stripped from
6+
the arguments
67
7-
This is intended to serve as a live demonstration so that developers can experiment with and understand how command
8-
and argument parsing is intended to work.
8+
This is intended to serve as a live demonstration so that developers can
9+
experiment with and understand how command and argument parsing work.
910
1011
It also serves as an example of how to create command aliases (shortcuts).
1112
"""
@@ -25,9 +26,12 @@ def __init__(self):
2526
# NOTE: It is critical that the super class __init__ method be called AFTER updating certain parameters which
2627
# are not settable at runtime. This includes the shortcuts, multiline_commands, etc.
2728

28-
def do_aprint(self, arg):
29+
def do_aprint(self, statement):
2930
"""Print the argument string this basic command is called with."""
30-
self.poutput('aprint was called with argument: {!r}'.format(arg))
31+
self.poutput('aprint was called with argument: {!r}'.format(statement))
32+
self.poutput('statement.raw = {!r}'.format(statement.raw))
33+
self.poutput('statement.argv = {!r}'.format(statement.argv))
34+
self.poutput('statement.command = {!r}'.format(statement.command))
3135

3236
@cmd2.with_argument_list
3337
def do_lprint(self, arglist):

examples/help_categories.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def do_connect(self, _):
2525
self.poutput('Connect')
2626

2727
# Tag the above command functions under the category Connecting
28-
categorize(do_connect, CMD_CAT_CONNECTING)
28+
cmd2.categorize(do_connect, CMD_CAT_CONNECTING)
2929

3030
@cmd2.with_category(CMD_CAT_CONNECTING)
3131
def do_which(self, _):
@@ -80,7 +80,7 @@ def do_findleakers(self, _):
8080
self.poutput('Find Leakers')
8181

8282
# Tag the above command functions under the category Application Management
83-
categorize((do_list,
83+
cmd2.categorize((do_list,
8484
do_deploy,
8585
do_start,
8686
do_sessions,
@@ -137,7 +137,7 @@ def do_config(self, _):
137137

138138
def do_version(self, _):
139139
"""Version command"""
140-
self.poutput(__version__)
140+
self.poutput(cmd2.__version__)
141141

142142

143143
if __name__ == '__main__':

examples/pirate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Pirate(cmd2.Cmd):
1616
def __init__(self):
1717
self.default_to_shell = True
1818
self.multiline_commands = ['sing']
19-
self.terminators = Cmd.terminators + ['...']
19+
self.terminators = self.terminators + ['...']
2020
self.songcolor = 'blue'
2121

2222
# Add stuff to settable and/or shortcuts before calling base class initializer
@@ -75,7 +75,7 @@ def do_sing(self, arg):
7575
yo_parser.add_argument('-c', '--commas', action='store_true', help='Intersperse commas')
7676
yo_parser.add_argument('beverage', help='beverage to drink with the chant')
7777

78-
@cmd.with_argparser(yo_parser)
78+
@cmd2.with_argparser(yo_parser)
7979
def do_yo(self, args):
8080
"""Compose a yo-ho-ho type chant with flexible options."""
8181
chant = ['yo'] + ['ho'] * args.ho

examples/tab_autocompletion.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from typing import List
1212

1313
import cmd2
14+
from cmd2 import argparse_completer
1415

1516
actors = ['Mark Hamill', 'Harrison Ford', 'Carrie Fisher', 'Alec Guinness', 'Peter Mayhew',
1617
'Anthony Daniels', 'Adam Driver', 'Daisy Ridley', 'John Boyega', 'Oscar Isaac',
@@ -113,7 +114,7 @@ def instance_query_actors(self) -> List[str]:
113114
# - The help output for arguments with multiple flags or with append=True is more concise
114115
# - ACArgumentParser adds the ability to specify ranges of argument counts in 'nargs'
115116

116-
suggest_parser = cmd2.argparse_completer.ACArgumentParser()
117+
suggest_parser = argparse_completer.ACArgumentParser()
117118

118119
suggest_parser.add_argument('-t', '--type', choices=['movie', 'show'], required=True)
119120
suggest_parser.add_argument('-d', '--duration', nargs=(1, 2), action='append',
@@ -138,7 +139,7 @@ def do_suggest(self, args) -> None:
138139

139140
suggest_parser_hybrid = argparse.ArgumentParser()
140141
# This registers the custom narg range handling
141-
cmd2.argparse_completer.register_custom_actions(suggest_parser_hybrid)
142+
argparse_completer.register_custom_actions(suggest_parser_hybrid)
142143

143144
suggest_parser_hybrid.add_argument('-t', '--type', choices=['movie', 'show'], required=True)
144145
suggest_parser_hybrid.add_argument('-d', '--duration', nargs=(1, 2), action='append',

0 commit comments

Comments
 (0)