mirror of
https://github.com/RGBCube/ncc
synced 2025-07-28 10:37:44 +00:00
nushell: make jc wrapper better
This commit is contained in:
parent
9da7ad1439
commit
fd49444afe
1 changed files with 38 additions and 3 deletions
|
@ -24,15 +24,50 @@ def --env mcg [path: path]: nothing -> nothing {
|
|||
jj git init --colocate
|
||||
}
|
||||
|
||||
def --env "nu-complete jc" [] {
|
||||
if $env.__NU_COMPLETE_JC? != null {
|
||||
return $env.__NU_COMPLETE_JC
|
||||
}
|
||||
|
||||
let options = try {
|
||||
let options = jc --help
|
||||
| parse "{_}Options:\n{inherent}\n\nSlice:{_}"
|
||||
| get 0
|
||||
|
||||
let parsers = jc --about
|
||||
| from json
|
||||
| get parsers.argument
|
||||
|
||||
let inherent = $options.inherent
|
||||
| lines
|
||||
| parse " {short}, {long} {description}"
|
||||
| update description { str trim }
|
||||
| each {|record|
|
||||
[[value, description];
|
||||
[$record.short, $record.description],
|
||||
[$record.long, $record.description]]
|
||||
}
|
||||
| flatten
|
||||
|
||||
$parsers ++ $inherent
|
||||
} catch {
|
||||
null
|
||||
}
|
||||
|
||||
$env.__NU_COMPLETE_JC = $options
|
||||
|
||||
$options
|
||||
}
|
||||
|
||||
# Run `jc` (JSON Converter).
|
||||
def --wrapped jc [...arguments]: [any -> table, any -> record, any -> string] {
|
||||
def --wrapped jc [...arguments: string@"nu-complete jc"]: [any -> table, any -> record, any -> string] {
|
||||
let run = ^jc ...$arguments | complete
|
||||
|
||||
if $run.exit_code != 0 {
|
||||
error make {
|
||||
msg: $run.stderr
|
||||
msg: "jc exection failed"
|
||||
label: {
|
||||
text: "jc execution failed"
|
||||
text: ($run.stderr | str replace "jc:" "" | str replace "Error -" "" | str trim)
|
||||
span: (metadata $arguments).span
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue