1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-07-31 14:17:45 +00:00
nu_scripts/custom-completions/mask/mask-completions.nu
Darren Schroeder 32cdc96414
replace filter with where (#1135)
This PR tries to clean up the use of `filter` by replacing it with
`where`. I did not test each script.

closes #1134
closes #1133
2025-06-12 06:42:16 -05:00

50 lines
1.5 KiB
Text

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"]
| where {|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 extern "mask" [
recipes?: string@"nu-complete mask recipes"
...args: any@"nu-complete mask args"
]