Skip to content

Commit 6330daf

Browse files
committed
Fixed broken example.
1 parent 7a3da26 commit 6330daf

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

examples/modular_commands/commandset_basic.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
)
99

1010
from cmd2 import (
11-
Cmd,
1211
CommandSet,
1312
CompletionError,
1413
Statement,
@@ -32,15 +31,15 @@ class BasicCompletionCommandSet(CommandSet):
3231
'/home/other user/tests.db',
3332
]
3433

35-
def do_flag_based(self, cmd: Cmd, statement: Statement):
34+
def do_flag_based(self, statement: Statement) -> None:
3635
"""Tab completes arguments based on a preceding flag using flag_based_complete
3736
-f, --food [completes food items]
3837
-s, --sport [completes sports]
3938
-p, --path [completes local file system paths]
4039
"""
4140
self._cmd.poutput("Args: {}".format(statement.args))
4241

43-
def complete_flag_based(self, cmd: Cmd, text: str, line: str, begidx: int, endidx: int) -> List[str]:
42+
def complete_flag_based(self, text: str, line: str, begidx: int, endidx: int) -> List[str]:
4443
"""Completion function for do_flag_based"""
4544
flag_dict = {
4645
# Tab complete food items after -f and --food flags in command line
@@ -50,38 +49,38 @@ def complete_flag_based(self, cmd: Cmd, text: str, line: str, begidx: int, endid
5049
'-s': self.sport_item_strs,
5150
'--sport': self.sport_item_strs,
5251
# Tab complete using path_complete function after -p and --path flags in command line
53-
'-p': cmd.path_complete,
54-
'--path': cmd.path_complete,
52+
'-p': self._cmd.path_complete,
53+
'--path': self._cmd.path_complete,
5554
}
5655

57-
return cmd.flag_based_complete(text, line, begidx, endidx, flag_dict=flag_dict)
56+
return self._cmd.flag_based_complete(text, line, begidx, endidx, flag_dict=flag_dict)
5857

59-
def do_index_based(self, cmd: Cmd, statement: Statement):
58+
def do_index_based(self, statement: Statement) -> None:
6059
"""Tab completes first 3 arguments using index_based_complete"""
6160
self._cmd.poutput("Args: {}".format(statement.args))
6261

63-
def complete_index_based(self, cmd: Cmd, text: str, line: str, begidx: int, endidx: int) -> List[str]:
62+
def complete_index_based(self, text: str, line: str, begidx: int, endidx: int) -> List[str]:
6463
"""Completion function for do_index_based"""
6564
index_dict = {
6665
1: self.food_item_strs, # Tab complete food items at index 1 in command line
6766
2: self.sport_item_strs, # Tab complete sport items at index 2 in command line
68-
3: cmd.path_complete, # Tab complete using path_complete function at index 3 in command line
67+
3: self._cmd.path_complete, # Tab complete using path_complete function at index 3 in command line
6968
}
7069

71-
return cmd.index_based_complete(text, line, begidx, endidx, index_dict=index_dict)
70+
return self._cmd.index_based_complete(text, line, begidx, endidx, index_dict=index_dict)
7271

73-
def do_delimiter_complete(self, cmd: Cmd, statement: Statement):
72+
def do_delimiter_complete(self, statement: Statement) -> None:
7473
"""Tab completes files from a list using delimiter_complete"""
7574
self._cmd.poutput("Args: {}".format(statement.args))
7675

77-
def complete_delimiter_complete(self, cmd: Cmd, text: str, line: str, begidx: int, endidx: int) -> List[str]:
78-
return cmd.delimiter_complete(text, line, begidx, endidx, match_against=self.file_strs, delimiter='/')
76+
def complete_delimiter_complete(self, text: str, line: str, begidx: int, endidx: int) -> List[str]:
77+
return self._cmd.delimiter_complete(text, line, begidx, endidx, match_against=self.file_strs, delimiter='/')
7978

80-
def do_raise_error(self, cmd: Cmd, statement: Statement):
79+
def do_raise_error(self, statement: Statement) -> None:
8180
"""Demonstrates effect of raising CompletionError"""
8281
self._cmd.poutput("Args: {}".format(statement.args))
8382

84-
def complete_raise_error(self, cmd: Cmd, text: str, line: str, begidx: int, endidx: int) -> List[str]:
83+
def complete_raise_error(self, text: str, line: str, begidx: int, endidx: int) -> List[str]:
8584
"""
8685
CompletionErrors can be raised if an error occurs while tab completing.
8786
@@ -92,5 +91,5 @@ def complete_raise_error(self, cmd: Cmd, text: str, line: str, begidx: int, endi
9291
raise CompletionError("This is how a CompletionError behaves")
9392

9493
@with_category('Not Basic Completion')
95-
def do_custom_category(self, cmd: Cmd, statement: Statement):
94+
def do_custom_category(self, statement: Statement) -> None:
9695
self._cmd.poutput('Demonstrates a command that bypasses the default category')

0 commit comments

Comments
 (0)