2021-12-21 02:42:18 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-12-21 10:36:12 +00:00
|
|
|
set -euo pipefail
|
2021-12-21 02:42:18 +00:00
|
|
|
|
|
|
|
main() {
|
2021-12-21 10:08:26 +00:00
|
|
|
[[ $(type -t _verify-prerequisites) == "function" ]] && ! _verify-prerequisites && exit 1
|
|
|
|
|
2021-12-21 06:48:10 +00:00
|
|
|
redefine-functions-defined-with-selector-16
|
2021-12-21 10:08:26 +00:00
|
|
|
|
2021-12-21 10:36:12 +00:00
|
|
|
if [[ $(type -t "⚡${1:-}") == "function" ]]; then
|
|
|
|
command="$1"
|
|
|
|
shift
|
2021-12-21 10:06:18 +00:00
|
|
|
⚡$command "$@"
|
2021-12-21 02:44:51 +00:00
|
|
|
else
|
2021-12-21 06:48:10 +00:00
|
|
|
⚡help
|
2021-12-21 02:44:51 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-12-21 06:48:10 +00:00
|
|
|
redefine-functions-defined-with-selector-16() {
|
|
|
|
for function in $(compgen -c $(printf "⚡\uFE0F")); do
|
|
|
|
original_definition="$(typeset -f $function)"
|
|
|
|
eval "${original_definition//$(printf "⚡\uFE0F")/⚡}"
|
|
|
|
unset $function
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
⚡help() {
|
2021-12-21 02:44:51 +00:00
|
|
|
_help-line "Show this list" "$@"
|
|
|
|
echo Usage: "$0" SUBCOMMAND
|
|
|
|
echo
|
|
|
|
echo "Available subcommands:"
|
|
|
|
for subcommand in $(_subcommands); do
|
2021-12-21 06:48:10 +00:00
|
|
|
if [[ $(type ⚡$subcommand) =~ _help-line ]]; then
|
|
|
|
printf "\t%-20s - %s\n" "$subcommand" "$(⚡$subcommand help-line)"
|
2021-12-21 02:44:51 +00:00
|
|
|
else
|
2021-12-21 04:51:18 +00:00
|
|
|
printf "\t%-20s\n" $subcommand
|
2021-12-21 02:44:51 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
_subcommands() {
|
2021-12-21 19:05:15 +00:00
|
|
|
prefix_length=1
|
|
|
|
while [[ "$(cut -c ${prefix_length}- <<< "⚡tomato")" != "tomato" ]]; do
|
|
|
|
prefix_length=$((prefix_length + 1))
|
|
|
|
done
|
|
|
|
|
|
|
|
compgen -c ⚡ | cut -c ${prefix_length}-
|
2021-12-21 02:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_help-line() {
|
|
|
|
if [[ "$#" == 2 && "$2" == "help-line" ]]; then
|
|
|
|
echo "$1" && exit 0
|
|
|
|
fi
|
2021-12-21 02:42:18 +00:00
|
|
|
}
|
|
|
|
|
2021-12-21 04:51:18 +00:00
|
|
|
_good-message() {
|
|
|
|
echo -e "\e[32m$@\e[0m"
|
|
|
|
}
|
|
|
|
|
|
|
|
_bad-message() {
|
|
|
|
echo -e "\e[31m$@\e[0m"
|
|
|
|
}
|
|
|
|
|
2021-12-21 10:00:48 +00:00
|
|
|
_wrapper() {
|
|
|
|
unset OPTIND
|
|
|
|
while getopts "l:d:n:v:" opt; do
|
|
|
|
case $opt in
|
|
|
|
l) linux_url=$OPTARG ;;
|
|
|
|
d) darwin_url=$OPTARG ;;
|
|
|
|
n) name=$OPTARG ;;
|
|
|
|
v) version=$OPTARG ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2021-12-21 10:36:12 +00:00
|
|
|
while [[ -n "${1:-}" && "$1" != "--" ]]; do
|
2021-12-21 10:00:48 +00:00
|
|
|
shift
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
|
|
|
|
if [[ $(uname -s) == Linux ]]; then
|
|
|
|
url=$linux_url
|
|
|
|
else
|
|
|
|
url=$darwin_url
|
|
|
|
fi
|
|
|
|
|
|
|
|
wrapper_root=".generated/wrapper/$name/$version/"
|
|
|
|
mkdir -p $wrapper_root
|
|
|
|
[[ -f $wrapper_root/bin ]] || curl --location ${url//VERSION/$version} > $wrapper_root/bin
|
|
|
|
chmod +x $wrapper_root/bin
|
|
|
|
./$wrapper_root/bin "$@"
|
|
|
|
}
|
|
|
|
|
2021-12-21 02:42:18 +00:00
|
|
|
main "$@"
|