8
8
9
9
from prompt_toolkit .shortcuts import get_input
10
10
from prompt_toolkit .history import InMemoryHistory
11
- from prompt_toolkit .completion import Completer , Completion
12
11
12
+ from awsshell import shellcomplete
13
13
from awsshell import autocomplete
14
14
from awsshell import app
15
15
16
16
17
- NOOP = {'arguments' : [], 'commands' : [], 'children' : {}}
18
-
19
-
20
17
__version__ = '0.0.1'
21
18
22
19
@@ -37,61 +34,15 @@ def load_index(filename):
37
34
return ast .literal_eval (f .read ())
38
35
39
36
40
- class AWSShellCompleter (Completer ):
41
- """Completer class for the aws-shell.
42
-
43
- This is the completer used specifically for the aws shell.
44
- Not to be confused with the AWSCLICompleter, which is more
45
- low level, and can be reused in contexts other than the
46
- aws shell.
47
- """
48
- def __init__ (self , completer ):
49
- self ._completer = completer
50
-
51
- @property
52
- def completer (self ):
53
- return self ._completer
54
-
55
- @completer .setter
56
- def completer (self , value ):
57
- self ._completer = value
58
-
59
- def get_completions (self , document , complete_event ):
60
- text_before_cursor = document .text_before_cursor
61
- word_before_cursor = ''
62
- if text_before_cursor .strip ():
63
- word_before_cursor = text_before_cursor .split ()[- 1 ]
64
- completions = self ._completer .autocomplete (text_before_cursor )
65
- arg_meta = self ._completer .arg_metadata
66
- for completion in completions :
67
- if completion .startswith ('--' ) and completion in arg_meta :
68
- # TODO: Need to handle merging in global options as well.
69
- meta = arg_meta [completion ]
70
- if meta ['required' ]:
71
- display_text = '%s (required)' % completion
72
- else :
73
- display_text = completion
74
- type_name = arg_meta [completion ]['type_name' ]
75
- display_meta = '[%s] %s' % (type_name , arg_meta [completion ]['minidoc' ])
76
- else :
77
- display_text = completion
78
- display_meta = ''
79
- if text_before_cursor and text_before_cursor [- 1 ] == ' ' :
80
- location = 0
81
- else :
82
- location = - len (word_before_cursor )
83
- yield Completion (completion , location ,
84
- display = display_text , display_meta = display_meta )
85
-
86
-
87
37
def main ():
88
38
index_file = determine_index_filename ()
89
39
if not os .path .isfile (index_file ):
90
40
print ("First run, creating autocomplete index..." )
91
41
from awsshell .makeindex import write_index
92
42
write_index ()
93
43
index_data = load_index (index_file )
94
- completer = AWSShellCompleter (autocomplete .AWSCLICompleter (index_data ))
44
+ completer = shellcomplete .AWSShellCompleter (
45
+ autocomplete .AWSCLICompleter (index_data ))
95
46
history = InMemoryHistory ()
96
47
shell = app .create_aws_shell (completer , history )
97
48
shell .run ()
0 commit comments