diff --git a/lib/commands/command-current.bash b/lib/commands/command-current.bash index 4dc60411c..fe3517498 100644 --- a/lib/commands/command-current.bash +++ b/lib/commands/command-current.bash @@ -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" @@ -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 $plugin \"" - printf "$terminal_format" "$plugin" "______" "$description" 1>&2 - return 126 + if [ "$tool_versions" == "false" ]; then + description="No version set. Run \"asdf $plugin \"" + printf "$terminal_format" "$plugin" "______" "$description" 1>&2 + return 126 + fi else description="$version_file_path" printf "$terminal_format" "$plugin" "$full_version" "$description" @@ -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 diff --git a/test/current_command.bats b/test/current_command.bats index 2d1e64da5..03dc65d94 100755 --- a/test/current_command.bats +++ b/test/current_command.bats @@ -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" ] +}