mask-completions (#631)

- mask-completions
- kubernetes: rename kgpw to kwp

---------

Co-authored-by: agent <agent@nuc>
This commit is contained in:
fj0r 2023-10-07 18:26:58 +08:00 committed by GitHub
parent 1019cca060
commit c9d63946ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 1 deletions

View File

@ -0,0 +1,56 @@
def "nu-complete mask recipes" [] {
^mask --introspect
| from json
| get commands
| each {|x|
{
value: $x.name,
description: (
$x.description
)
}
}
}
def "nu-complete mask args" [context: string, offset: int] {
let r = ($context | split row ' ')
let c = ^mask --introspect
| from json
| get commands
| where name == $r.1
| get 0
mut rt = []
if not ($c | get required_args | is-empty) {
$rt ++= ($c | get required_args | each {|x|
{value: null, description: $"($x.name) \(positional)"}
})
}
if not ($c | get subcommands | is-empty) {
$rt ++= ($c | get subcommands | each {|x|
{value: $x.name, description: $"($x.description) \(subcommand)"}
})
}
if not ($c | get named_flags | is-empty) {
$rt ++= ($c | get named_flags | each {|x|
let v = if not ($x.long | is-empty) { $"`--($x.long)`" } else if not ($x.short | is-empty) { $"`-($x.short)`" } else { $"---($x.name)" }
let a = ["required", "multiple", "takes_value", "validate_as_number"]
| filter {|y| ($x | get $y) == true }
| str join ','
let d = if ($a | is-empty) { $x.description } else { $"($x.description) \(($a))" }
{value: $v , description: $d }
})
}
$rt
}
export def main [
recipes?: string@"nu-complete mask recipes"
...args: any@"nu-complete mask args"
] {
if ($recipes | is-empty) {
^mask --help
} else {
^mask $recipes $args
}
}

View File

@ -629,7 +629,7 @@ export def kgp [
}
# kubectl get pods --watch
export def kgpw [
export def kwp [
r?: string@"nu-complete kube res via name"
--namespace (-n): string@"nu-complete kube ns"
--selector (-l): string