asdf/lib/commands/version_commands.sh

41 lines
705 B
Bash
Raw Normal View History

#!/usr/bin/env bash
version_command() {
local cmd=$1
local plugin=$2
if [ "$#" -lt "3" ]; then
echo "Usage: asdf $cmd <name> <version>"
exit 1
fi
shift 2
local versions=$@
local file
if [ $cmd = "global" ]; then
file=$HOME/.tool-versions
else
2016-05-13 19:11:16 -07:00
file=$(pwd)/.tool-versions
fi
check_if_plugin_exists $plugin
for version in $versions; do
check_if_version_exists $plugin $version
done
2016-08-16 07:54:36 -07:00
if [ -f "$file" ] && grep $plugin "$file" > /dev/null; then
sed -i -e "s/$plugin .*/$plugin $versions/" "$file"
else
echo "$plugin $versions" >> "$file"
fi
}
local_command() {
version_command "local" $@
}
global_command() {
version_command "global" $@
}