install.zsh: allow alternatives in deps
Specify a dependency as a|b to check if either a or b is available as a command. The script itself must check at runtime, which one is actually available and use the right one. Helper methods for this are provided in lib/common.zsh: - `alternatives a b` aliases a to b, if a is not available - `alternatives-noparam a b` replaces a with b, if a is not available, and discards any parameters (e.g. for replacing a formatter with cat)
This commit is contained in:
parent
0ca3e95262
commit
7c14c8ae1a
|
@ -6,15 +6,16 @@ typeset -A interpreter_checked
|
|||
have_dependency() {
|
||||
if [[ ! $interpreter_checked[$1] ]]; then
|
||||
check "Checking for $1… "
|
||||
if which $1 &> /dev/null; then
|
||||
for variant in ${(s.|.)1}; do
|
||||
if which $variant &> /dev/null; then
|
||||
succeed
|
||||
interpreter_checked[$1]=1
|
||||
return 0
|
||||
else
|
||||
fi
|
||||
done
|
||||
fail "not found in path"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,14 @@ exists() {
|
|||
type "$1" &>/dev/null
|
||||
}
|
||||
|
||||
alternative() {
|
||||
if ! exists $1; then eval "$1(){ $2 \$@}"; fi
|
||||
}
|
||||
|
||||
alternative-noparam() {
|
||||
if ! exists $1; then eval "$1(){ $2 }"; fi
|
||||
}
|
||||
|
||||
depend() {
|
||||
local missing
|
||||
local i
|
||||
|
|
Loading…
Reference in a new issue