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

Method _get_query

awscli/autoprompt/output.py:77–106  ·  view source on GitHub ↗
(self, parsed)

Source from the content-addressed store, hash-verified

75 return output, error_message
76
77 def _get_query(self, parsed):
78 error_message = None
79 if parsed.current_param == 'query':
80 query = parsed.current_fragment
81 else:
82 query = parsed.global_params.get('query')
83 if query:
84 # Because output example has only 1 element in any list if
85 # user enters query like Groups[2] jmespath will return "null"
86 # so we change all the numbers in brackets to 0 to keep the output
87 # meaningful
88 query = re.sub(r'([\{\[])\d+?([\}\]])', r'\g<1>0\g<2>', query)
89 # In case of incorrect expression we return an error message
90 # but we want to do it only in the case expression is really broken
91 # and not during user types it so if expression has open bracket
92 # with input at the end or trailing dot we remove this part before
93 # parsing, for example:
94 #
95 # for "Groups." we will parse only "Groups"
96 # for "Groups.Names[34" we will parse only "Groups.Names"
97 query = re.sub(r'([\{\[])[^\]^\}]*$', '', query).strip('.')
98 try:
99 self._current_expression = jmespath.compile(query)
100 except jmespath.exceptions.ParseError as e:
101 error_message = "Bad value for --query: %s\n\n%s" % (query, str(e))
102 except jmespath.exceptions.EmptyExpressionError:
103 self._current_expression = None
104 except Exception:
105 LOG.debug('Exception caught in OutputGetter: ', exc_info=True)
106 return self._current_expression, error_message
107
108 def _get_display(self, operation, output_shape, output, query):
109 args = argparse.Namespace(query=query, color='off')

Callers 1

get_outputMethod · 0.95

Calls 1

subMethod · 0.80

Tested by

no test coverage detected