Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improved completions for version in commands for asdf.nu #1760

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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