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

Allow passing the inline jq script after -- #2919

Merged
merged 1 commit into from
Oct 4, 2023

Conversation

emanuele6
Copy link
Member

@emanuele6 emanuele6 commented Oct 3, 2023

jq previously only allowed passing the inline script before -- (as if they were options) even though one would expect the inline script to be a positional argument.

Since jq previously also refused to run with a usage error if the script was passed after -- (It was not assuming . as script as it does when no arguments are passed), and positional arguments are allowed before -- and even before other options, it should not be a breaking change to change that weird behaviour, and allow the script to appear after --.

It also simplifies the option parsing code a bunch.

Fixes #2918

@emanuele6
Copy link
Member Author

emanuele6 commented Oct 3, 2023

I could add a test for this in shtest.done
Is there some documentation that I should change that I missing?

@emanuele6 emanuele6 force-pushed the allowscriptasarg branch 6 times, most recently from 3892278 to 997b239 Compare October 3, 2023 03:16
@emanuele6
Copy link
Member Author

Editing this code made me realise that --args and --jsonargs are not mutually exclusive; you can pass file inputs even if you use one of those options, and you can even pass file inputs, string arguments, json arguments at the same time to jq as long as they don't look like options:

jq '$ARGS.positional + [ .foo ]' file1 file2 --args str1 str2 --jsonargs '"json1"' '"json2"' '"json3"' --args str3

I never realised that, that's funny. =)

jq previously only allowed passing the inline script before -- (as if
they were options) even though one would expect the inline script to be
a positional argument.

Since jq previously also refused to run with a usage error if the script
was passed after -- (It was not assuming  .  as script as it does when
no arguments are passed), and positional arguments are allowed before --
and even before other options, it should not be a breaking change to
change that weird behaviour, and allow the script to appear after --.

It also simplifies the option parsing code a bunch.

Fixes jqlang#2918
@nicowilliams nicowilliams merged commit 4ebd21e into jqlang:master Oct 4, 2023
29 checks passed
@nicowilliams
Copy link
Contributor

Thanks!

@emanuele6 emanuele6 deleted the allowscriptasarg branch October 4, 2023 05:51
@emanuele6 emanuele6 changed the title Allow passing the inline jq script before -- Allow passing the inline jq script after -- Oct 4, 2023
@emanuele6
Copy link
Member Author

Oops, I should have said "after", not "before" in the title.

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

Successfully merging this pull request may close these issues.

Allow -- to come just before the jq program
2 participants