From bbbdf04058db12698857950a4c8238e4f936a444 Mon Sep 17 00:00:00 2001 From: Jeff Edwards Date: Mon, 27 Sep 2021 12:03:49 -0700 Subject: [PATCH 1/2] 'asdf current --as-tool-versions' outputs a format suitable for a .tool-versions specification based on current setup --- lib/commands/command-current.bash | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/commands/command-current.bash b/lib/commands/command-current.bash index 4dc60411c..af9409eb2 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 From 479f6ce2b5460e1c503d7b2ef3634a6288d563a8 Mon Sep 17 00:00:00 2001 From: Jeff Edwards Date: Mon, 27 Sep 2021 12:39:41 -0700 Subject: [PATCH 2/2] Add test and format for new current --as-tool-versions option --- lib/commands/command-current.bash | 8 ++++---- test/current_command.bats | 33 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/lib/commands/command-current.bash b/lib/commands/command-current.bash index af9409eb2..fe3517498 100644 --- a/lib/commands/command-current.bash +++ b/lib/commands/command-current.bash @@ -32,10 +32,10 @@ plugin_current_command() { printf "$terminal_format" "$plugin" "$version" "$description" 1>&2 return 1 elif [ -z "$full_version" ]; then - if [ "$tool_versions" == "false" ]; 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" 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" ] +}