How to use the yq.operators.match_error.MatchError function in yq

To help you get started, we’ve selected a few yq examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github abesto / yq / yq / operators / comprehension.py View on Github external
def _apply_item(self, data):
        if not isinstance(data, list):
            raise MatchError(self, data, 'tried to apply comprehension %s to non-array' % self)
        retval = []
        for item in data:
            retval.append(self.op._apply_item(item))
        return retval
github abesto / yq / yq / __main__.py View on Github external
def main(op_str, input):
    op = parser.parse(op_str)
    data = yaml.load(input)
    try:
        for item in op.apply([data]):
            yield item
    except MatchError as ex:
        print ex
github abesto / yq / yq / operators / dot.py View on Github external
def _apply_item(self, data):
        if self.key == '':
            return data
        if not isinstance(data, dict):
            raise MatchError(self, data, 'tried to access field %s on a non-object' % self)
        try:
            return data[self.key]
        except KeyError:
            return None
github abesto / yq / yq.py View on Github external
#!/usr/bin/env python

import yaml
import sys

from yq import parser
from yq.operators.match_error import MatchError
from yq.output import output

op = parser.parse(sys.argv[1])
input = sys.stdin.read()
data = yaml.load(input)

try:
    print output(op.apply(data))
except MatchError as ex:
    print ex