Allow passing the inline jq script before --

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
This commit is contained in:
Emanuele Torre authored and Nico Williams committed 2023-10-04 00:00:46 -05:00
1 parent 7f547827e4
commit 4ebd21e1eb
4 files changed
+17 -25

No files matched your search

+10
View File
@@ -579,4 +579,14 @@ if ( ! $msys && ! $mingw ) && locale -a > /dev/null; then
fi
fi
# Allow passing the inline jq script before -- #2919
if ! r=$($JQ --args -rn -- '$ARGS.positional[0]' bar) || [ "$r" != bar ]; then
echo "passing the inline script after -- didn't work"
exit 1
fi
if ! r=$($JQ --args -rn 1 -- '$ARGS.positional[0]' bar) || [ "$r" != 1 ]; then
echo "passing the inline script before -- didn't work"
exit 1
fi
exit 0