mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 06:37:46 +00:00
jc: add magic command completions and clean up parsing
This commit is contained in:
parent
41b1e9510b
commit
9482d0325a
1 changed files with 18 additions and 10 deletions
|
@ -4,29 +4,37 @@ def --env "nu-complete jc" [] {
|
||||||
}
|
}
|
||||||
|
|
||||||
let options = try {
|
let options = try {
|
||||||
let options = ^jc --help
|
let about = ^jc --about
|
||||||
| collect
|
|
||||||
| parse "{_}Parsers:\n{_}\n\nOptions:\n{inherent}\n\nSlice:{_}"
|
|
||||||
| get 0
|
|
||||||
|
|
||||||
let parsers = ^jc --about
|
|
||||||
| from json
|
| from json
|
||||||
|
|
||||||
|
let magic = $about
|
||||||
|
| get parsers
|
||||||
|
| each { { value: $in.magic_commands?, description: $in.description } }
|
||||||
|
| where value != null
|
||||||
|
| flatten
|
||||||
|
|
||||||
|
let options = $about
|
||||||
| get parsers
|
| get parsers
|
||||||
| select argument description
|
| select argument description
|
||||||
| rename value description
|
| rename value description
|
||||||
|
|
||||||
let inherent = $options.inherent
|
let inherent = ^jc --help
|
||||||
| lines
|
| lines
|
||||||
| parse " {short}, {long} {description}"
|
| split list "" # Group with empty lines as boundary.
|
||||||
|
| where { $in.0? == "Options:" } | get 0 # Get the first section that starts with "Options:"
|
||||||
|
| skip 1 # Remove header
|
||||||
|
| each { str trim }
|
||||||
|
| parse "{short}, {long} {description}"
|
||||||
| update description { str trim }
|
| update description { str trim }
|
||||||
| each {|record|
|
| each {|record|
|
||||||
[[value, description];
|
[[value, description];
|
||||||
[$record.short, $record.description],
|
[$record.short, $record.description],
|
||||||
[$record.long, $record.description]]
|
[$record.long, $record.description],
|
||||||
|
]
|
||||||
}
|
}
|
||||||
| flatten
|
| flatten
|
||||||
|
|
||||||
$parsers ++ $inherent
|
$options ++ $inherent ++ $magic
|
||||||
} catch {
|
} catch {
|
||||||
[]
|
[]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue