Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument values starting with dash '-' throw "argument --arg: expected 2 arguments" #186

Open
SaberStrat opened this issue Apr 11, 2024 · 1 comment

Comments

@SaberStrat
Copy link

Problem

Trying to pass an argument to the query via --arg with a value starting with a dash, even when passed in quotes, yq throws an error.

# yq -n --arg name "foo" --arg value "-bar" '{"name":$value}'
usage: yq [-h] [--yaml-output] [--yaml-roundtrip] [--yaml-output-grammar-version {1.1,1.2}] [--width WIDTH] [--indentless-lists]
          [--explicit-start] [--explicit-end] [--in-place] [--version]
          [jq_filter] [files ...]
yq: error: argument --arg: expected 2 arguments

It looks as if the --arg value is interpreted as another argument here.

In comparison,jq does not throw an error and even allows passing a dash-prefixed --arg value without quotation marks.

Versions

Plattform

Alpine Linux 3.17.0

yq version

3.2.3

Python version

3.9.16

pip version

23.3.2

jq version

1.6-r2

@kislyuk
Copy link
Owner

kislyuk commented Apr 13, 2024

Thanks for reporting. This is a limitation of argparse, which yq relies on to parse arguments and separate them into yq and jq arguments. I'm not aware of a workaround. You might consider using env (environment variables) in jq to pass the value in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants