Skip to content

Allow passing the inline jq script after -- - #2919

Merged
nicowilliams merged 1 commit into
jqlang:masterfrom
emanuele6:allowscriptasarg
Oct 4, 2023
Merged

nicowilliams merged 1 commit into
jqlang:masterfrom
emanuele6:allowscriptasarg

Conversation

@emanuele6

@emanuele6 emanuele6 commented Oct 3, 2023

Copy link
Copy Markdown
Member

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
emanuele6 requested a review from nicowilliams October 3, 2023 02:40
@emanuele6

emanuele6 commented Oct 3, 2023

Copy link
Copy Markdown
Member Author

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
Comment thread docs/content/manual/manual.yml
@emanuele6

Copy link
Copy Markdown
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. =)

@emanuele6 emanuele6 self-assigned this Oct 3, 2023
Comment thread src/main.c
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
@nicowilliams

Copy link
Copy Markdown
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
Copy Markdown
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