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: updated rustup completions to use the new rustup help page style #871

Merged
merged 1 commit into from
Jun 6, 2024
Merged
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
feat: updated rustup completions to use the new rustup help page style
  • Loading branch information
OJarrisonn committed Jun 6, 2024
commit 71c9647a6e269a389840569e7a1f47d997ae0ce3
71 changes: 46 additions & 25 deletions custom-completions/rustup/rustup-completions.nu
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,54 @@

def "nu-complete rustup" [] {
^rustup --help
| str replace --regex --multiline '(rustup[\s\S]*(?=SUBCOMMANDS:))' ''
| str replace --regex --multiline '\n+DISCUSSION[\s\S]*' ''
| str replace --regex --multiline '(rustup[\s\S]*(?=Commands:))' ''
| str replace --regex --multiline '\n+Arguments:[\s\S]*' ''
| lines
| where $it starts-with " "
| where $it starts-with " "
| parse -r '\s*(?P<value>[^ ]+) \s*(?P<description>\w.*)'
}

def "nu-complete rustup toolchain" [] {
^rustup toolchain
| str replace --regex --multiline '(rustup[\s\S]*(?=SUBCOMMANDS:))' ''
| str replace --regex --multiline '\n+DISCUSSION[\s\S]*' ''
| str replace --regex --multiline '(rustup[\s\S]*(?=Commands:))' ''
| str replace --regex --multiline '\n+Options:[\s\S]*' ''
| lines
| where $it starts-with " "
| where $it starts-with " "
| parse -r '\s*(?P<value>[^ ]+) \s*(?P<description>\w.*)'
}


def "nu-complete rustup toolchain list" [] {
^rustup toolchain list
| lines
| str replace " (default)" ""
| append 'stable'
| append 'beta'
| append 'nightly'
| each { |line| if ($line | str contains "(default)") {
{value: ($line | str replace " (default)" ""), description: "default"}
} else {
{value: $line, description: ""}
}
}
}

def "nu-complete rustup target" [] {
^rustup target
| str replace --regex --multiline '(rustup[\s\S]*(?=SUBCOMMANDS:))' ''
| str replace --regex --multiline '\n+DISCUSSION[\s\S]*' ''
| str replace --regex --multiline '(rustup[\s\S]*(?=Commands:))' ''
| str replace --regex --multiline '\n+Options:[\s\S]*' ''
| lines
| where $it starts-with " "
| where $it starts-with " "
| parse -r '\s*(?P<value>[^ ]+) \s*(?P<description>\w.*)'
}

def "nu-complete rustup target list" [] {
^rustup target list
| lines
| str replace " (installed)" ""
| each {|line| if ($line | str contains "installed") {
{value: ($line | str replace " (installed)" ""), description: "installed"}
} else {
{value: $line, description: ""}
}}
}

def "nu-complete rustup target list --installed" [] {
Expand All @@ -51,22 +60,30 @@ def "nu-complete rustup target list --installed" [] {
def "nu-complete rustup update" [] {
^rustup toolchain list
| lines
| str replace " (default)" ""
| each {|line| if ($line | str contains "default") {
{value: ($line | str replace " (default)" ""), description: "default"}
} else {
{value: $line, description: ""}
}}
}

def "nu-complete rustup component" [] {
^rustup component
| str replace --regex --multiline '(rustup[\s\S]*(?=SUBCOMMANDS:))' ''
| str replace --regex --multiline '\n+DISCUSSION[\s\S]*' ''
| str replace --regex --multiline '(rustup[\s\S]*(?=Commands:))' ''
| str replace --regex --multiline '\n+Options:[\s\S]*' ''
| lines
| where $it starts-with " "
| where $it starts-with " "
| parse -r '\s*(?P<value>[^ ]+) \s*(?P<description>\w.*)'
}

def "nu-complete rustup component list" [] {
^rustup component list
| lines
| str replace " (installed)" ""
| each {|line| if ($line | str contains "installed") {
{value: ($line | str replace " (installed)" ""), description: "installed"}
} else {
{value: $line, description: ""}
}}
}

def "nu-complete rustup component list installed" [] {
Expand All @@ -77,10 +94,10 @@ def "nu-complete rustup component list installed" [] {

def "nu-complete rustup override" [] {
^rustup override
| str replace --regex --multiline '(rustup[\s\S]*(?=SUBCOMMANDS:))' ''
| str replace --regex --multiline '\n+DISCUSSION[\s\S]*' ''
| str replace --regex --multiline '(rustup[\s\S]*(?=Commands:))' ''
| str replace --regex --multiline '\n+Options:[\s\S]*' ''
| lines
| where $it starts-with " "
| where $it starts-with " "
| parse -r '\s*(?P<value>[^ ]+) \s*(?P<description>\w.*)'
}

Expand All @@ -100,19 +117,19 @@ def "nu-complete rustup override list installed" [] {

def "nu-complete rustup self" [] {
^rustup self
| str replace --regex --multiline '(rustup[\s\S]*(?=SUBCOMMANDS:))' ''
| str replace --regex --multiline '\n+DISCUSSION[\s\S]*' ''
| str replace --regex --multiline '(rustup[\s\S]*(?=Commands:))' ''
| str replace --regex --multiline '\n+Options:[\s\S]*' ''
| lines
| where $it starts-with " "
| where $it starts-with " "
| parse -r '\s*(?P<value>[^ ]+) \s*(?P<description>\w.*)'
}

def "nu-complete rustup set" [] {
^rustup set
| str replace --regex --multiline '(rustup[\s\S]*(?=SUBCOMMANDS:))' ''
| str replace --regex --multiline '\n+DISCUSSION[\s\S]*' ''
| str replace --regex --multiline '(rustup[\s\S]*(?=Commands:))' ''
| str replace --regex --multiline '\n+Options:[\s\S]*' ''
| lines
| where $it starts-with " "
| where $it starts-with " "
| parse -r '\s*(?P<value>[^ ]+) \s*(?P<description>\w.*)'
}

Expand Down Expand Up @@ -142,6 +159,10 @@ export extern "rustup" [
--version(-V) # Print version information
]

export extern "rustup help" [
command?: string@"nu-complete rustup"
]

export extern "rustup update" [
command?: string@"nu-complete rustup update"
--help(-h) # Print help information
Expand Down