Skip to content

Commit

Permalink
feat(jq): support all command-line options
Browse files Browse the repository at this point in the history
The options are not all listed by --help, so look in the man page to find a
nearly complete list (I hope!). Neither the man page nor --help mentions --help
or --version; I have not looked elsewhere to see if there might be yet more.

Guard against the possibility of jq being fixed in future by testing to see if
its --help output contains “--help” and using it if so, otherwise, use the
hard-coded list; see
jqlang/jq#2284
  • Loading branch information
rrthomas committed Mar 27, 2021
1 parent f1ddf81 commit 677d152
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion completions/jq
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,24 @@ _jq()
esac

if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
# Get jq's --help output and see whether it mentions --help
# jq's --help only shows some of its command-line options; some are not
# even listed in the man page!
local help_output=$("$1" --help 2>/dev/null)

if [[ "$help_output" == *--help* ]]; then
# If the output of --help seems complete, use it
COMPREPLY=($(compgen -W '$(printf "%s" "$help_output" | _parse_help -)' -- "$cur"))
else
# Otherwise, use a hard-coded list of known flags, some of which do
# not appear in the output of --help as of jq 1.6.
COMPREPLY=($(compgen -W '--version --seq --stream --slurp --raw-input
--null-input --compact-input --tab --indent --color-output
--monochrome-output --ascii-output --unbuffered --sort-keys
--raw-output --join-output --from-file --exit-status
--arg --argjson --slurpfile --rawfile --argfile --args --jsonargs
--run-tests --help --version' -- "$cur"))
fi
return
fi

Expand Down

0 comments on commit 677d152

Please sign in to comment.