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
17
install.zsh
17
install.zsh
|
@ -6,14 +6,15 @@ typeset -A interpreter_checked
|
||||||
have_dependency() {
|
have_dependency() {
|
||||||
if [[ ! $interpreter_checked[$1] ]]; then
|
if [[ ! $interpreter_checked[$1] ]]; then
|
||||||
check "Checking for $1… "
|
check "Checking for $1… "
|
||||||
if which $1 &> /dev/null; then
|
for variant in ${(s.|.)1}; do
|
||||||
succeed
|
if which $variant &> /dev/null; then
|
||||||
interpreter_checked[$1]=1
|
succeed
|
||||||
return 0
|
interpreter_checked[$1]=1
|
||||||
else
|
return 0
|
||||||
fail "not found in path"
|
fi
|
||||||
return 1
|
done
|
||||||
fi
|
fail "not found in path"
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,14 @@ exists() {
|
||||||
type "$1" &>/dev/null
|
type "$1" &>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
alternative() {
|
||||||
|
if ! exists $1; then eval "$1(){ $2 \$@}"; fi
|
||||||
|
}
|
||||||
|
|
||||||
|
alternative-noparam() {
|
||||||
|
if ! exists $1; then eval "$1(){ $2 }"; fi
|
||||||
|
}
|
||||||
|
|
||||||
depend() {
|
depend() {
|
||||||
local missing
|
local missing
|
||||||
local i
|
local i
|
||||||
|
|
Loading…
Reference in a new issue