2016-04-24 08:11:33 -07:00
|
|
|
version_command() {
|
|
|
|
local cmd=$1
|
2016-07-23 05:46:02 -07:00
|
|
|
local plugin=$2
|
2016-04-24 08:11:33 -07:00
|
|
|
|
2016-08-29 23:46:14 -07:00
|
|
|
if [ "$#" -lt "3" ]; then
|
2016-07-23 05:46:02 -07:00
|
|
|
echo "Usage: asdf $cmd <name> <version>"
|
2016-04-24 08:11:33 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-08-29 23:46:14 -07:00
|
|
|
shift 2
|
2017-09-04 10:04:56 -07:00
|
|
|
local versions=("$@")
|
2016-08-29 23:46:14 -07:00
|
|
|
|
|
|
|
local file
|
2017-09-04 10:04:56 -07:00
|
|
|
if [ "$cmd" = "global" ]; then
|
|
|
|
file="$HOME/.tool-versions"
|
2016-07-23 05:46:02 -07:00
|
|
|
else
|
2017-09-04 10:04:56 -07:00
|
|
|
file="$(pwd)/.tool-versions"
|
2016-05-13 19:11:16 -07:00
|
|
|
fi
|
|
|
|
|
2017-09-04 10:04:56 -07:00
|
|
|
check_if_plugin_exists "$plugin"
|
|
|
|
|
|
|
|
local version
|
|
|
|
for version in "${versions[@]}"; do
|
|
|
|
check_if_version_exists "$plugin" "$version"
|
2016-08-29 23:46:14 -07:00
|
|
|
done
|
2016-04-24 08:11:33 -07:00
|
|
|
|
2017-09-04 10:04:56 -07:00
|
|
|
if [ -f "$file" ] && grep "$plugin" "$file" > /dev/null; then
|
|
|
|
sed -i -e "s/$plugin .*/$plugin ${versions[*]}/" "$file"
|
2016-04-24 08:11:33 -07:00
|
|
|
else
|
2017-09-04 10:04:56 -07:00
|
|
|
echo "$plugin ${versions[*]}" >> "$file"
|
2016-04-24 08:11:33 -07:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
local_command() {
|
2017-09-04 10:04:56 -07:00
|
|
|
# shellcheck disable=2068
|
2016-04-24 08:11:33 -07:00
|
|
|
version_command "local" $@
|
|
|
|
}
|
|
|
|
|
|
|
|
global_command() {
|
2017-09-04 10:04:56 -07:00
|
|
|
# shellcheck disable=2068
|
2016-04-24 08:11:33 -07:00
|
|
|
version_command "global" $@
|
|
|
|
}
|