MCPcopy
hub / github.com/awslabs/aws-shell / CompletionIndex

Class CompletionIndex

awsshell/index/completion.py:22–102  ·  view source on GitHub ↗

Handles working with the local commmand completion index. :type commands: list :param commands: ec2, s3, elb... :type subcommands: list :param subcommands: start-instances, stop-instances, terminate-instances... :type global_opts: list :param global_opts: --profile, --regi

Source from the content-addressed store, hash-verified

20
21
22class CompletionIndex(object):
23 """Handles working with the local commmand completion index.
24
25 :type commands: list
26 :param commands: ec2, s3, elb...
27
28 :type subcommands: list
29 :param subcommands: start-instances, stop-instances, terminate-instances...
30
31 :type global_opts: list
32 :param global_opts: --profile, --region, --output...
33
34 :type args_opts: set, to filter out duplicates
35 :param args_opts: ec2 start-instances: --instance-ids, --dry-run...
36 """
37
38 # The completion index can read/write to a cache dir
39 # so that it doesn't have to recompute the completion cache
40 # every time the CLI starts up.
41 DEFAULT_CACHE_DIR = build_config_file_path('cache')
42
43 def __init__(self, cache_dir=DEFAULT_CACHE_DIR, fslayer=None):
44 self._cache_dir = cache_dir
45 if fslayer is None:
46 fslayer = FSLayer()
47 self._fslayer = fslayer
48 self.commands = []
49 self.subcommands = []
50 self.global_opts = []
51 self.args_opts = set()
52
53 def load_index(self, version_string):
54 """Load the completion index for a given CLI version.
55
56 :type version_string: str
57 :param version_string: The AWS CLI version, e.g "1.9.2".
58
59 :raises: :class:`IndexLoadError <exceptions.IndexLoadError>`
60 """
61 filename = self._filename_for_version(version_string)
62 try:
63 contents = self._fslayer.file_contents(filename)
64 except FileReadError as e:
65 raise IndexLoadError(str(e))
66 return contents
67
68 def _filename_for_version(self, version_string):
69 return os.path.join(
70 self._cache_dir, 'completions-%s.json' % version_string)
71
72 def load_completions(self):
73 """Load completions from the completion index.
74
75 Updates the following attributes:
76 * commands
77 * subcommands
78 * global_opts
79 * args_opts

Callers 2

ShellLexerClass · 0.90
setUpMethod · 0.90

Calls 1

build_config_file_pathFunction · 0.90

Tested by 1

setUpMethod · 0.72