Skip to content

Commit

Permalink
fix Nushell tests for 0.75.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperupcall committed Feb 19, 2023
1 parent fde0ce6 commit 681d6e8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 35 deletions.
54 changes: 27 additions & 27 deletions asdf.nu
Original file line number Diff line number Diff line change
@@ -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' )
Expand All @@ -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",
Expand Down Expand Up @@ -63,7 +63,7 @@ module asdf {
}

# ASDF version manager
export extern "asdf" [
export extern main [
subcommand?: string@"complete asdf sub-commands"
]

Expand All @@ -82,45 +82,45 @@ 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
export def "asdf plugin list all" [] {
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
]

# Remove an installed plugin and their package versions
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
Expand Down Expand Up @@ -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" []
Expand Down Expand Up @@ -240,4 +240,4 @@ module asdf {

}

use asdf *
use asdf *
11 changes: 3 additions & 8 deletions test/asdf_nu.bats
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ cleaned_path() {
echo \$env.ASDF_DIR"

[ "$status" -eq 0 ]

result=$(echo "$output" | grep "asdf")
[ "$result" = "$PWD" ]
}
Expand All @@ -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" {
Expand Down Expand Up @@ -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
Expand All @@ -97,7 +93,6 @@ cleaned_path() {
which asdf | get path | to text"

[ "$status" -eq 0 ]
[[ "$output" =~ "command" ]]
}

@test "function calls asdf command" {
Expand Down

0 comments on commit 681d6e8

Please sign in to comment.