Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'asdf current --as-tool-versions' outputs a format suitable for export to .tool-versions #1058

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions lib/commands/command-current.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
plugin_current_command() {
local plugin_name=$1
local terminal_format=$2
local tool_versions=$3

check_if_plugin_exists "$plugin_name"

Expand Down Expand Up @@ -31,9 +32,11 @@ plugin_current_command() {
printf "$terminal_format" "$plugin" "$version" "$description" 1>&2
return 1
elif [ -z "$full_version" ]; then
description="No version set. Run \"asdf <global|shell|local> $plugin <version>\""
printf "$terminal_format" "$plugin" "______" "$description" 1>&2
return 126
if [ "$tool_versions" == "false" ]; then
description="No version set. Run \"asdf <global|shell|local> $plugin <version>\""
printf "$terminal_format" "$plugin" "______" "$description" 1>&2
return 126
fi
else
description="$version_file_path"
printf "$terminal_format" "$plugin" "$full_version" "$description"
Expand All @@ -44,15 +47,29 @@ plugin_current_command() {
current_command() {
local terminal_format="%-15s %-15s %-10s\\n"
local exit_status=0
local plugin=""
local tool_versions=false
while [ -n "$*" ]; do
case "$1" in
"--as-tool-versions")
tool_versions=true
terminal_format="%s %s%.0s\\n"
shift
;;
*)
plugin="$1"
shift
;;
esac
done

# printf "$terminal_format" "PLUGIN" "VERSION" "SET BY CONFIG" # disbale this until we release headings across the board
if [ $# -eq 0 ]; then
if [ -z "$plugin" ]; then
for plugin in $(asdf plugin list); do
plugin_current_command "$plugin" "$terminal_format"
plugin_current_command "$plugin" "$terminal_format" "$tool_versions"
done
else
local plugin=$1
plugin_current_command "$plugin" "$terminal_format"
plugin_current_command "$plugin" "$terminal_format" "$tool_versions"
exit_status="$?"
fi

Expand Down
33 changes: 33 additions & 0 deletions test/current_command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,36 @@ foobar 1.0.0 $PROJECT_DIR/.tool-versions"
[ "$status" -eq 0 ]
[ "$output" = "$expected" ]
}

@test "should be able to output the equivalent of a .tool-versions" {
install_dummy_plugin
install_dummy_version "1.1.0"

install_mock_plugin "y"
install_mock_plugin_version "y" "2.1.0"

cd $PROJECT_DIR
echo 'dummy 1.1.0' >> $PROJECT_DIR/.tool-versions
echo 'y 2.1.0' >> $PROJECT_DIR/.tool-versions

run asdf current --as-tool-versions
[ "$status" -eq 0 ]
echo "$output" | grep '^dummy 1.1.0$'
echo "$output" | grep '^y 2.1.0$'
}

@test "should be able to output the equivalent of a .tool-versions for a single tool" {
install_dummy_plugin
install_dummy_version "1.1.0"

install_mock_plugin "y"
install_mock_plugin_version "y" "2.1.0"

cd $PROJECT_DIR
echo 'dummy 1.1.0' >> $PROJECT_DIR/.tool-versions
echo 'y 2.1.0' >> $PROJECT_DIR/.tool-versions

run asdf current --as-tool-versions y
[ "$status" -eq 0 ]
[ "$output" = "y 2.1.0" ]
}