mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 14:47:47 +00:00
Migrate some scripts to fit new variable and arguments naming style (#268)
* add tmp script * fix more scripts * remove tmp file * migrate to new variable definition * rename builtin variable back
This commit is contained in:
parent
ea7de87315
commit
a34f173181
10 changed files with 99 additions and 99 deletions
|
@ -12,8 +12,8 @@ def build-completions-from-pwd [] {
|
|||
}
|
||||
|
||||
# build a completion form a .fish file and generate a .nu file
|
||||
def build-completion [fish-file: path, nu-file: path] {
|
||||
open $fish-file | parse-fish | make-commands-completion | str collect "\n\n" | save $nu-file
|
||||
def build-completion [fish_file: path, nu_file: path] {
|
||||
open $fish_file | parse-fish | make-commands-completion | str collect "\n\n" | save $nu_file
|
||||
}
|
||||
|
||||
# parse a .fish file based on autogenerated complete syntax
|
||||
|
@ -38,15 +38,15 @@ def parse-fish [] {
|
|||
# tokenize each line of the fish file into a list of tokens
|
||||
# make use of detect columns -n which with one like properly tokenizers arguments including across quotes
|
||||
def tokenize-complete-lines [] {
|
||||
lines
|
||||
| each { |line|
|
||||
lines
|
||||
| each { |line|
|
||||
$line
|
||||
| where $line starts-with complete
|
||||
| where $line starts-with complete
|
||||
| str replace -a "\\\\'" "" # remove escaped quotes ' which break detect columns
|
||||
| str replace -a "-f " "" # remove -f which is a boolean flag we don't support yet
|
||||
| detect columns -n
|
||||
| detect columns -n
|
||||
| transpose -i tokens # turn columns into items, each is a token
|
||||
}
|
||||
}
|
||||
| where ($it | length) > 0 # remove any empty lines
|
||||
| get tokens # get the list of tokens
|
||||
}
|
||||
|
@ -55,10 +55,10 @@ def tokenize-complete-lines [] {
|
|||
def pair-args [] {
|
||||
where $it != complete # drop complete command as we don't need it
|
||||
| window 2 -s 2 # group by ordered pairs, using window 2 -s 2 instead of group 2 to automatically drop any left overs
|
||||
| each { |pair|
|
||||
| each { |pair|
|
||||
[
|
||||
{$"($pair.0 | str trim -c '-')": ($pair.1 | unquote)} # turn into a [{<flag> :<arg>}] removing quotes
|
||||
]
|
||||
]
|
||||
}
|
||||
| reduce { |it, acc| $acc | merge { $it }} # merge the list of records into one big record
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ def make-subcommands-completion [parents: list] {
|
|||
| transpose name args # turn it into a table of name to arguments
|
||||
| each {|subcommand|
|
||||
build-string (
|
||||
if ('d' in ($subcommand.args | columns)) && ($subcommand.args.d != "") {
|
||||
if ('d' in ($subcommand.args | columns)) && ($subcommand.args.d != "") {
|
||||
build-string "# " ($subcommand.args.d.0) "\n" # (sub)command description
|
||||
}) "extern " $quote ($parents | str collect " ") (
|
||||
if $subcommand.name != "" {
|
||||
|
@ -108,7 +108,7 @@ def make-subcommands-completion [parents: list] {
|
|||
} else {
|
||||
where ($it.n == "__fish_use_subcommand") && ($it.a == "") # for root command -> any where n == __fish_use_subcommand and a is empty. otherwise a means a subcommand
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
$fishes # catch all
|
||||
}
|
||||
| build-flags
|
||||
|
@ -119,11 +119,11 @@ def make-subcommands-completion [parents: list] {
|
|||
|
||||
# build the list of flag string in nu syntax
|
||||
def build-flags [] {
|
||||
each { |subargs|
|
||||
if ('l' in ($subargs | columns)) && ($subargs.l != "") {
|
||||
each { |subargs|
|
||||
if ('l' in ($subargs | columns)) && ($subargs.l != "") {
|
||||
build-string "\t--" $subargs.l (build-string
|
||||
(if ('s' in ($subargs | columns)) && ($subargs.s != "") {
|
||||
build-string "(-" $subargs.s ")"
|
||||
(if ('s' in ($subargs | columns)) && ($subargs.s != "") {
|
||||
build-string "(-" $subargs.s ")"
|
||||
}) (if ('d' in ($subargs | columns)) && ($subargs.d != "") {
|
||||
build-string "\t\t\t\t\t# " $subargs.d
|
||||
})
|
||||
|
|
|
@ -7,10 +7,10 @@ def parse-help [] {
|
|||
}
|
||||
|
||||
# takes a table of parsed help commands in format [short? long format? description]
|
||||
def make-completion [command-name: string] {
|
||||
build-string "extern \"" $command-name "\" [\n" ($in | each { |it|
|
||||
def make-completion [command_name: string] {
|
||||
build-string "extern \"" $command_name "\" [\n" ($in | each { |it|
|
||||
build-string "\t--" $it.long (if ($it.short | empty?) == false {
|
||||
build-string "(-" $it.short ")"
|
||||
build-string "(-" $it.short ")"
|
||||
}) (if ($it.description | empty?) == false {
|
||||
build-string "\t\t# " $it.description
|
||||
})
|
||||
|
@ -33,16 +33,16 @@ module tests {
|
|||
['' config 'KEY=VALUE' 'Override a configuration value (unstable)']
|
||||
[h help '' 'Print help information']
|
||||
]
|
||||
|
||||
|
||||
let result = (cargo --help | parse-help)
|
||||
|
||||
|
||||
if $result == $expect {
|
||||
"passed"
|
||||
} else {
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def test-nu [] {
|
||||
let expect = [
|
||||
[short long format description];
|
||||
|
@ -59,16 +59,16 @@ module tests {
|
|||
['' log-level 'String' 'log level for performance logs']
|
||||
['t' threads 'Int' 'threads to use for parallel commands']
|
||||
]
|
||||
|
||||
|
||||
let result = (nu --help | parse-help)
|
||||
|
||||
|
||||
if $result == $expect {
|
||||
"passed"
|
||||
} else {
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export def run-tests [] {
|
||||
[
|
||||
[test result];
|
||||
|
|
|
@ -266,7 +266,7 @@ export extern "yarn npm logout" [
|
|||
export extern "yarn npm publish" [
|
||||
--access: string # The access level of the published package (public or restricted)
|
||||
--tag: string # The tag on the registry that the package should be attached to
|
||||
--tolerate-republish # Warn and exit when republishing an already existing version of a package
|
||||
--tolerate-republish # Warn and exit when republishing an already existing version of a package
|
||||
--opt: string # The OTP token to use with the command
|
||||
]
|
||||
|
||||
|
@ -327,7 +327,7 @@ export extern "yarn plugin" []
|
|||
export extern "yarn plugin import from sources" [
|
||||
--path: string # The path where the repository should be cloned to
|
||||
--repository: string # The repository that should be cloned
|
||||
--branch: string # The branch of the repository that should be cloned
|
||||
--branch: string # The branch of the repository that should be cloned
|
||||
--no-minify # Build a plugin for development (debugging) - non-minified and non-mangled
|
||||
--force(-f) # Always clone the repository instead of trying to fetch the latest commits
|
||||
plugin: string
|
||||
|
@ -419,7 +419,7 @@ export extern "yarn set resolution" [
|
|||
export extern "yarn set version from sources" [
|
||||
--path: string # The path where the repository should be cloned to
|
||||
--repository: string # The repository that should be cloned
|
||||
--branch: string # The branch of the repository that should be cloned
|
||||
--branch: string # The branch of the repository that should be cloned
|
||||
--no-minify # Build a plugin for development (debugging) - non-minified and non-mangled
|
||||
--force(-f) # Always clone the repository instead of trying to fetch the latest commits
|
||||
--skip-plugins # Skip updating the contrib plugins
|
||||
|
@ -506,7 +506,7 @@ def "nu-complete yarn why" [] {
|
|||
|
||||
# Display the reason why a package is needed.
|
||||
export extern "yarn why" [
|
||||
--recursive(-R) # List, for each workspace, what are all the paths that lead to the dependency
|
||||
--recursive(-R) # List, for each workspace, what are all the paths that lead to the dependency
|
||||
--json # Format the output as an NDJSON stream
|
||||
--peers # Also print the peer dependencies that match the specified name
|
||||
package: string@"nu-complete yarn why"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue