mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
Remove getter feature on local and global commands
This simplifies the `local` and `global` commands. `asdf current` should be sufficient for getting the current version. closes #80
This commit is contained in:
parent
0ce18100c5
commit
7517aa3abc
14
README.md
14
README.md
@ -132,19 +132,11 @@ asdf list-all <name>
|
||||
#### View current version
|
||||
|
||||
```bash
|
||||
asdf local [name]
|
||||
asdf global [name]
|
||||
# asdf local
|
||||
# asdf global
|
||||
# asdf local elixir
|
||||
# asdf global elixir
|
||||
asdf current <name>
|
||||
# asdf current erlang
|
||||
# 17.3 (set by /Users/kim/.tool-versions)
|
||||
```
|
||||
|
||||
`global` reads from `$HOME/.tool-versions`.
|
||||
|
||||
`local` reads from `$PWD/.tool-versions` if it exists,
|
||||
or searches recursively in the parent directories until it finds a `.tool-versions` file.
|
||||
|
||||
#### Set current version
|
||||
|
||||
```bash
|
||||
|
2
help.txt
2
help.txt
@ -13,9 +13,7 @@ MANAGE PACKAGES
|
||||
asdf uninstall <name> <version> Remove a specific version of a package
|
||||
asdf current <name> Display current version set or being used for package
|
||||
asdf where <name> <version> Display install path for an installed version
|
||||
asdf local [name] Display a package local version
|
||||
asdf local <name> <version> Set the package local version
|
||||
asdf global [name] Display a package global version
|
||||
asdf global <name> <version> Set the package global version
|
||||
asdf list <name> List installed versions of a package
|
||||
asdf list-all <name> List all versions of a package
|
||||
|
@ -1,70 +1,21 @@
|
||||
get_plugin_version() {
|
||||
local cmd=$1
|
||||
local file=$2
|
||||
local plugin=$3
|
||||
local legacy_version_file_support=$(get_asdf_config_value "legacy_version_file")
|
||||
local result
|
||||
|
||||
if [ $cmd = "local" -a "$legacy_version_file_support" = "yes" -a \
|
||||
\( ! -f $file -o $file = "$HOME/.tool-versions" \) ]; then
|
||||
result=$(get_tool_version_from_legacy_file $plugin $(pwd))
|
||||
if [ -n "$result" ]; then
|
||||
echo $result
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -f $file ]; then
|
||||
result=$(get_tool_version_from_file $file $plugin)
|
||||
fi
|
||||
|
||||
if [ -n "$result" ]; then
|
||||
echo $result
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
echo "version not set for $plugin"
|
||||
exit 1
|
||||
}
|
||||
|
||||
version_command() {
|
||||
local cmd=$1
|
||||
|
||||
local plugin=$2
|
||||
local version=$3
|
||||
local file
|
||||
if [ $cmd = "global" ]; then
|
||||
file=$HOME/.tool-versions
|
||||
else
|
||||
file=$(get_asdf_versions_file_path)
|
||||
if [ -z "$file" ]; then
|
||||
file=.tool-versions
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $# -eq 1 -a ! -f $file ]; then
|
||||
echo $file does not exist
|
||||
if [ "$#" -ne 3 ]; then
|
||||
echo "Usage: asdf $cmd <name> <version>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ $# -eq 1 ]; then
|
||||
cat $file
|
||||
exit 0
|
||||
fi
|
||||
|
||||
local plugin=$2
|
||||
|
||||
check_if_plugin_exists $plugin
|
||||
|
||||
if [ $# -eq 2 ]; then
|
||||
get_plugin_version $cmd $file $plugin
|
||||
fi
|
||||
|
||||
local version=${@:3}
|
||||
|
||||
if [ $cmd = "local" ]; then
|
||||
if [ $cmd = "global" ]; then
|
||||
file=$HOME/.tool-versions
|
||||
else
|
||||
file=$(pwd)/.tool-versions
|
||||
fi
|
||||
|
||||
check_if_plugin_exists $plugin
|
||||
check_if_version_exists $plugin $version
|
||||
|
||||
if [ -f $file ] && grep $plugin $file > /dev/null; then
|
||||
|
@ -9,14 +9,10 @@ setup() {
|
||||
install_dummy_plugin
|
||||
install_dummy_version "1.0.0"
|
||||
install_dummy_version "1.1.0"
|
||||
install_dummy_version "1.2.0"
|
||||
|
||||
PROJECT_DIR=$BASE_DIR/project
|
||||
PROJECT_DIR=$HOME/project
|
||||
mkdir -p $PROJECT_DIR
|
||||
|
||||
echo 'dummy 1.0.0' >> $HOME/.tool-versions
|
||||
echo 'dummy 1.1.0' >> $PROJECT_DIR/.tool-versions
|
||||
|
||||
cd $PROJECT_DIR
|
||||
}
|
||||
|
||||
@ -24,19 +20,11 @@ teardown() {
|
||||
clean_asdf_dir
|
||||
}
|
||||
|
||||
|
||||
@test "local should emit an error when run in lookup mode and file does not exist" {
|
||||
rm .tool-versions
|
||||
run local_command
|
||||
# Warn users who invoke the old style command without arguments.
|
||||
@test "local should emit an error when called with incorrect arity" {
|
||||
run local_command "dummy"
|
||||
[ "$status" -eq 1 ]
|
||||
[ "$output" = ".tool-versions does not exist" ]
|
||||
}
|
||||
|
||||
@test "global should emit an error when run in lookup mode and file does not exist" {
|
||||
rm $HOME/.tool-versions
|
||||
run global_command "dummy"
|
||||
[ "$status" -eq 1 ]
|
||||
[ "$output" = "version not set for dummy" ]
|
||||
[ "$output" = "Usage: asdf local <name> <version>" ]
|
||||
}
|
||||
|
||||
@test "local should emit an error when plugin does not exist" {
|
||||
@ -51,69 +39,28 @@ teardown() {
|
||||
[ "$output" = "version 0.0.1 is not installed for dummy" ]
|
||||
}
|
||||
|
||||
@test "local should return and set the local version" {
|
||||
|
||||
run local_command
|
||||
@test "local should create a local .tool-versions file if it doesn't exist" {
|
||||
run local_command "dummy" "1.1.0"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "dummy 1.1.0" ]
|
||||
|
||||
run local_command dummy "1.2.0"
|
||||
|
||||
run local_command dummy
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "1.2.0" ]
|
||||
|
||||
rm .tool-versions
|
||||
run local_command dummy 1.2.0
|
||||
[ -f .tool-versions ]
|
||||
|
||||
run local_command dummy
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "1.2.0" ]
|
||||
run global_command dummy
|
||||
[ "$output" = "1.0.0" ]
|
||||
|
||||
mkdir $BASE_DIR/other && cd $BASE_DIR/other
|
||||
|
||||
run local_command dummy
|
||||
[ "$status" -eq 1 ]
|
||||
|
||||
run local_command dummy 1.0.0
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
run local_command dummy
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "1.0.0" ]
|
||||
[ "$(cat $PROJECT_DIR/.tool-versions)" = "dummy 1.1.0" ]
|
||||
}
|
||||
|
||||
@test "local should fallback to legacy-file when enabled" {
|
||||
echo 'legacy_version_file = yes' > $HOME/.asdfrc
|
||||
echo '1.3.0' > .dummy-version
|
||||
rm .tool-versions
|
||||
run local_command dummy
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "1.3.0" ]
|
||||
@test "local should overwrite the existing version if it's set" {
|
||||
echo 'dummy 1.0.0' >> $PROJECT_DIR/.tool-versions
|
||||
run local_command "dummy" "1.1.0"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$(cat $PROJECT_DIR/.tool-versions)" = "dummy 1.1.0" ]
|
||||
}
|
||||
|
||||
@test "local should ignore legacy-file when disabled" {
|
||||
rm .tool-versions
|
||||
run local_command dummy
|
||||
|
||||
[ "$status" -eq 1 ]
|
||||
[ "$output" = "version not set for dummy" ]
|
||||
@test "global should create a global .tool-versions file if it doesn't exist" {
|
||||
run global_command "dummy" "1.1.0"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$(cat $HOME/.tool-versions)" = "dummy 1.1.0" ]
|
||||
}
|
||||
|
||||
|
||||
@test "global should return and set the global version" {
|
||||
run global_command
|
||||
@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"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "dummy 1.0.0" ]
|
||||
|
||||
run global_command dummy 1.2.0
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
run global_command dummy
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "1.2.0" ]
|
||||
[ "$(cat $HOME/.tool-versions)" = "dummy 1.1.0" ]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user