8
8
)
9
9
10
10
from cmd2 import (
11
- Cmd ,
12
11
CommandSet ,
13
12
CompletionError ,
14
13
Statement ,
@@ -32,15 +31,15 @@ class BasicCompletionCommandSet(CommandSet):
32
31
'/home/other user/tests.db' ,
33
32
]
34
33
35
- def do_flag_based (self , cmd : Cmd , statement : Statement ):
34
+ def do_flag_based (self , statement : Statement ) -> None :
36
35
"""Tab completes arguments based on a preceding flag using flag_based_complete
37
36
-f, --food [completes food items]
38
37
-s, --sport [completes sports]
39
38
-p, --path [completes local file system paths]
40
39
"""
41
40
self ._cmd .poutput ("Args: {}" .format (statement .args ))
42
41
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 ]:
44
43
"""Completion function for do_flag_based"""
45
44
flag_dict = {
46
45
# 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
50
49
'-s' : self .sport_item_strs ,
51
50
'--sport' : self .sport_item_strs ,
52
51
# 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 ,
55
54
}
56
55
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 )
58
57
59
- def do_index_based (self , cmd : Cmd , statement : Statement ):
58
+ def do_index_based (self , statement : Statement ) -> None :
60
59
"""Tab completes first 3 arguments using index_based_complete"""
61
60
self ._cmd .poutput ("Args: {}" .format (statement .args ))
62
61
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 ]:
64
63
"""Completion function for do_index_based"""
65
64
index_dict = {
66
65
1 : self .food_item_strs , # Tab complete food items at index 1 in command line
67
66
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
69
68
}
70
69
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 )
72
71
73
- def do_delimiter_complete (self , cmd : Cmd , statement : Statement ):
72
+ def do_delimiter_complete (self , statement : Statement ) -> None :
74
73
"""Tab completes files from a list using delimiter_complete"""
75
74
self ._cmd .poutput ("Args: {}" .format (statement .args ))
76
75
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 = '/' )
79
78
80
- def do_raise_error (self , cmd : Cmd , statement : Statement ):
79
+ def do_raise_error (self , statement : Statement ) -> None :
81
80
"""Demonstrates effect of raising CompletionError"""
82
81
self ._cmd .poutput ("Args: {}" .format (statement .args ))
83
82
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 ]:
85
84
"""
86
85
CompletionErrors can be raised if an error occurs while tab completing.
87
86
@@ -92,5 +91,5 @@ def complete_raise_error(self, cmd: Cmd, text: str, line: str, begidx: int, endi
92
91
raise CompletionError ("This is how a CompletionError behaves" )
93
92
94
93
@with_category ('Not Basic Completion' )
95
- def do_custom_category (self , cmd : Cmd , statement : Statement ):
94
+ def do_custom_category (self , statement : Statement ) -> None :
96
95
self ._cmd .poutput ('Demonstrates a command that bypasses the default category' )
0 commit comments