From 537472c1a48cf3f356b6ac4eef626be1ca1df4f3 Mon Sep 17 00:00:00 2001 From: Kevin Lane Date: Thu, 14 May 2020 07:39:19 -0700 Subject: [PATCH 01/20] Move command that returns the latest version to a utility function --- lib/commands/command-latest.bash | 7 +------ lib/utils.bash | 10 ++++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/commands/command-latest.bash b/lib/commands/command-latest.bash index 490eea962..7c2ee8fdd 100644 --- a/lib/commands/command-latest.bash +++ b/lib/commands/command-latest.bash @@ -8,12 +8,7 @@ latest_command() { [[ -z $query ]] && query="$DEFAULT_QUERY" - # pattern from xxenv-latest (https://github.com/momo-lab/xxenv-latest) - asdf list-all "$plugin_name" "$query" | - grep -vE "(^Available versions:|-src|-dev|-latest|-stm|[-\\.]rc|-alpha|-beta|[-\\.]pre|-next|(a|b|c)[0-9]+|snapshot|master)" | - sed 's/^\s\+//' | - sort --version-sort | - tail -1 + get_latest_version "$(asdf list-all $plugin_name $query)" } latest_command "$@" diff --git a/lib/utils.bash b/lib/utils.bash index 6d663df51..c6334cbb2 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -86,6 +86,16 @@ get_download_path() { fi } +get_latest_version() { + # pattern from xxenv-latest (https://github.com/momo-lab/xxenv-latest) + local versions=$1 + echo "$versions" | + grep -vE "(^Available versions:|-src|-dev|-latest|-stm|[-\.]rc|-alpha|-beta|[-\.]pre|-next|(a|b|c)[0-9]+|snapshot|master)" | + sed "s/^\s\+//" | + sort --version-sort | + tail -1 +} + list_installed_versions() { local plugin_name=$1 local plugin_path From 9c82d11a82f1565a4f22205217f206c9c6e9ef46 Mon Sep 17 00:00:00 2001 From: Kevin Lane Date: Thu, 14 May 2020 07:39:19 -0700 Subject: [PATCH 02/20] Add support for filtering installed versions with asdf list --- lib/commands/command-list.bash | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/commands/command-list.bash b/lib/commands/command-list.bash index 55e074adf..423514f49 100644 --- a/lib/commands/command-list.bash +++ b/lib/commands/command-list.bash @@ -2,6 +2,7 @@ list_command() { local plugin_name=$1 + local query=$2 if [ -z "$plugin_name" ]; then local plugins_path @@ -11,21 +12,26 @@ list_command() { for plugin_path in "$plugins_path"/*; do plugin_name=$(basename "$plugin_path") echo "$plugin_name" - display_installed_versions "$plugin_name" + display_installed_versions "$plugin_name" "$query" done else printf "%s\\n" 'Oohes nooes ~! No plugins installed' fi else check_if_plugin_exists "$plugin_name" - display_installed_versions "$plugin_name" + display_installed_versions "$plugin_name" "$query" fi } display_installed_versions() { local versions + local query=$2 versions=$(list_installed_versions "$1") + if [[ $query ]]; then + versions=$(echo "$versions" | grep -E "^\s*$query") + fi + if [ -n "${versions}" ]; then for version in $versions; do echo " $version" From e1331cd4d188db57292ce91d8c410300db5b53dc Mon Sep 17 00:00:00 2001 From: Kevin Lane Date: Thu, 14 May 2020 07:39:20 -0700 Subject: [PATCH 03/20] Add support for using the latest installed version of a tool --- lib/commands/version_commands.bash | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/commands/version_commands.bash b/lib/commands/version_commands.bash index 9d484dd56..99083a0a2 100644 --- a/lib/commands/version_commands.bash +++ b/lib/commands/version_commands.bash @@ -32,6 +32,14 @@ version_command() { check_if_plugin_exists "$plugin_name" + for i in "${!versions[@]}"; do + IFS=':' read -r -a version_info <<<"${versions[$i]}" + if [ "${version_info[0]}" = "latest" ]; then + local installed_versions=$(asdf list "$plugin" "${version_info[1]}") + versions[$i]=$(get_latest_version "$installed_versions") + fi + done + local version for version in "${versions[@]}"; do check_if_version_exists "$plugin_name" "$version" From c1bcade3a8fc921413a2c22cc9ab4b09c5fb3746 Mon Sep 17 00:00:00 2001 From: Kevin Lane Date: Thu, 14 May 2020 07:39:20 -0700 Subject: [PATCH 04/20] Add tests for new features - Filter installed versions with asdf list - Use the latest installed version of a tool --- test/list_command.bats | 9 +++++++++ test/version_commands.bats | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/test/list_command.bats b/test/list_command.bats index 83a8ec29d..0a819898d 100644 --- a/test/list_command.bats +++ b/test/list_command.bats @@ -38,6 +38,15 @@ teardown() { [ "$status" -eq 0 ] } +@test "list_command with version filters installed versions" { + run asdf install dummy 1.0 + run asdf install dummy 1.1 + run asdf install dummy 2.0 + run asdf list dummy 1 + [ "$(echo -e " 1.0\n 1.1")" == "$output" ] + [ "$status" -eq 0 ] +} + @test "list_all_command lists available versions" { run asdf list-all dummy [ "$(echo -e "1.0\n1.1\n2.0")" == "$output" ] diff --git a/test/version_commands.bats b/test/version_commands.bats index 00e21bee5..0c2b74789 100644 --- a/test/version_commands.bats +++ b/test/version_commands.bats @@ -46,6 +46,18 @@ teardown() { [ "$(cat $PROJECT_DIR/.tool-versions)" = "dummy 1.1.0" ] } +@test "local with latest should use the latest installed version" { + run asdf local "dummy" "latest" + [ "$status" -eq 0 ] + [ "$(cat $PROJECT_DIR/.tool-versions)" = "dummy 1.1.0" ] +} + +@test "local with latest:version should use the latest valid installed version" { + run asdf local "dummy" "latest:1.0" + [ "$status" -eq 0 ] + [ "$(cat $PROJECT_DIR/.tool-versions)" = "dummy 1.0.0" ] +} + @test "local should allow multiple versions" { run asdf local "dummy" "1.1.0" "1.0.0" [ "$status" -eq 0 ] @@ -140,6 +152,18 @@ teardown() { [ "$(cat $HOME/.tool-versions)" = "dummy 1.1.0" ] } +@test "global with latest should use the latest installed version" { + run asdf global "dummy" "latest" + [ "$status" -eq 0 ] + [ "$(cat $HOME/.tool-versions)" = "dummy 1.1.0" ] +} + +@test "global with latest:version should use the latest valid installed version" { + run asdf global "dummy" "latest:1.0" + [ "$status" -eq 0 ] + [ "$(cat $HOME/.tool-versions)" = "dummy 1.0.0" ] +} + @test "global should accept multiple versions" { run asdf global "dummy" "1.1.0" "1.0.0" [ "$status" -eq 0 ] From 7291d97c3a47382da33e39aefdc3bc23e35a9533 Mon Sep 17 00:00:00 2001 From: Kevin Lane Date: Thu, 14 May 2020 07:39:20 -0700 Subject: [PATCH 05/20] Update documentation with new features - Filter installed versions with asdf list - Use the latest installed version of a tool --- CHANGELOG.md | 16 ++++++++++++++++ docs/core-commands.md | 4 +++- docs/core-manage-versions.md | 11 +++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ee9fb8e9..f0b4527b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,22 @@ Fixed Bugs * Ignore shim directory for executable lookups (#623) * Fix issue with preset version warning assuming that the shim name and plugin name are the same (#622) +Features + +* Add support for using the latest installed version with `asdf global` and `asdf local` + + ```shell + asdf global python latest + asdf local python latest + asdf local python latest:3.7 # sets local Python version to latest installed version of Python 3.7 + ``` + +* Add support for filtering installed versions with `asdf list` + + ```shell + asdf list python 3.7 # lists installed versions of Python 3.7 + ``` + ## 0.7.6 Features diff --git a/docs/core-commands.md b/docs/core-commands.md index 9323ca4b2..82b03a8a9 100644 --- a/docs/core-commands.md +++ b/docs/core-commands.md @@ -25,9 +25,11 @@ | `asdf where []` | Display install path for an installed or current version | | `asdf which ` | Display install path for current version | | `asdf local ` | Set the package local version | +| `asdf local latest[:]` | Set the package local version to the latest installed version | | `asdf global ` | Set the package global version | +| `asdf global latest[:]` | Set the package global version to the latest installed version | | `asdf latest []` | Show latest stable version of a package | -| `asdf list ` | List installed versions of a package | +| `asdf list []` | List installed versions of a package and optionally filter the versions | | `asdf list all []` | List all versions of a package and optionally filter the returned versions | ## Utils diff --git a/docs/core-manage-versions.md b/docs/core-manage-versions.md index b46bdfb33..f7d8e16f5 100644 --- a/docs/core-manage-versions.md +++ b/docs/core-manage-versions.md @@ -28,6 +28,13 @@ asdf list # asdf list erlang ``` +Limit versions to those that begin with a given string. + +```shell +asdf list +# asdf list erlang 17 +``` + ## List All Available Versions ```shell @@ -62,6 +69,10 @@ asdf latest asdf global [...] asdf local [...] # asdf global elixir 1.2.4 + +asdf global latest[:] +asdf local latest[:] +# asdf global elixir latest ``` `global` writes the version to `$HOME/.tool-versions`. From 5a084b285ba02ed95fc7cc2d51eb358383239451 Mon Sep 17 00:00:00 2001 From: Kevin Lane Date: Thu, 14 May 2020 07:39:20 -0700 Subject: [PATCH 06/20] Fix shellcheck errors --- lib/commands/command-latest.bash | 2 +- lib/commands/version_commands.bash | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/commands/command-latest.bash b/lib/commands/command-latest.bash index 7c2ee8fdd..8a738f283 100644 --- a/lib/commands/command-latest.bash +++ b/lib/commands/command-latest.bash @@ -8,7 +8,7 @@ latest_command() { [[ -z $query ]] && query="$DEFAULT_QUERY" - get_latest_version "$(asdf list-all $plugin_name $query)" + get_latest_version "$(asdf list-all "$plugin_name" "$query")" } latest_command "$@" diff --git a/lib/commands/version_commands.bash b/lib/commands/version_commands.bash index 99083a0a2..451aa5ce2 100644 --- a/lib/commands/version_commands.bash +++ b/lib/commands/version_commands.bash @@ -35,7 +35,8 @@ version_command() { for i in "${!versions[@]}"; do IFS=':' read -r -a version_info <<<"${versions[$i]}" if [ "${version_info[0]}" = "latest" ]; then - local installed_versions=$(asdf list "$plugin" "${version_info[1]}") + local installed_versions + installed_versions=$(asdf list "$plugin" "${version_info[1]}") versions[$i]=$(get_latest_version "$installed_versions") fi done From ad5381114a5c933365264e8479a9901d49a30adb Mon Sep 17 00:00:00 2001 From: Kevin Lane Date: Thu, 14 May 2020 07:39:20 -0700 Subject: [PATCH 07/20] Add error messages when filtering yields no compatible versions --- lib/commands/command-latest.bash | 7 ++++++- lib/commands/command-list-all.bash | 5 +++++ lib/commands/command-list.bash | 8 +++++++- lib/commands/version_commands.bash | 5 +++++ lib/utils.bash | 11 +++++++++-- 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/lib/commands/command-latest.bash b/lib/commands/command-latest.bash index 8a738f283..4ea06f1e4 100644 --- a/lib/commands/command-latest.bash +++ b/lib/commands/command-latest.bash @@ -8,7 +8,12 @@ latest_command() { [[ -z $query ]] && query="$DEFAULT_QUERY" - get_latest_version "$(asdf list-all "$plugin_name" "$query")" + local versions + versions=$(asdf list-all "$plugin_name" "$query") + + if [ -n "${versions}" ]; then + get_latest_version "$versions" + fi } latest_command "$@" diff --git a/lib/commands/command-list-all.bash b/lib/commands/command-list-all.bash index ccfcd901c..90a81e331 100644 --- a/lib/commands/command-list-all.bash +++ b/lib/commands/command-list-all.bash @@ -17,6 +17,11 @@ list_all_command() { tr '\n' ' ') fi + if [ -z "$versions" ]; then + display_error "No compatible versions available" + exit 1 + fi + IFS=' ' read -r -a versions_list <<<"$versions" for version in "${versions_list[@]}"; do diff --git a/lib/commands/command-list.bash b/lib/commands/command-list.bash index 423514f49..f81338439 100644 --- a/lib/commands/command-list.bash +++ b/lib/commands/command-list.bash @@ -28,6 +28,11 @@ display_installed_versions() { local query=$2 versions=$(list_installed_versions "$1") + if [ -z "${versions}" ]; then + display_error 'No versions installed' + exit 1 + fi + if [[ $query ]]; then versions=$(echo "$versions" | grep -E "^\s*$query") fi @@ -37,7 +42,8 @@ display_installed_versions() { echo " $version" done else - display_error 'No versions installed' + display_error 'No compatible versions installed' + exit 1 fi } diff --git a/lib/commands/version_commands.bash b/lib/commands/version_commands.bash index 451aa5ce2..d7bf0101c 100644 --- a/lib/commands/version_commands.bash +++ b/lib/commands/version_commands.bash @@ -37,6 +37,11 @@ version_command() { if [ "${version_info[0]}" = "latest" ]; then local installed_versions installed_versions=$(asdf list "$plugin" "${version_info[1]}") + + if [ -z "$installed_versions" ]; then + exit 1 + fi + versions[$i]=$(get_latest_version "$installed_versions") fi done diff --git a/lib/utils.bash b/lib/utils.bash index c6334cbb2..f16ed536f 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -89,11 +89,18 @@ get_download_path() { get_latest_version() { # pattern from xxenv-latest (https://github.com/momo-lab/xxenv-latest) local versions=$1 - echo "$versions" | + versions=$(echo "$versions" | grep -vE "(^Available versions:|-src|-dev|-latest|-stm|[-\.]rc|-alpha|-beta|[-\.]pre|-next|(a|b|c)[0-9]+|snapshot|master)" | sed "s/^\s\+//" | sort --version-sort | - tail -1 + tail -1) + + if [ -z "$versions" ]; then + display_error "No compatible versions available" + exit 1 + fi + + echo "$versions" } list_installed_versions() { From 8f5fb89d63a1b749d4416123da8ad1a947f714f8 Mon Sep 17 00:00:00 2001 From: Kevin Lane Date: Thu, 14 May 2020 07:39:20 -0700 Subject: [PATCH 08/20] Remove unnecessary echo flags --- test/latest_command.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/latest_command.bats b/test/latest_command.bats index 90e2a286c..76fdc1f8b 100644 --- a/test/latest_command.bats +++ b/test/latest_command.bats @@ -13,12 +13,12 @@ teardown() { @test "latest_command shows latest stable version" { run asdf latest dummy - [ "$(echo -e "2.0")" == "$output" ] + [ "$(echo "2.0")" == "$output" ] [ "$status" -eq 0 ] } @test "latest_command with version shows latest stable version that matches the given string" { run asdf latest dummy 1 - [ "$(echo -e "1.1")" == "$output" ] + [ "$(echo "1.1")" == "$output" ] [ "$status" -eq 0 ] } From 23575a2313377c46cd48f45ef1f5b5a6ef992bd9 Mon Sep 17 00:00:00 2001 From: Kevin Lane Date: Thu, 14 May 2020 07:39:21 -0700 Subject: [PATCH 09/20] Rearrange asdf list error messages to retain original behavior --- lib/commands/command-list.bash | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/commands/command-list.bash b/lib/commands/command-list.bash index f81338439..e08eff27d 100644 --- a/lib/commands/command-list.bash +++ b/lib/commands/command-list.bash @@ -24,17 +24,18 @@ list_command() { } display_installed_versions() { - local versions + local plugin_name=$1 local query=$2 - versions=$(list_installed_versions "$1") - - if [ -z "${versions}" ]; then - display_error 'No versions installed' - exit 1 - fi + local versions + versions=$(list_installed_versions "$plugin_name") if [[ $query ]]; then versions=$(echo "$versions" | grep -E "^\s*$query") + + if [ -z "${versions}" ]; then + display_error "No compatible versions installed ($plugin_name $query)" + exit 1 + fi fi if [ -n "${versions}" ]; then @@ -42,8 +43,7 @@ display_installed_versions() { echo " $version" done else - display_error 'No compatible versions installed' - exit 1 + display_error 'No versions installed' fi } From 163aca78a1b292c75f7c9e6867b6f437c9acce88 Mon Sep 17 00:00:00 2001 From: Kevin Lane Date: Thu, 14 May 2020 07:39:21 -0700 Subject: [PATCH 10/20] Improve version filtering error messages and exit codes --- lib/commands/command-latest.bash | 2 ++ lib/commands/command-list-all.bash | 2 +- lib/utils.bash | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/commands/command-latest.bash b/lib/commands/command-latest.bash index 4ea06f1e4..12e20a1fb 100644 --- a/lib/commands/command-latest.bash +++ b/lib/commands/command-latest.bash @@ -13,6 +13,8 @@ latest_command() { if [ -n "${versions}" ]; then get_latest_version "$versions" + else + exit 1 fi } diff --git a/lib/commands/command-list-all.bash b/lib/commands/command-list-all.bash index 90a81e331..afc752575 100644 --- a/lib/commands/command-list-all.bash +++ b/lib/commands/command-list-all.bash @@ -18,7 +18,7 @@ list_all_command() { fi if [ -z "$versions" ]; then - display_error "No compatible versions available" + display_error "No compatible versions available ($plugin_name $query)" exit 1 fi diff --git a/lib/utils.bash b/lib/utils.bash index f16ed536f..714b68355 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -96,7 +96,7 @@ get_latest_version() { tail -1) if [ -z "$versions" ]; then - display_error "No compatible versions available" + display_error "No compatible stable versions available" exit 1 fi From 1bb167d7122c8a9ffbce8bbac973839c4d843886 Mon Sep 17 00:00:00 2001 From: Kevin Lane Date: Thu, 14 May 2020 07:39:21 -0700 Subject: [PATCH 11/20] Add tests for version filtering error messages --- test/latest_command.bats | 6 ++++++ test/list_command.bats | 14 ++++++++++++++ test/version_commands.bats | 12 ++++++++++++ 3 files changed, 32 insertions(+) diff --git a/test/latest_command.bats b/test/latest_command.bats index 76fdc1f8b..936ef0489 100644 --- a/test/latest_command.bats +++ b/test/latest_command.bats @@ -22,3 +22,9 @@ teardown() { [ "$(echo "1.1")" == "$output" ] [ "$status" -eq 0 ] } + +@test "latest_command with an invalid version should return an error" { + run asdf latest dummy 3 + [ "$(echo "No compatible versions available (dummy 3)")" == "$output" ] + [ "$status" -eq 1 ] +} diff --git a/test/list_command.bats b/test/list_command.bats index 0a819898d..be9eccedd 100644 --- a/test/list_command.bats +++ b/test/list_command.bats @@ -47,6 +47,14 @@ teardown() { [ "$status" -eq 0 ] } +@test "list_command with an invalid version should return an error" { + run asdf install dummy 1.0 + run asdf install dummy 1.1 + run asdf list dummy 2 + [ "$(echo "No compatible versions installed (dummy 2)")" == "$output" ] + [ "$status" -eq 1 ] +} + @test "list_all_command lists available versions" { run asdf list-all dummy [ "$(echo -e "1.0\n1.1\n2.0")" == "$output" ] @@ -58,3 +66,9 @@ teardown() { [ "$(echo -e "1.0\n1.1")" == "$output" ] [ "$status" -eq 0 ] } + +@test "list_all_command with an invalid version should return an error" { + run asdf list-all dummy 3 + [ "$(echo "No compatible versions available (dummy 3)")" == "$output" ] + [ "$status" -eq 1 ] +} diff --git a/test/version_commands.bats b/test/version_commands.bats index 0c2b74789..30db6738b 100644 --- a/test/version_commands.bats +++ b/test/version_commands.bats @@ -58,6 +58,12 @@ teardown() { [ "$(cat $PROJECT_DIR/.tool-versions)" = "dummy 1.0.0" ] } +@test "local with latest:version should return an error for invalid versions" { + run asdf local "dummy" "latest:2" + [ "$status" -eq 1 ] + [ "$output" = "$(echo "No compatible versions installed (dummy 2)")" ] +} + @test "local should allow multiple versions" { run asdf local "dummy" "1.1.0" "1.0.0" [ "$status" -eq 0 ] @@ -164,6 +170,12 @@ teardown() { [ "$(cat $HOME/.tool-versions)" = "dummy 1.0.0" ] } +@test "global with latest:version should return an error for invalid versions" { + run asdf global "dummy" "latest:2" + [ "$status" -eq 1 ] + [ "$output" = "$(echo "No compatible versions installed (dummy 2)")" ] +} + @test "global should accept multiple versions" { run asdf global "dummy" "1.1.0" "1.0.0" [ "$status" -eq 0 ] From be68403f56bd179b697922b80cd72d5b7121e46a Mon Sep 17 00:00:00 2001 From: Kevin Lane Date: Thu, 14 May 2020 07:39:21 -0700 Subject: [PATCH 12/20] Rename variable to account for previous name change --- lib/commands/version_commands.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commands/version_commands.bash b/lib/commands/version_commands.bash index d7bf0101c..f5e6d37ac 100644 --- a/lib/commands/version_commands.bash +++ b/lib/commands/version_commands.bash @@ -36,7 +36,7 @@ version_command() { IFS=':' read -r -a version_info <<<"${versions[$i]}" if [ "${version_info[0]}" = "latest" ]; then local installed_versions - installed_versions=$(asdf list "$plugin" "${version_info[1]}") + installed_versions=$(asdf list "$plugin_name" "${version_info[1]}") if [ -z "$installed_versions" ]; then exit 1 From b787fe8520ae1e84f512a7b4c7c81d7867d4079d Mon Sep 17 00:00:00 2001 From: Kevin Lane Date: Thu, 14 May 2020 07:39:21 -0700 Subject: [PATCH 13/20] Move changes to latest version in CHANGELOG --- CHANGELOG.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0b4527b5..becefd222 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,22 @@ ## 0.7.9-dev +Features + +* Add support for using the latest installed version with `asdf global` and `asdf local` + + ```shell + asdf global python latest + asdf local python latest + asdf local python latest:3.7 # sets local Python version to latest installed version of Python 3.7 + ``` + +* Add support for filtering installed versions with `asdf list` + + ```shell + asdf list python 3.7 # lists installed versions of Python 3.7 + ``` + ## 0.7.8 Features @@ -51,22 +67,6 @@ Fixed Bugs * Ignore shim directory for executable lookups (#623) * Fix issue with preset version warning assuming that the shim name and plugin name are the same (#622) -Features - -* Add support for using the latest installed version with `asdf global` and `asdf local` - - ```shell - asdf global python latest - asdf local python latest - asdf local python latest:3.7 # sets local Python version to latest installed version of Python 3.7 - ``` - -* Add support for filtering installed versions with `asdf list` - - ```shell - asdf list python 3.7 # lists installed versions of Python 3.7 - ``` - ## 0.7.6 Features From 00bcb8bb20ded9715606614032993e02a127b366 Mon Sep 17 00:00:00 2001 From: Kevin Lane Date: Thu, 14 May 2020 07:39:21 -0700 Subject: [PATCH 14/20] Replace sed with awk to get the latest version of a tool Fixes failing CI tests on macOS Co-authored-by: Thomas B Homburg --- lib/utils.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils.bash b/lib/utils.bash index 714b68355..af0375c52 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -91,7 +91,7 @@ get_latest_version() { local versions=$1 versions=$(echo "$versions" | grep -vE "(^Available versions:|-src|-dev|-latest|-stm|[-\.]rc|-alpha|-beta|[-\.]pre|-next|(a|b|c)[0-9]+|snapshot|master)" | - sed "s/^\s\+//" | + awk '{ print $1 }' | sort --version-sort | tail -1) From c7272f091e1fb3b10ad10aea2b514a1b395cdde6 Mon Sep 17 00:00:00 2001 From: jthegedus Date: Tue, 6 Jul 2021 17:03:40 +1000 Subject: [PATCH 15/20] chore: rm changelog changes --- CHANGELOG.md | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4f6b1b57..8f1cddadb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,22 +77,6 @@ Fixed Bugs * Add CODEOWNERS file for GitHub reviews (#705) * Add unit test for `asdf plugin-add` exit code (#689) -Features - -* Add support for using the latest installed version with `asdf global` and `asdf local` - - ```shell - asdf global python latest - asdf local python latest - asdf local python latest:3.7 # sets local Python version to latest installed version of Python 3.7 - ``` - -* Add support for filtering installed versions with `asdf list` - - ```shell - asdf list python 3.7 # lists installed versions of Python 3.7 - ``` - ## 0.7.8 Features From 73f9c58bd679d8996aac0460869e48900287a598 Mon Sep 17 00:00:00 2001 From: jthegedus Date: Tue, 6 Jul 2021 17:11:45 +1000 Subject: [PATCH 16/20] chore: replace echo with printf --- lib/commands/command-list.bash | 4 ++-- lib/utils.bash | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/commands/command-list.bash b/lib/commands/command-list.bash index e66562cad..b0cbd1610 100644 --- a/lib/commands/command-list.bash +++ b/lib/commands/command-list.bash @@ -11,7 +11,7 @@ list_command() { if ls "$plugins_path" &>/dev/null; then for plugin_path in "$plugins_path"/*; do plugin_name=$(basename "$plugin_path") - echo "$plugin_name" + printf "%s\\n" "$plugin_name" display_installed_versions "$plugin_name" "$query" done else @@ -30,7 +30,7 @@ display_installed_versions() { versions=$(list_installed_versions "$plugin_name") if [[ $query ]]; then - versions=$(echo "$versions" | grep -E "^\s*$query") + versions=$(printf "%s\n" "$versions" | grep -E "^\s*$query") if [ -z "${versions}" ]; then display_error "No compatible versions installed ($plugin_name $query)" diff --git a/lib/utils.bash b/lib/utils.bash index 40dc68201..2e31462ee 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -89,7 +89,7 @@ get_download_path() { get_latest_version() { # pattern from xxenv-latest (https://github.com/momo-lab/xxenv-latest) local versions=$1 - versions=$(echo "$versions" | + versions=$(printf "%s\n" "$versions" | grep -vE "(^Available versions:|-src|-dev|-latest|-stm|[-\.]rc|-alpha|-beta|[-\.]pre|-next|(a|b|c)[0-9]+|snapshot|master)" | awk '{ print $1 }' | sort --version-sort | @@ -100,7 +100,7 @@ get_latest_version() { exit 1 fi - echo "$versions" + printf "%s\n" "$versions" } list_installed_versions() { From 5c4cda637f975e549d7505d6952bfed5bcfdc1bc Mon Sep 17 00:00:00 2001 From: jthegedus Date: Tue, 6 Jul 2021 17:22:24 +1000 Subject: [PATCH 17/20] fix: error when latest cmd with invlid version --- lib/commands/command-list-all.bash | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/commands/command-list-all.bash b/lib/commands/command-list-all.bash index d16602972..e3e23d185 100644 --- a/lib/commands/command-list-all.bash +++ b/lib/commands/command-list-all.bash @@ -32,6 +32,11 @@ list_all_command() { output=$(cat "$std_out_file") fi + if [ -z "$output" ]; then + display_error "No compatible versions available ($plugin_name $query)" + exit 1 + fi + IFS=' ' read -r -a versions_list <<<"$output" for version in "${versions_list[@]}"; do From 675411584f94e69811d235c04410edaffdb0409b Mon Sep 17 00:00:00 2001 From: jthegedus Date: Tue, 6 Jul 2021 18:11:00 +1000 Subject: [PATCH 18/20] chore: revert command-latest --- lib/commands/command-latest.bash | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/commands/command-latest.bash b/lib/commands/command-latest.bash index 12e20a1fb..c73f9f350 100644 --- a/lib/commands/command-latest.bash +++ b/lib/commands/command-latest.bash @@ -8,14 +8,11 @@ latest_command() { [[ -z $query ]] && query="$DEFAULT_QUERY" - local versions - versions=$(asdf list-all "$plugin_name" "$query") - - if [ -n "${versions}" ]; then - get_latest_version "$versions" - else - exit 1 - fi + # pattern from xxenv-latest (https://github.com/momo-lab/xxenv-latest) + asdf list-all "$plugin_name" "$query" | + grep -vE "(^Available versions:|-src|-dev|-latest|-stm|[-\\.]rc|-alpha|-beta|[-\\.]pre|-next|(a|b|c)[0-9]+|snapshot|master)" | + sed 's/^\s\+//' | + tail -1 } latest_command "$@" From 4e849c752d3669981cfcffe578d9f5e47ae5b29c Mon Sep 17 00:00:00 2001 From: jthegedus Date: Tue, 6 Jul 2021 18:11:45 +1000 Subject: [PATCH 19/20] chore: revert command-latest --- lib/utils.bash | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/lib/utils.bash b/lib/utils.bash index 2e31462ee..8b2f1ad32 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -86,23 +86,6 @@ get_download_path() { fi } -get_latest_version() { - # pattern from xxenv-latest (https://github.com/momo-lab/xxenv-latest) - local versions=$1 - versions=$(printf "%s\n" "$versions" | - grep -vE "(^Available versions:|-src|-dev|-latest|-stm|[-\.]rc|-alpha|-beta|[-\.]pre|-next|(a|b|c)[0-9]+|snapshot|master)" | - awk '{ print $1 }' | - sort --version-sort | - tail -1) - - if [ -z "$versions" ]; then - display_error "No compatible stable versions available" - exit 1 - fi - - printf "%s\n" "$versions" -} - list_installed_versions() { local plugin_name=$1 local plugin_path From 495b1d0bf5735f96892cbe8d43c31f81e41fdf7c Mon Sep 17 00:00:00 2001 From: jthegedus Date: Tue, 6 Jul 2021 21:09:51 +1000 Subject: [PATCH 20/20] fix: local & global with latest and filters --- lib/commands/command-latest.bash | 11 +++++++++-- lib/commands/version_commands.bash | 19 ++++++++++++++++--- test/version_commands.bats | 13 +++++++------ 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/lib/commands/command-latest.bash b/lib/commands/command-latest.bash index c73f9f350..efcac8fe0 100644 --- a/lib/commands/command-latest.bash +++ b/lib/commands/command-latest.bash @@ -8,11 +8,18 @@ latest_command() { [[ -z $query ]] && query="$DEFAULT_QUERY" + local versions # pattern from xxenv-latest (https://github.com/momo-lab/xxenv-latest) - asdf list-all "$plugin_name" "$query" | + versions=$(asdf list-all "$plugin_name" "$query" | grep -vE "(^Available versions:|-src|-dev|-latest|-stm|[-\\.]rc|-alpha|-beta|[-\\.]pre|-next|(a|b|c)[0-9]+|snapshot|master)" | sed 's/^\s\+//' | - tail -1 + tail -1) + + if [ -z "${versions}" ]; then + exit 1 + fi + + printf "%s\n" "$versions" } latest_command "$@" diff --git a/lib/commands/version_commands.bash b/lib/commands/version_commands.bash index 7b5564e06..a80eff1a7 100644 --- a/lib/commands/version_commands.bash +++ b/lib/commands/version_commands.bash @@ -33,15 +33,28 @@ version_command() { check_if_plugin_exists "$plugin_name" declare -a resolved_versions - local version - for version in "${versions[@]}"; do - if [ "$version" = "latest" ]; then + local item + for item in "${!versions[@]}"; do + IFS=':' read -r -a version_info <<<"${versions[$item]}" + if [ "${version_info[0]}" = "latest" ] && [ -n "${version_info[1]}" ]; then + version=$(asdf latest "$plugin_name" "${version_info[1]}") + elif [ "${version_info[0]}" = "latest" ] && [ -z "${version_info[1]}" ]; then version=$(asdf latest "$plugin_name") + else + # if branch handles ref: || path: || normal versions + version="${versions[$item]}" + fi + + # check_if_version_exists should probably handle if either param is empty string + if [ -z "$version" ]; then + exit 1 fi + if ! (check_if_version_exists "$plugin_name" "$version"); then version_not_installed_text "$plugin_name" "$version" 1>&2 exit 1 fi + resolved_versions+=("$version") done diff --git a/test/version_commands.bats b/test/version_commands.bats index 90902704a..097734a09 100644 --- a/test/version_commands.bats +++ b/test/version_commands.bats @@ -50,7 +50,7 @@ teardown() { @test "local with latest should use the latest installed version" { run asdf local "dummy" "latest" [ "$status" -eq 0 ] - [ "$(cat $PROJECT_DIR/.tool-versions)" = "dummy 1.1.0" ] + [ "$(cat $PROJECT_DIR/.tool-versions)" = "dummy 2.0.0" ] } @test "local with latest:version should use the latest valid installed version" { @@ -60,9 +60,9 @@ teardown() { } @test "local with latest:version should return an error for invalid versions" { - run asdf local "dummy" "latest:2" + run asdf local "dummy" "latest:99" [ "$status" -eq 1 ] - [ "$output" = "$(echo "No compatible versions installed (dummy 2)")" ] + [ "$output" = "$(echo "No compatible versions available (dummy 99)")" ] } @test "local should allow multiple versions" { @@ -93,6 +93,7 @@ teardown() { @test "local should overwrite the existing version if it's set" { echo 'dummy 1.0.0' >> $PROJECT_DIR/.tool-versions + run asdf local "dummy" "1.1.0" [ "$status" -eq 0 ] [ "$(cat $PROJECT_DIR/.tool-versions)" = "dummy 1.1.0" ] @@ -162,7 +163,7 @@ teardown() { @test "global with latest should use the latest installed version" { run asdf global "dummy" "latest" [ "$status" -eq 0 ] - [ "$(cat $HOME/.tool-versions)" = "dummy 1.1.0" ] + [ "$(cat $HOME/.tool-versions)" = "dummy 2.0.0" ] } @test "global with latest:version should use the latest valid installed version" { @@ -172,9 +173,9 @@ teardown() { } @test "global with latest:version should return an error for invalid versions" { - run asdf global "dummy" "latest:2" + run asdf global "dummy" "latest:99" [ "$status" -eq 1 ] - [ "$output" = "$(echo "No compatible versions installed (dummy 2)")" ] + [ "$output" = "$(echo "No compatible versions available (dummy 99)")" ] } @test "global should accept multiple versions" {