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
|
2018-10-19 17:29:31 -07:00
|
|
|
if [ "$cmd" = "global" ]; then
|
|
|
|
echo "Usage: asdf global <name> <version>"
|
|
|
|
else
|
|
|
|
echo "Usage: asdf local <name> <version>"
|
|
|
|
fi
|
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
|
2018-02-12 16:41:27 -07:00
|
|
|
if [ "$cmd" = "global" ]; then
|
2017-09-14 04:21:36 -07:00
|
|
|
file=${ASDF_DEFAULT_TOOL_VERSIONS_FILENAME:-$HOME/.tool-versions}
|
2018-10-19 17:29:31 -07:00
|
|
|
elif [ "$cmd" = "local-tree" ]; then
|
|
|
|
file=$(find_tool_versions)
|
|
|
|
else # cmd = local
|
2017-09-04 10:04:56 -07:00
|
|
|
file="$(pwd)/.tool-versions"
|
2016-05-13 19:11:16 -07:00
|
|
|
fi
|
|
|
|
|
2018-06-16 19:59:37 -07:00
|
|
|
if [ -L "$file" ]; then
|
|
|
|
# Resolve file path if symlink
|
|
|
|
file="$(resolve_symlink "$file")"
|
|
|
|
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
|
|
|
|
2018-06-16 19:59:37 -07:00
|
|
|
|
2017-12-15 18:05:52 -07:00
|
|
|
if [ -f "$file" ] && grep "^$plugin " "$file" > /dev/null; then
|
2018-02-11 13:12:31 -07:00
|
|
|
sed -i.bak -e "s/^$plugin .*$/$plugin ${versions[*]}/" "$file"
|
2017-10-27 07:27:27 -07:00
|
|
|
rm "$file".bak
|
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() {
|
2018-10-19 17:29:31 -07:00
|
|
|
local parent=false
|
|
|
|
local positional=()
|
|
|
|
|
|
|
|
while [[ $# -gt 0 ]]
|
|
|
|
do
|
|
|
|
case $1 in
|
|
|
|
-p|--parent)
|
|
|
|
parent="true"
|
|
|
|
shift # past value
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
positional+=("$1") # save it in an array for later
|
|
|
|
shift # past argument
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
set -- "${positional[@]}" # restore positional parameters
|
|
|
|
|
|
|
|
if [ $parent = true ]; then
|
|
|
|
# shellcheck disable=2068
|
|
|
|
version_command "local-tree" $@
|
|
|
|
else
|
|
|
|
# shellcheck disable=2068
|
|
|
|
version_command "local" $@
|
|
|
|
fi
|
2016-04-24 08:11:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
global_command() {
|
2017-09-04 10:04:56 -07:00
|
|
|
# shellcheck disable=2068
|
2016-04-24 08:11:33 -07:00
|
|
|
version_command "global" $@
|
|
|
|
}
|