Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
jq_filter_arg_loc = len(jq_args)
if "--args" in jq_args:
jq_filter_arg_loc = jq_args.index('--args') + 1
elif "--jsonargs" in jq_args:
jq_filter_arg_loc = jq_args.index('--jsonargs') + 1
jq_args.insert(jq_filter_arg_loc, args.jq_filter)
delattr(args, "jq_filter")
in_place = args.in_place
delattr(args, "in_place")
if sys.stdin.isatty() and not args.input_streams:
return parser.print_help()
yq_args = dict(input_format=input_format, program_name=program_name, jq_args=jq_args, **vars(args))
if in_place:
if USING_PYTHON2:
sys.exit("{}: -i/--in-place is not compatible with Python 2".format(program_name))
if args.output_format not in {"yaml", "annotated_yaml"}:
sys.exit("{}: -i/--in-place can only be used with -y/-Y".format(program_name))
input_streams = yq_args.pop("input_streams")
if len(input_streams) == 1 and input_streams[0].name == "":
msg = "{}: -i/--in-place can only be used with filename arguments, not on standard input"
sys.exit(msg.format(program_name))
for i, input_stream in enumerate(input_streams):
def exit_handler(arg=None):
if arg:
sys.exit(arg)
if i < len(input_streams):
yq_args["exit_func"] = exit_handler
yq(input_streams=[input_stream], output_stream=DeferredOutputStream(input_stream.name), **yq_args)
else:
yq(**yq_args)