From dd8d3999d41cfdd8518a9ea478929b5291b8838c Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Sun, 19 Feb 2023 02:46:59 -0800 Subject: [PATCH] fix: support nushell v0.75.0 (#1481) --- asdf.nu | 54 +++++++++++++++++++++++------------------------ test/asdf_nu.bats | 11 +++------- 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/asdf.nu b/asdf.nu index 3f07d242..b6f3e680 100644 --- a/asdf.nu +++ b/asdf.nu @@ -1,7 +1,7 @@ def-env configure-asdf [] { let-env ASDF_DIR = ( if ( $env | get --ignore-errors ASDF_DIR | is-empty ) { $env.ASDF_NU_DIR } else { $env.ASDF_DIR } ) - + let shims_dir = ( if ( $env | get --ignore-errors ASDF_DATA_DIR | is-empty ) { $env.HOME | path join '.asdf' } else { $env.ASDF_DIR } | path join 'shims' ) let asdf_bin_dir = ( $env.ASDF_DIR | path join 'bin' ) @@ -17,19 +17,19 @@ configure-asdf ## Completions module asdf { - + def "complete asdf sub-commands" [] { [ - "plugin", - "list", - "install", - "uninstall", - "current", - "where", - "which", - "local", - "global", - "shell", + "plugin", + "list", + "install", + "uninstall", + "current", + "where", + "which", + "local", + "global", + "shell", "latest", "help", "exec", @@ -63,7 +63,7 @@ module asdf { } # ASDF version manager - export extern "asdf" [ + export extern main [ subcommand?: string@"complete asdf sub-commands" ] @@ -82,19 +82,19 @@ module asdf { {name: 'urls', enabled: $urls, template: '\s+?(?Pgit@.+\.git)', flag: '--urls'} {name: 'refs', enabled: $refs, template: '\s+?(?P\w+)\s+(?P\w+)', flag: '--refs'} ] - + let template = '(?P.+)' + ( - $params | + $params | where enabled | get --ignore-errors template | - str join '' | + str join '' | str trim ) let parsed_urls_flag = ($params | where enabled and name == 'urls' | get --ignore-errors flag | default '' ) let parsed_refs_flag = ($params | where enabled and name == 'refs' | get --ignore-errors flag | default '' ) - - ^asdf plugin list $parsed_urls_flag $parsed_refs_flag | lines | parse -r $template | str trim + + ^asdf plugin list $parsed_urls_flag $parsed_refs_flag | lines | parse -r $template | str trim } # list all available plugins @@ -102,17 +102,17 @@ module asdf { let template = '(?P.+)\s+?(?P[*]?)(?P(?:git|http).+\.git)' let is_installed = { |it| $it.installed == '*' } - ^asdf plugin list all | - lines | - parse -r $template | - str trim | + ^asdf plugin list all | + lines | + parse -r $template | + str trim | update installed $is_installed | sort-by name } # Add a plugin export extern "asdf plugin add" [ - name: string # Name of the plugin + name: string # Name of the plugin git_url?: string # Git url of the plugin ] @@ -120,7 +120,7 @@ module asdf { export extern "asdf plugin remove" [ name: string@"complete asdf installed plugins" # Name of the plugin ] - + # Update a plugin export extern "asdf plugin update" [ name: string@"complete asdf installed plugins" # Name of the plugin @@ -175,13 +175,13 @@ module asdf { export extern "asdf shell" [ name: string@"complete asdf installed" # Name of the package version?: string # Version of the package or latest - ] + ] # Show latest stable version of a package export extern "asdf latest" [ name: string # Name of the package version?: string # Filter latest stable version from this version - ] + ] # Show latest stable version for all installed packages export extern "asdf latest --all" [] @@ -240,4 +240,4 @@ module asdf { } -use asdf * \ No newline at end of file +use asdf * diff --git a/test/asdf_nu.bats b/test/asdf_nu.bats index 1ec2f56d..9319e7ea 100644 --- a/test/asdf_nu.bats +++ b/test/asdf_nu.bats @@ -27,7 +27,6 @@ cleaned_path() { echo \$env.ASDF_DIR" [ "$status" -eq 0 ] - result=$(echo "$output" | grep "asdf") [ "$result" = "$PWD" ] } @@ -46,11 +45,8 @@ cleaned_path() { [ "$status" -eq 0 ] - output_bin=$(echo "$output" | grep "asdf/bin") - [ "$output_bin" = "$PWD/bin" ] - - output_shims=$(echo "$output" | grep "/shims") - [ "$output_shims" = "$HOME/.asdf/shims" ] + [[ "$output" == *"$PWD/bin"* ]] + [[ "$output" == *"$HOME/.asdf/shims"* ]] } @test "does not add paths to PATH more than once" { @@ -86,7 +82,7 @@ cleaned_path() { [ "$output" = "$PWD" ] } -@test "defines the asdf function" { +@test "defines the asdf or main function" { run nu -c " hide-env -i asdf hide-env -i ASDF_DIR @@ -97,7 +93,6 @@ cleaned_path() { which asdf | get path | to text" [ "$status" -eq 0 ] - [[ "$output" =~ "command" ]] } @test "function calls asdf command" {