fix: support nushell v0.75.0 (#1481)

This commit is contained in:
Edwin Kofler 2023-02-19 02:46:59 -08:00 committed by GitHub
parent fde0ce6c8e
commit dd8d3999d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 35 deletions

54
asdf.nu
View File

@ -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+?(?P<repository>git@.+\.git)', flag: '--urls'}
{name: 'refs', enabled: $refs, template: '\s+?(?P<branch>\w+)\s+(?P<ref>\w+)', flag: '--refs'}
]
let template = '(?P<name>.+)' + (
$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<name>.+)\s+?(?P<installed>[*]?)(?P<repository>(?: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 *
use asdf *

View File

@ -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" {