"exec" "$$(dirname $$(readlink -f $$0))/python3" "$$0" "$$@"
from pprint import pformat
from jmespath import exceptions
parser = argparse.ArgumentParser()
parser.add_argument('expression')
parser.add_argument('-f', '--filename',
help=('The filename containing the input data. '
'If a filename is not given then data is '
parser.add_argument('--ast', action='store_true',
help=('Pretty print the AST, do not search the data.'))
args = parser.parse_args()
expression = args.expression
expression = jmespath.compile(args.expression)
sys.stdout.write(pformat(expression.parsed))
with open(args.filename, 'r') as f:
sys.stdout.write(json.dumps(
jmespath.search(expression, data), indent=4, ensure_ascii=False))
except exceptions.ArityError as e:
sys.stderr.write("invalid-arity: %s\n" % e)
except exceptions.JMESPathTypeError as e:
sys.stderr.write("invalid-type: %s\n" % e)
except exceptions.UnknownFunctionError as e:
sys.stderr.write("unknown-function: %s\n" % e)
except exceptions.ParseError as e:
sys.stderr.write("syntax-error: %s\n" % e)
if __name__ == '__main__':