Skip to content

Commit 450c676

Browse files
authored
feat(jq): support all command-line options (scop#507)
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
1 parent f1ddf81 commit 450c676

File tree

1 file changed

+19
-1
lines changed
  • completions

1 file changed

+19
-1
lines changed

completions/jq

+19-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,25 @@ _jq()
3535
esac
3636

3737
if [[ $cur == -* ]]; then
38-
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
38+
# Get jq's --help output and see whether it mentions --help
39+
# jq's --help only shows some of its command-line options; some are not
40+
# even listed in the man page!
41+
local help_output=$("$1" --help 2>/dev/null)
42+
43+
if [[ $help_output == *--help* ]]; then
44+
# If the output of --help seems complete, use it
45+
COMPREPLY=($(compgen -W \
46+
'$(printf "%s" "$help_output" | _parse_help -)' -- "$cur"))
47+
else
48+
# Otherwise, use a hard-coded list of known flags, some of which do
49+
# not appear in the output of --help as of jq 1.6.
50+
COMPREPLY=($(compgen -W '--version --seq --stream --slurp
51+
--raw-input --null-input --compact-output --tab --indent
52+
--color-output -monochrome-output --ascii-output --unbuffered
53+
--sort-keys --raw-output --join-output --from-file --exit-status
54+
--arg --argjson --slurpfile --rawfile --argfile --args
55+
--jsonargs --run-tests --help' -- "$cur"))
56+
fi
3957
return
4058
fi
4159

0 commit comments

Comments
 (0)