From ea138b9e9a23ece02320a1f82bd0a6fb53464287 Mon Sep 17 00:00:00 2001 From: Emanuele Torre Date: Tue, 3 Oct 2023 04:39:42 +0200 Subject: [PATCH] Allow passing the inline jq script before -- It previously was only allowed to pass inline scripts to jq before -- (as if they were options), and not after --; 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. --- docs/content/manual/manual.yml | 5 ++--- jq.1.prebuilt | 4 ++-- src/main.c | 25 ++++--------------------- tests/shtest | 10 ++++++++++ 4 files changed, 18 insertions(+), 26 deletions(-) diff --git a/docs/content/manual/manual.yml b/docs/content/manual/manual.yml index 6ce8233c7d..be282a34ef 100644 --- a/docs/content/manual/manual.yml +++ b/docs/content/manual/manual.yml @@ -313,9 +313,8 @@ sections: * `--`: - Terminates argument processing. Remaining arguments are - positional, either strings, JSON texts, or input filenames, - according to whether `--args` or `--jsonargs` were given. + Terminates argument processing. Remaining arguments are not + intreted as options. * `--run-tests [filename]`: diff --git a/jq.1.prebuilt b/jq.1.prebuilt index a421a502cb..9dcfe38764 100644 --- a/jq.1.prebuilt +++ b/jq.1.prebuilt @@ -1,5 +1,5 @@ . -.TH "JQ" "1" "September 2023" "" "" +.TH "JQ" "1" "October 2023" "" "" . .SH "NAME" \fBjq\fR \- Command\-line JSON processor @@ -250,7 +250,7 @@ Output the jq help and exit with zero\. \fB\-\-\fR: . .IP -Terminates argument processing\. Remaining arguments are positional, either strings, JSON texts, or input filenames, according to whether \fB\-\-args\fR or \fB\-\-jsonargs\fR were given\. +Terminates argument processing\. Remaining arguments are not intreted as options\. . .TP \fB\-\-run\-tests [filename]\fR: diff --git a/src/main.c b/src/main.c index 6d857c3671..226c926ce2 100644 --- a/src/main.c +++ b/src/main.c @@ -353,8 +353,10 @@ int main(int argc, char* argv[]) { size_t short_opts = 0; jv lib_search_paths = jv_null(); for (int i=1; i /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