MCPcopy Index your code
hub / github.com/aws/aws-cli / AliasSubCommandInjector

Class AliasSubCommandInjector

awscli/alias.py:151–208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

149
150
151class AliasSubCommandInjector(BaseAliasCommandInjector):
152 def __init__(self, alias_loader):
153 super(AliasSubCommandInjector, self).__init__(alias_loader)
154 self._global_cmd_driver = None
155 self._global_args_parser = None
156
157 def _retrieve_global_args_parser(self):
158 if self._global_args_parser is None:
159 if self._global_cmd_driver is not None:
160 command_table = self._global_cmd_driver.subcommand_table
161 self._global_args_parser = (
162 self._global_cmd_driver.create_parser(command_table)
163 )
164 return self._global_args_parser
165
166 def on_building_command_table(
167 self, command_table, event_name, command_object, session, **kwargs
168 ):
169 if (
170 not isinstance(command_object, CLICommand)
171 and event_name == 'building-command-table.main'
172 ):
173 self._global_cmd_driver = command_object
174 return
175 # We have to transform the event name to figure out what the
176 # hierarchy of commands actually is. Normally the hierarchical
177 # events are separated by dots:
178 #
179 # some-event.cloudformation.wait.stack-exists
180 #
181 # But specifically for the `building-command-table` event, this
182 # was purposefully avoided to workaround a specific bug.
183 # As a result the actual event name for
184 #
185 # "aws cloudformation wait stack-exists" would be:
186 #
187 # building-command-table.cloudformation_wait_stack-exists
188 #
189 # See https://github.com/aws/aws-cli/pull/5714 for more details.
190 key_name = tuple(event_name.split('.', 1)[1].split('_'))
191 aliases_for_cmd = self._alias_loader.get_aliases(command=key_name)
192 if not aliases_for_cmd:
193 return
194 for alias_name, alias_value in aliases_for_cmd.items():
195 if self._is_external_alias(alias_value):
196 self._inject_external_alias(
197 alias_name, alias_value, command_table
198 )
199 else:
200 proxied_sub_command = command_table.get(alias_name)
201 command_table[alias_name] = InternalAliasSubCommand(
202 alias_name,
203 alias_value,
204 command_object,
205 self._retrieve_global_args_parser(),
206 session=session,
207 proxied_sub_command=proxied_sub_command,
208 )

Callers 2

setUpMethod · 0.90
register_alias_commandsFunction · 0.85

Calls

no outgoing calls

Tested by 1

setUpMethod · 0.72