mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
Fix local and global commands to accept multiple versions
This commit is contained in:
parent
c007ac728b
commit
f525ba85ff
@ -1,14 +1,16 @@
|
||||
version_command() {
|
||||
local cmd=$1
|
||||
local plugin=$2
|
||||
local version=$3
|
||||
local file
|
||||
|
||||
if [ "$#" -ne 3 ]; then
|
||||
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
|
||||
@ -16,12 +18,14 @@ version_command() {
|
||||
fi
|
||||
|
||||
check_if_plugin_exists $plugin
|
||||
check_if_version_exists $plugin $version
|
||||
for version in $versions; do
|
||||
check_if_version_exists $plugin $version
|
||||
done
|
||||
|
||||
if [ -f "$file" ] && grep $plugin "$file" > /dev/null; then
|
||||
sed -i -e "s/$plugin .*/$plugin $version/" "$file"
|
||||
sed -i -e "s/$plugin .*/$plugin $versions/" "$file"
|
||||
else
|
||||
echo "$plugin $version" >> "$file"
|
||||
echo "$plugin $versions" >> "$file"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,12 @@ teardown() {
|
||||
[ "$(cat $PROJECT_DIR/.tool-versions)" = "dummy 1.1.0" ]
|
||||
}
|
||||
|
||||
@test "local should allow multiple versions" {
|
||||
run local_command "dummy" "1.1.0" "1.0.0"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$(cat $PROJECT_DIR/.tool-versions)" = "dummy 1.1.0 1.0.0" ]
|
||||
}
|
||||
|
||||
@test "local should create a local .tool-versions file if it doesn't exist when the directory name contains whitespace" {
|
||||
WHITESPACE_DIR="$PROJECT_DIR/whitespace\ dir"
|
||||
mkdir -p "$WHITESPACE_DIR"
|
||||
@ -70,6 +76,12 @@ teardown() {
|
||||
[ "$(cat $HOME/.tool-versions)" = "dummy 1.1.0" ]
|
||||
}
|
||||
|
||||
@test "global should accept multiple versions" {
|
||||
run global_command "dummy" "1.1.0" "1.0.0"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$(cat $HOME/.tool-versions)" = "dummy 1.1.0 1.0.0" ]
|
||||
}
|
||||
|
||||
@test "global should overwrite the existing version if it's set" {
|
||||
echo 'dummy 1.0.0' >> $HOME/.tool-versions
|
||||
run global_command "dummy" "1.1.0"
|
||||
|
Loading…
Reference in New Issue
Block a user