Skip to content

Commit fba054b

Browse files
committed
feat(jq): support all command-line options
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.
1 parent cbe5e41 commit fba054b

File tree

1 file changed

+18
-1
lines changed
  • completions

1 file changed

+18
-1
lines changed

completions/jq

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,25 @@ _jq()
3434
;;
3535
esac
3636

37+
# See whether the output of --help mentions --help
38+
SEEMS_TO_HAVE_COMPLETE_HELP=$(jq --help | grep -q -e --help && echo yes || echo no)
39+
40+
# jq's --help only shows some of its command-line options; some are not
41+
# even listed in the man page!
3742
if [[ $cur == -* ]]; then
38-
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
43+
if [[ $SEEMS_TO_HAVE_COMPLETE_HELP == yes ]]; then
44+
# If the output of --help seems complete, use it
45+
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
46+
else
47+
# Otherwise, use a hard-coded list of known flags, some of which do
48+
# not appear in the output of --help as of jq 1.6.
49+
COMPREPLY=($(compgen -W '--version --seq --stream --slurp --raw-input
50+
--null-input --compact-input --tab --indent --color-output
51+
--monochrome-output --ascii-output --unbuffered --sort-keys
52+
--raw-output --join-output --from-file --exit-status
53+
--arg --argjson --slurpfile --rawfile --argfile --args --jsonargs
54+
--run-tests --help --version' -- "$cur"))
55+
fi
3956
return
4057
fi
4158

0 commit comments

Comments
 (0)