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

Class ParamShorthandParser

awscli/argprocess.py:305–440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

303
304
305class ParamShorthandParser(ParamShorthand):
306 def __init__(self):
307 self._parser = shorthand.ShorthandParser()
308 self._visitor = shorthand.BackCompatVisitor()
309
310 def __call__(self, cli_argument, value, event_name, **kwargs):
311 """Attempt to parse shorthand syntax for values.
312
313 This is intended to be hooked up as an event handler (hence the
314 **kwargs). Given ``param`` object and its string ``value``,
315 figure out if we can parse it. If we can parse it, we return
316 the parsed value (typically some sort of python dict).
317
318 :type cli_argument: :class:`awscli.arguments.BaseCLIArgument`
319 :param cli_argument: The CLI argument object.
320
321 :type param: :class:`botocore.parameters.Parameter`
322 :param param: The parameter object (includes various metadata
323 about the parameter).
324
325 :type value: str
326 :param value: The value for the parameter type on the command
327 line, e.g ``--foo this_value``, value would be ``"this_value"``.
328
329 :returns: If we can parse the value we return the parsed value.
330 If it looks like JSON, we return None (which tells the event
331 emitter to use the default ``unpack_cli_arg`` provided that
332 no other event handlers can parsed the value). If we
333 run into an error parsing the value, a ``ParamError`` will
334 be raised.
335
336 """
337
338 if not self._should_parse_as_shorthand(cli_argument, value):
339 return
340 else:
341 command_name, operation_name = (
342 find_service_and_method_in_event_name(event_name)
343 )
344 return self._parse_as_shorthand(
345 cli_argument, value, command_name, operation_name
346 )
347
348 def _parse_as_shorthand(
349 self, cli_argument, value, command_name, operation_name
350 ):
351 try:
352 LOG.debug("Parsing param %s as shorthand", cli_argument.cli_name)
353 handled_value = self._handle_special_cases(
354 cli_argument, value, command_name, operation_name
355 )
356 if handled_value is not None:
357 return handled_value
358 if isinstance(value, list):
359 # Because of how we're using argparse, list shapes
360 # are configured with nargs='+' which means the ``value``
361 # is given to us "conveniently" as a list. When
362 # this happens we need to parse each list element

Callers 5

setUpMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by 3

setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72