Skip to content

Commit

Permalink
feat: improved completions for version in commands
Browse files Browse the repository at this point in the history
Improved completions for commands such as `asdf global <name> <version>` to list the installed versions

Added "complete asdf plugin versions installed" and "complete asdf plugin versions all" that produce completions for the installed versions and for all versions available for a given plugin

Improved `asdf install` completion to list the installed plugins and all the available versions
  • Loading branch information
OJarrisonn committed Jun 1, 2024
1 parent ccdd47d commit 82be580
Showing 1 changed file with 37 additions and 13 deletions.
50 changes: 37 additions & 13 deletions asdf.nu
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,30 @@ module asdf {
}
}

def "complete asdf plugin versions all" [context: string] {
let plugin = $context | str trim | split words | last
^asdf list all $plugin
| lines
| each { |line| $line | str trim }
| prepend "latest"
}

def "complete asdf plugin versions installed" [context: string] {
let plugin = $context | str trim | split words | last
let versions = ^asdf list $plugin
| lines
| each { |line| $line | str trim }
| each { |version| if ($version | str starts-with "*") {{value: ($version | str substring 1..), description: "current global"}} else {{value: $version, description: ""}} }

let latest = ^asdf latest $plugin | str trim

if ($versions | get value | any {|el| $el == $latest}) {
$versions | prepend {value: "latest", description: $"alias to ($latest)"}
} else {
$versions
}
}

# ASDF version manager
export extern main [
subcommand?: string@"complete asdf sub-commands"
Expand Down Expand Up @@ -145,15 +169,15 @@ module asdf {

# install a package version
export extern "asdf install" [
name?: string # Name of the package
version?: string # Version of the package or latest
name?: string@"complete asdf installed plugins" # Name of the package
version?: string@"complete asdf plugin versions all" # Version of the package or latest
]


# Remove an installed package version
export extern "asdf uninstall" [
name: string@"complete asdf installed" # Name of the package
version: string # Version of the package
version: string@"complete asdf plugin versions installed" # Version of the package
]

# Display current version
Expand All @@ -169,31 +193,31 @@ module asdf {
# Display install path for an installled package version
export extern "asdf where" [
name: string@"complete asdf installed" # Name of installed package
version?: string # Version of installed package
version?: string@"complete asdf plugin versions installed" # Version of installed package
]

# Set the package local version
export extern "asdf local" [
name: string@"complete asdf installed" # Name of the package
version?: string # Version of the package or latest
version?: string@"complete asdf plugin versions installed" # Version of the package or latest
]

# Set the package global version
export extern "asdf global" [
name: string@"complete asdf installed" # Name of the package
version?: string # Version of the package or latest
version?: string@"complete asdf plugin versions installed" # Version of the package or latest
]

# Set the package to version in the current shell
export extern "asdf shell" [
name: string@"complete asdf installed" # Name of the package
version?: string # Version of the package or latest
version?: string@"complete asdf plugin versions installed" # 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
name: string@"complete asdf installed" # Name of the package
version?: string@"complete asdf plugin versions installed" # Filter latest stable version from this version
]

# Show latest stable version for all installed packages
Expand All @@ -202,21 +226,21 @@ module asdf {
# List installed package versions
export extern "asdf list" [
name?: string@"complete asdf installed" # Name of the package
version?: string # Filter the version
version?: string@"complete asdf plugin versions installed" # Filter the version
]

# List all available package versions
export def "asdf list all" [
name: string@"complete asdf installed" # Name of the package
version?: string="" # Filter the version
version?: string@"complete asdf plugin versions installed"="" # Filter the version
] {
^asdf list all $name $version | lines | parse "{version}" | str trim
}

# Show documentation for plugin
export extern "asdf help" [
name: string@"complete asdf installed" # Name of the plugin
version?: string # Version of the plugin
version?: string@"complete asdf plugin versions installed" # Version of the plugin
]

# Execute a command shim for the current version
Expand All @@ -237,7 +261,7 @@ module asdf {
# Recreate shims for version package
export extern "asdf reshim" [
name?: string@"complete asdf installed" # Name of the package
version?: string # Version of the package
version?: string@"complete asdf plugin versions installed" # Version of the package
]

# List the plugins and versions that provide a command
Expand Down

0 comments on commit 82be580

Please sign in to comment.