fix(coffee): fix completion bug on missing `coffee` command (#10759)

This commit fixes the error

  _coffee:49: bad math expression: operand expected at `< 2 '

when the coffee command is missing or the `coffee --version` command fails.

It also uses is-at-least to check for the cut-off version for suggesting
`--lint` and `--require` arguments, instead of using `cut` multiple times.

Fixes #10759
parent 93b348b1
...@@ -39,14 +39,14 @@ ...@@ -39,14 +39,14 @@
# #
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
local curcontext="$curcontext" state line ret=1 version opts first second third local curcontext="$curcontext" state line ret=1 version
local -a opts
typeset -A opt_args typeset -A opt_args
version=(${(f)"$(_call_program version $words[1] --version)"}) version=(${(f)"$(_call_program version $words[1] --version)"}) || return ret
version=${${(z)${version[1]}}[3]} version=${${(z)${version[1]}}[3]}
first=$(echo $version|cut -d '.' -f 1)
second=$(echo $version|cut -d '.' -f 2) autoload -Uz is-at-least
third=$(echo $version|cut -d '.' -f 3) if ! is-at-least 1.6.3 "$version"; then
if (( $first < 2 )) && (( $second < 7 )) && (( $third < 3 ));then
opts+=('(-l --lint)'{-l,--lint}'[pipe the compiled JavaScript through JavaScript Lint]' opts+=('(-l --lint)'{-l,--lint}'[pipe the compiled JavaScript through JavaScript Lint]'
'(-r --require)'{-r,--require}'[require a library before executing your script]:library') '(-r --require)'{-r,--require}'[require a library before executing your script]:library')
fi fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment