Skip to content

Commit ca1273e

Browse files
rockwoodDaniel Perez
authored andcommitted
Rename which to current (asdf-vm#79)
* Rename `asdf which` -> `asdf current` * Output `set by $path` with current command * Use dummy plugin in current_command test * Hide "set by" message if derived from legacy file
1 parent 337b335 commit ca1273e

File tree

10 files changed

+120
-27
lines changed

10 files changed

+120
-27
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ asdf plugin-update <name>
105105
asdf install <name> <version>
106106
# asdf install erlang 17.3
107107

108-
asdf which <name>
109-
# asdf which erlang
110-
# 17.3
108+
asdf current <name>
109+
# asdf current erlang
110+
# 17.3 (set by /Users/kim/.tool-versions)
111111

112112
asdf uninstall <name> <version>
113113
# asdf uninstall erlang 17.3

bin/asdf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ source $(dirname $(dirname $0))/lib/utils.sh
55
source $(dirname $(dirname $0))/lib/commands/help.sh
66
source $(dirname $(dirname $0))/lib/commands/install.sh
77
source $(dirname $(dirname $0))/lib/commands/uninstall.sh
8-
source $(dirname $(dirname $0))/lib/commands/which.sh
8+
source $(dirname $(dirname $0))/lib/commands/current.sh
99
source $(dirname $(dirname $0))/lib/commands/where.sh
1010
source $(dirname $(dirname $0))/lib/commands/version_commands.sh
1111
source $(dirname $(dirname $0))/lib/commands/list.sh
@@ -36,8 +36,8 @@ case $1 in
3636
"uninstall")
3737
uninstall_command $callback_args;;
3838

39-
"which")
40-
which_command $callback_args;;
39+
"current")
40+
current_command $callback_args;;
4141

4242
"where")
4343
where_command $callback_args;;

completions/asdf.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ _asdf () {
1212
plugin-update)
1313
COMPREPLY=($(compgen -W "$plugins --all" -- $cur))
1414
;;
15-
plugin-remove|which|list|list-all)
15+
plugin-remove|current|list|list-all)
1616
COMPREPLY=($(compgen -W "$plugins" -- $cur))
1717
;;
1818
install)
@@ -32,7 +32,7 @@ _asdf () {
3232
fi
3333
;;
3434
*)
35-
local cmds='plugin-add plugin-list plugin-remove plugin-update install uninstall which where list list-all reshim'
35+
local cmds='plugin-add plugin-list plugin-remove plugin-update install uninstall current where list list-all reshim'
3636
COMPREPLY=($(compgen -W "$cmds" -- $cur))
3737
;;
3838
esac

completions/asdf.fish

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ complete -f -c asdf -n '__fish_asdf_needs_command' -a uninstall -d "Remove a spe
5656
complete -f -c asdf -n '__fish_asdf_using_command uninstall; and __fish_asdf_arg_number 2' -a '(asdf plugin-list)'
5757
complete -f -c asdf -n '__fish_asdf_using_command uninstall; and __fish_asdf_arg_number 3' -a '(asdf list (__fish_asdf_arg_at 3))'
5858

59-
# which completion
60-
complete -f -c asdf -n '__fish_asdf_needs_command' -a which -d "Display version set or being used for package"
61-
complete -f -c asdf -n '__fish_asdf_using_command which; and __fish_asdf_arg_number 2' -a '(asdf plugin-list)'
59+
# current completion
60+
complete -f -c asdf -n '__fish_asdf_needs_command' -a current -d "Display version set or being used for package"
61+
complete -f -c asdf -n '__fish_asdf_using_command current; and __fish_asdf_arg_number 2' -a '(asdf plugin-list)'
6262

6363
# where completion
6464
complete -f -c asdf -n '__fish_asdf_needs_command' -a where -d "Display install path for an installed version"

help.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ MANAGE PACKAGES
1111
with no arguments, install all the package
1212
versions listed in the .tool-versions file
1313
asdf uninstall <name> <version> Remove a specific version of a package
14-
asdf which <name> Display version set or being used for package
14+
asdf current <name> Display current version set or being used for package
1515
asdf where <name> <version> Display install path for an installed version
1616
asdf local [name] Display a package local version
1717
asdf local <name> <version> Set the package local version

lib/commands/current.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
current_command() {
2+
local plugin_name=$1
3+
local version=$(get_preset_version_for $plugin_name)
4+
5+
check_if_plugin_exists $plugin_name
6+
7+
if [ "$version" == "" ]; then
8+
echo "No version set for $plugin_name"
9+
exit 1
10+
else
11+
local version_file_path=$(get_version_file_path_for $plugin_name)
12+
if [ "$version_file_path" == "" ]; then
13+
echo "$version"
14+
else
15+
echo "$version (set by $version_file_path)"
16+
fi
17+
18+
exit 0
19+
fi
20+
}

lib/commands/which.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

lib/utils.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ display_error() {
6767
echo >&2 $1
6868
}
6969

70+
get_version_file_path_for() {
71+
local tool_name=$1
72+
local legacy_version_file_support=$(get_asdf_config_value "legacy_version_file")
73+
74+
if [ ! -f "$(pwd)/.tool-versions" ] && [ "$legacy_version_file_support" = "yes" ]; then
75+
# Check for legacy version and return "" if it exists
76+
local legacy_version=$(get_tool_version_from_legacy_file $tool_name $(pwd))
77+
if [ "$legacy_version" != "" ]; then
78+
echo ""
79+
return 1
80+
fi
81+
fi
82+
83+
echo $(get_asdf_versions_file_path)
84+
}
7085

7186
get_asdf_versions_file_path() {
7287
local asdf_tool_versions_path=""

test/current_command.bats

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bats
2+
3+
load test_helpers
4+
5+
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/current.sh
6+
7+
setup() {
8+
setup_asdf_dir
9+
install_dummy_plugin
10+
11+
PROJECT_DIR=$HOME/project
12+
OTHER_DIR=$HOME/other
13+
mkdir -p $ASDF_DIR/installs/dummy/1.0.0 $ASDF_DIR/installs/dummy/1.1.0 $PROJECT_DIR $OTHER_DIR
14+
15+
echo 'dummy 1.0.0' >> $HOME/.tool-versions
16+
echo 'dummy 1.1.0' >> $PROJECT_DIR/.tool-versions
17+
echo '1.2.0' >> $OTHER_DIR/.dummy-version
18+
}
19+
20+
teardown() {
21+
clean_asdf_dir
22+
}
23+
24+
@test "current should derive from the local .tool_versions when it exists" {
25+
cd $PROJECT_DIR
26+
27+
run current_command "dummy"
28+
[ "$status" -eq 0 ]
29+
[ "$output" = "1.1.0 (set by $PROJECT_DIR/.tool-versions)" ]
30+
}
31+
32+
@test "current should derive from the global .tool_versions when local doesn't exist" {
33+
cd $OTHER_DIR
34+
35+
run current_command "dummy"
36+
[ "$status" -eq 0 ]
37+
[ "$output" = "1.0.0 (set by $HOME/.tool-versions)" ]
38+
}
39+
40+
@test "current should derive from the legacy file if enabled and hide the file path" {
41+
echo 'legacy_version_file = yes' > $HOME/.asdfrc
42+
cd $OTHER_DIR
43+
44+
run current_command "dummy"
45+
[ "$status" -eq 0 ]
46+
[ "$output" = "1.2.0" ]
47+
}
48+
49+
@test "current should error when the plugin doesn't exist" {
50+
run current_command "foobar"
51+
[ "$status" -eq 1 ]
52+
}
53+
54+
@test "current should error when no version is set" {
55+
cd $OTHER_DIR
56+
rm $HOME/.tool-versions
57+
58+
run current_command "dummy"
59+
[ "$status" -eq 1 ]
60+
[ "$output" = "No version set for dummy" ]
61+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
get_legacy_version() {
4+
current_directory=$1
5+
version_file="$current_directory/.dummy-version"
6+
7+
if [ -f $version_file ]; then
8+
cat $version_file
9+
fi
10+
}
11+
12+
get_legacy_version $1

0 commit comments

Comments
 (0)