From 7fcbf543db0fd9255104a77c1bfffb5c56b2326b Mon Sep 17 00:00:00 2001 From: neur1n Date: Mon, 11 Mar 2024 10:25:44 +0800 Subject: [PATCH 1/7] fix: update modules/virtual_environments/nu_msvs to work with nushell 0.91.0 (#784) Fixed the `glob` related code as mentioned in title. --- modules/virtual_environments/nu_msvs/README.md | 2 +- modules/virtual_environments/nu_msvs/nu_msvs.nu | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/virtual_environments/nu_msvs/README.md b/modules/virtual_environments/nu_msvs/README.md index a69be17d4..c8be42541 100644 --- a/modules/virtual_environments/nu_msvs/README.md +++ b/modules/virtual_environments/nu_msvs/README.md @@ -3,7 +3,7 @@ A module for Using Microsoft Visual Studio (MSVS) command line tools from Nushel ## Prerequisites -- [nushell](https://github.com/nushell/nushell) >= 0.83.0 +- [nushell](https://github.com/nushell/nushell) >= 0.91.0 - [vswhere](https://github.com/microsoft/vswhere) standalone or comes with VS diff --git a/modules/virtual_environments/nu_msvs/nu_msvs.nu b/modules/virtual_environments/nu_msvs/nu_msvs.nu index 79b88c231..ee0db76f1 100644 --- a/modules/virtual_environments/nu_msvs/nu_msvs.nu +++ b/modules/virtual_environments/nu_msvs/nu_msvs.nu @@ -14,10 +14,10 @@ export-env { $env.MSVS_MSVC_ROOT = ( if not ($"($env.MSVS_ROOT)/VC/Tools/MSVC/" | path exists) { "" - } else if (ls $"($env.MSVS_ROOT)/VC/Tools/MSVC/*" | is-empty) { + } else if (ls ($"($env.MSVS_ROOT)/VC/Tools/MSVC/*" | into glob) | is-empty) { "" } else { - ((ls $"($env.MSVS_ROOT)/VC/Tools/MSVC/*").name.0 | str replace -a '\\' '/') + ((ls ($"($env.MSVS_ROOT)/VC/Tools/MSVC/*" | into glob)).name.0 | str replace -a '\\' '/') }) $env.MSVS_MSDK_ROOT = (registry query --hklm 'SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0' InstallationFolder | get value) From 56fe4b94ff351d629efce837e0d692f24cb2edbf Mon Sep 17 00:00:00 2001 From: fj0r <82698591+fj0r@users.noreply.github.com> Date: Tue, 12 Mar 2024 19:45:50 +0800 Subject: [PATCH 2/7] standardized parameter naming for `--help` and fix regex capture (#786) standardized parameter naming for `--help` |old|new| |-|-| |img|image| |ctn|container| |p|file| |ctx|context| |ns|namespace| |k|kind| |r, i|resource| |r|pod, service, deployment| |res|kind| |svc|service| |d, dpl|deployment| change `(?P)` to `(?)` Co-authored-by: nash --- modules/docker/docker.nu | 60 +++++------ modules/git/git-v2.nu | 8 +- modules/kubernetes/kubernetes.nu | 172 +++++++++++++++---------------- modules/network/ssh.nu | 2 +- 4 files changed, 121 insertions(+), 121 deletions(-) diff --git a/modules/docker/docker.nu b/modules/docker/docker.nu index 7675b5417..9c7c8f849 100644 --- a/modules/docker/docker.nu +++ b/modules/docker/docker.nu @@ -79,9 +79,9 @@ export def container-list [ # list images export def image-list [ -n: string@"nu-complete docker ns" - img?: string@"nu-complete docker images" + image?: string@"nu-complete docker images" ] { - if ($img | is-empty) { + if ($image | is-empty) { ^$env.docker-cli ...($n | with-flag -n) images | from ssv -a | each {|x| @@ -99,7 +99,7 @@ export def image-list [ } } } else { - let r = ^$env.docker-cli ...($n | with-flag -n) inspect $img + let r = ^$env.docker-cli ...($n | with-flag -n) inspect $image | from json | get 0 let e = $r.Config.Env? @@ -170,48 +170,48 @@ def "nu-complete docker images" [] { # container log export def container-log [ - ctn: string@"nu-complete docker containers" + container: string@"nu-complete docker containers" -l: int = 100 # line -n: string@"nu-complete docker ns" # namespace ] { let l = if $l == 0 { [] } else { [--tail $l] } - ^$env.docker-cli ...($n | with-flag -n) logs -f ...$l $ctn + ^$env.docker-cli ...($n | with-flag -n) logs -f ...$l $container } export def container-log-trunc [ - ctn: string@"nu-complete docker containers" + container: string@"nu-complete docker containers" -n: string@"nu-complete docker ns" # namespace ] { if $env.docker-cli == 'podman' { print -e $'(ansi yellow)podman(ansi dark_gray) isn’t supported(ansi reset)' } else { - let f = ^$env.docker-cli ...($n | with-flag -n) inspect --format='{{.LogPath}}' $ctn + let f = ^$env.docker-cli ...($n | with-flag -n) inspect --format='{{.LogPath}}' $container truncate -s 0 $f } } # attach container export def --wrapped container-attach [ - ctn: string@"nu-complete docker containers" + container: string@"nu-complete docker containers" -n: string@"nu-complete docker ns" ...args ] { let ns = $n | with-flag -n if ($args|is-empty) { - ^$env.docker-cli ...$ns exec -it $ctn /bin/sh -c "[ -e /bin/zsh ] && /bin/zsh || [ -e /bin/bash ] && /bin/bash || /bin/sh" + ^$env.docker-cli ...$ns exec -it $container /bin/sh -c "[ -e /bin/zsh ] && /bin/zsh || [ -e /bin/bash ] && /bin/bash || /bin/sh" } else { - ^$env.docker-cli ...$ns exec -it $ctn ...$args + ^$env.docker-cli ...$ns exec -it $container ...$args } } def "nu-complete docker cp" [cmd: string, offset: int] { let argv = $cmd | str substring ..$offset | split row ' ' let p = if ($argv | length) > 2 { $argv | get 2 } else { $argv | get 1 } - let ctn = ^$env.docker-cli ps + let container = ^$env.docker-cli ps | from ssv -a | each {|x| {description: $x.'CONTAINER ID' value: $"($x.NAMES):" }} let n = $p | split row ':' - if $"($n | get 0):" in ($ctn | get value) { + if $"($n | get 0):" in ($container | get value) { ^$env.docker-cli exec ($n | get 0) sh -c $"ls -dp ($n | get 1)*" | lines | each {|x| $"($n | get 0):($x)"} @@ -220,7 +220,7 @@ def "nu-complete docker cp" [cmd: string, offset: int] { ls -a ($"($p)*" | into glob) | each {|x| if $x.type == dir { $"($x.name)/"} else { $x.name }} } - $files | append $ctn + $files | append $container } } @@ -233,20 +233,20 @@ export def container-copy-file [ } # remove container -export def container-remove [ctn: string@"nu-complete docker containers" -n: string@"nu-complete docker ns"] { - ^$env.docker-cli ...($n | with-flag -n) container rm -f $ctn +export def container-remove [container: string@"nu-complete docker containers" -n: string@"nu-complete docker ns"] { + ^$env.docker-cli ...($n | with-flag -n) container rm -f $container } # history -export def container-history [img: string@"nu-complete docker images" -n: string@"nu-complete docker ns"] { - ^$env.docker-cli ...($n | with-flag -n) history --no-trunc $img | from ssv -a +export def container-history [image: string@"nu-complete docker images" -n: string@"nu-complete docker ns"] { + ^$env.docker-cli ...($n | with-flag -n) history --no-trunc $image | from ssv -a } # save images -export def image-save [-n: string@"nu-complete docker ns" ...img: string@"nu-complete docker images"] { - ^$env.docker-cli ...($n | with-flag -n) save ...$img +export def image-save [-n: string@"nu-complete docker ns" ...image: string@"nu-complete docker images"] { + ^$env.docker-cli ...($n | with-flag -n) save ...$image } # load images @@ -265,8 +265,8 @@ export def system-prune-all [-n: string@"nu-complete docker ns"] { } # remove image -export def image-remove [img: string@"nu-complete docker images" -n: string@"nu-complete docker ns"] { - ^$env.docker-cli ...($n | with-flag -n) rmi $img +export def image-remove [image: string@"nu-complete docker images" -n: string@"nu-complete docker ns"] { + ^$env.docker-cli ...($n | with-flag -n) rmi $image } # add new tag @@ -276,15 +276,15 @@ export def image-tag [from: string@"nu-complete docker images" to: string -n: s # push image export def image-push [ - img: string@"nu-complete docker images" + image: string@"nu-complete docker images" --tag(-t): string -n: string@"nu-complete docker ns" -i ] { let $insecure = if $i {[--insecure-registry]} else {[]} if ($tag | is-empty) { - ^$env.docker-cli ...($n | with-flag -n) ...$insecure push $img + ^$env.docker-cli ...($n | with-flag -n) ...$insecure push $image } else { - ^$env.docker-cli ...($n | with-flag -n) tag $img $tag + ^$env.docker-cli ...($n | with-flag -n) tag $image $tag do -i { ^$env.docker-cli ...($n | with-flag -n) ...$insecure push $tag } @@ -293,9 +293,9 @@ export def image-push [ } # pull image -export def image-pull [img -n: string@"nu-complete docker ns" -i] { +export def image-pull [image -n: string@"nu-complete docker ns" -i] { let $insecure = if $i {[--insecure-registry]} else {[]} - ^$env.docker-cli ...($n | with-flag -n) ...$insecure pull $img + ^$env.docker-cli ...($n | with-flag -n) ...$insecure pull $image } ### list volume @@ -371,7 +371,7 @@ export def container-create [ --with-x --privileged(-P) --namespace(-n): string@"nu-complete docker ns" - img: string@"nu-complete docker images" # image + image: string@"nu-complete docker images" # image ...cmd # command args ] { let ns = $namespace | with-flag -n @@ -409,11 +409,11 @@ export def container-create [ $debug $appimage $netadmin $with_x $mnt $vols $workdir $cache ] | flatten - let name = $"($img | split row '/' | last | str replace ':' '-')_(date now | format date %m%d%H%M)" + let name = $"($image | split row '/' | last | str replace ':' '-')_(date now | format date %m%d%H%M)" if $dry_run { - echo ([docker $ns run --name $name $args $img $cmd] | flatten | str join ' ') + echo ([docker $ns run --name $name $args $image $cmd] | flatten | str join ' ') } else { - ^$env.docker-cli ...$ns run --name $name ...$args $img ...($cmd | flatten) + ^$env.docker-cli ...$ns run --name $name ...$args $image ...($cmd | flatten) } } diff --git a/modules/git/git-v2.nu b/modules/git/git-v2.nu index 2a7b1170f..92a2b6c02 100644 --- a/modules/git/git-v2.nu +++ b/modules/git/git-v2.nu @@ -1,4 +1,4 @@ -use ../argx/argx.nu +use argx.nu def agree [ prompt @@ -119,7 +119,7 @@ export def gb [ } else if ($branch | is-empty) { let merged = git branch --merged | lines - | each { $in | parse -r '\s*\*?\s*(?P[^\s]+)' | get 0.b } + | each { $in | parse -r '\s*\*?\s*(?[^\s]+)' | get 0.b } { local: (git branch) remote: (git branch --remote) @@ -128,7 +128,7 @@ export def gb [ | each {|x| $x.v | lines | each {|n| - let n = $n | parse -r '\s*(?P\*)?\s*(?P[^\s]+)( -> )?(?P[^\s]+)?' | get 0 + let n = $n | parse -r '\s*(?\*)?\s*(?[^\s]+)( -> )?(?[^\s]+)?' | get 0 let c = if ($n.c | is-empty) { null } else { true } let r = if ($n.r | is-empty) { null } else { $n.r } let m = if $n.b in $merged { true } else { null } @@ -595,7 +595,7 @@ export def _git_log_stat [n] { | split row ',' | each {|x| $x | str trim - | parse -r "(?P[0-9]+) (?P.+)" + | parse -r "(?[0-9]+) (?.+)" | get 0 } | reduce -f {sha: $acc.c file:0 ins:0 del:0} {|i,a| diff --git a/modules/kubernetes/kubernetes.nu b/modules/kubernetes/kubernetes.nu index a583ac99c..75ea629c0 100644 --- a/modules/kubernetes/kubernetes.nu +++ b/modules/kubernetes/kubernetes.nu @@ -45,38 +45,38 @@ export-env { # kubectl apply -f -export def kaf [p: path] { - kubectl apply -f $p +export def kaf [file: path] { + kubectl apply -f $file } # kubectl diff -f -export def kdf [p: path] { - kubectl diff -f $p +export def kdf [file: path] { + kubectl diff -f $file } # kubectl delete -f -export def kdelf [p: path] { - kubectl delete -f $p +export def kdelf [file: path] { + kubectl delete -f $file } # kubectl apply -k (kustomize) -export def kak [p: path] { - kubectl apply -k $p +export def kak [file: path] { + kubectl apply -k $file } # kubectl diff -k (kustomize) -export def kdk [p: path] { - kubectl diff -k $p +export def kdk [file: path] { + kubectl diff -k $file } # kubectl delete -k (kustomize) -export def kdelk [p: path] { - kubectl delete -k $p +export def kdelk [file: path] { + kubectl delete -k $file } # kubectl kustomize (template) -export def kk [p: path] { - kubectl kustomize $p +export def kk [file: path] { + kubectl kustomize $file } ### ctx @@ -121,20 +121,20 @@ def "nu-complete kube ns" [] { } # kubectl change context -export def kcc [ctx: string@"nu-complete kube ctx"] { - kubectl config use-context $ctx +export def kcc [context: string@"nu-complete kube ctx"] { + kubectl config use-context $context } # kubectl (change) namespace -export def kn [ns: string@"nu-complete kube ns"] { - if not ($ns in (kubectl get namespace | from ssv -a | get NAME)) { - if ([no yes] | input list $"namespace '($ns)' doesn't exist, create it?") in [yes] { - kubectl create namespace $ns +export def kn [namespace: string@"nu-complete kube ns"] { + if not ($namespace in (kubectl get namespace | from ssv -a | get NAME)) { + if ([no yes] | input list $"namespace '($namespace)' doesn't exist, create it?") in [yes] { + kubectl create namespace $namespace } else { return } } - kubectl config set-context --current $"--namespace=($ns)" + kubectl config set-context --current $"--namespace=($namespace)" } def parse_cellpath [path] { @@ -312,8 +312,8 @@ def "nu-complete kube jsonpath" [context: string] { # kubectl get export def kg [ - k: string@"nu-complete kube kind" - r?: string@"nu-complete kube res" + kind: string@"nu-complete kube kind" + resource?: string@"nu-complete kube res" --namespace (-n): string@"nu-complete kube ns" --jsonpath (-p): string@"nu-complete kube jsonpath" --selector (-l): string @@ -329,12 +329,12 @@ export def kg [ } else { [-n $namespace] } - if ($r | is-empty) { + if ($resource | is-empty) { let l = $selector | with-flag -l if ($jsonpath | is-empty) { let wide = if $wide {[-o wide]} else {[]} if ($verbose) { - kubectl get -o json ...$n $k ...$l | from json | get items + kubectl get -o json ...$n $kind ...$l | from json | get items | each {|x| { name: $x.metadata.name @@ -348,74 +348,74 @@ export def kg [ } | normalize-column-names } else if $watch { - kubectl get ...$n $k ...$l ...$wide --watch + kubectl get ...$n $kind ...$l ...$wide --watch } else { - kubectl get ...$n $k ...$l ...$wide | from ssv -a | normalize-column-names + kubectl get ...$n $kind ...$l ...$wide | from ssv -a | normalize-column-names } } else { - kubectl get ...$n $k $"--output=jsonpath={($jsonpath)}" | from json + kubectl get ...$n $kind $"--output=jsonpath={($jsonpath)}" | from json } } else { - kubectl get ...$n $k $r -o json | from json + kubectl get ...$n $kind $resource -o json | from json } } # kubectl describe export def kd [ - r: string@"nu-complete kube kind" - i: string@"nu-complete kube res" + kind: string@"nu-complete kube kind" + resource: string@"nu-complete kube res" --namespace (-n): string@"nu-complete kube ns" ] { - kubectl describe ...($namespace | with-flag -n) $r $i + kubectl describe ...($namespace | with-flag -n) $kind $resource } # kubectl create export def kc [ - r: string@"nu-complete kube kind" + kind: string@"nu-complete kube kind" --namespace (-n): string@"nu-complete kube ns" name:string ] { - kubectl create ...($namespace | with-flag -n) $r $name + kubectl create ...($namespace | with-flag -n) $kind $name } # kubectl get -o yaml export def ky [ - r: string@"nu-complete kube kind" - i: string@"nu-complete kube res" + kind: string@"nu-complete kube kind" + resource: string@"nu-complete kube res" --namespace (-n): string@"nu-complete kube ns" ] { - kubectl get ...($namespace | with-flag -n) -o yaml $r $i + kubectl get ...($namespace | with-flag -n) -o yaml $kind $resource } # kubectl edit export def ke [ - k: string@"nu-complete kube kind" - r?: string@"nu-complete kube res" + kind: string@"nu-complete kube kind" + resource?: string@"nu-complete kube res" --namespace (-n): string@"nu-complete kube ns" --selector(-l): string ] { let n = $namespace | with-flag -n - let r = if ($selector | is-empty) { $r } else { - let res = kubectl get $k ...$n -l $selector | from ssv -a | each {|x| $x.NAME} + let r = if ($selector | is-empty) { $resource } else { + let res = kubectl get $kind ...$n -l $selector | from ssv -a | each {|x| $x.NAME} if ($res | length) == 1 { $res.0 } else if ($res | length) == 0 { return } else { - $res | input list $'select ($k) ' + $res | input list $'select ($kind) ' } } - kubectl edit ...$n $k $r + kubectl edit ...$n $kind $r } # kubectl delete export def kdel [ - r: string@"nu-complete kube kind" - i: string@"nu-complete kube res" + kind: string@"nu-complete kube kind" + resource: string@"nu-complete kube res" --namespace (-n): string@"nu-complete kube ns" --force(-f) ] { - kubectl delete ...($namespace | with-flag -n) ...(if $force {[--grace-period=0 --force]} else {[]}) $r $i + kubectl delete ...($namespace | with-flag -n) ...(if $force {[--grace-period=0 --force]} else {[]}) $kind $resource } @@ -457,36 +457,36 @@ def "nu-complete kube ctns" [context: string, offset: int] { # kubectl get pods export def kgp [ - r?: string@"nu-complete kube res via name" + pod?: string@"nu-complete kube res via name" --namespace (-n): string@"nu-complete kube ns" --jsonpath (-p): string@"nu-complete kube jsonpath" --selector (-l): string --all (-a) ] { - if ($r | is-not-empty) { - kubectl get pods ...($namespace | with-flag -n) $r --output=json + if ($pod | is-not-empty) { + kubectl get pods ...($namespace | with-flag -n) $pod --output=json | from json | {...$in.metadata, ...$in.spec, ...$in.status} } else if $all { kg pods -a --wide } else { - kg pods -n $namespace -p $jsonpath -l $selector --wide $r + kg pods -n $namespace -p $jsonpath -l $selector --wide $pod } } # kubectl get pods --watch export def kwp [ - r?: string@"nu-complete kube res via name" + pod?: string@"nu-complete kube res via name" --namespace (-n): string@"nu-complete kube ns" --selector (-l): string ] { - kg pods -n $namespace -w -l $selector --wide $r + kg pods -n $namespace -w -l $selector --wide $pod } # kubectl edit pod export def kep [ --namespace (-n): string@"nu-complete kube ns" - pod?: string@"nu-complete kube res via name" + pod: string@"nu-complete kube res via name" --selector (-l): string ] { ke -n $namespace pod -l $selector $pod @@ -589,7 +589,7 @@ def "nu-complete kube port" [context: string, offset: int] { # kubectl port-forward export def kpf [ - res: string@"nu-complete port forward type" + kind: string@"nu-complete port forward type" target: string@"nu-complete kube res" port: string@"nu-complete kube port" --local (-l): string @@ -597,7 +597,7 @@ export def kpf [ ] { let ns = $namespace | with-flag -n let port = if ($local | is-empty) { $port } else { $"($local):($port)" } - kubectl port-forward ...$ns $"($res)/($target)" $port + kubectl port-forward ...$ns $"($kind)/($target)" $port } def "nu-complete kube cp" [cmd: string, offset: int] { @@ -630,15 +630,15 @@ export def kcp [ # kubectl get services export def kgs [ - r?: string@"nu-complete kube res via name" + service?: string@"nu-complete kube res via name" --namespace (-n): string@"nu-complete kube ns" --jsonpath (-p): string@"nu-complete kube jsonpath" --selector (-l): string ] { - if ($r | is-empty) { - kg services -n $namespace -p $jsonpath -l $selector $r + if ($service | is-empty) { + kg services -n $namespace -p $jsonpath -l $selector $service } else { - kubectl get svc ...($namespace | with-flag -n) $r --output=json + kubectl get svc ...($namespace | with-flag -n) $service --output=json | from json | {...$in.metadata, ...$in.spec, ...$in.status} } @@ -646,44 +646,44 @@ export def kgs [ # kubectl edit service export def kes [ - svc?: string@"nu-complete kube res via name" + service?: string@"nu-complete kube res via name" --namespace (-n): string@"nu-complete kube ns" --selector (-l): string ] { - ke -n $namespace service -l $selector $svc + ke -n $namespace service -l $selector $service } # kubectl delete service export def kdels [ - svc: string@"nu-complete kube res via name" + service: string@"nu-complete kube res via name" --namespace (-n): string@"nu-complete kube ns" ] { - kdel -n $namespace service $svc + kdel -n $namespace service $service } # kubectl get deployments export def kgd [ - r?: string@"nu-complete kube res via name" + deployment?: string@"nu-complete kube res via name" --namespace (-n): string@"nu-complete kube ns" --jsonpath (-p): string@"nu-complete kube jsonpath" --selector (-l): string ] { - kg -n $namespace deployments -p $jsonpath -l $selector $r + kg -n $namespace deployments -p $jsonpath -l $selector $deployment } # kubectl edit deployment export def ked [ - d?: string@"nu-complete kube res via name" + deployment?: string@"nu-complete kube res via name" --namespace (-n): string@"nu-complete kube ns" --selector (-l): string ] { - ke -n $namespace deployments -l $selector $d + ke -n $namespace deployments -l $selector $deployment } def "nu-complete num9" [] { [0 1 2 3] } # kubectl scale deployment export def ksd [ - d: string@"nu-complete kube deploys" + deployment: string@"nu-complete kube deploys" num: string@"nu-complete num9" --namespace (-n): string@"nu-complete kube ns" ] { @@ -691,13 +691,13 @@ export def ksd [ "too large" } else { let ns = $namespace | with-flag -n - kubectl scale ...$ns deployments $d --replicas $num + kubectl scale ...$ns deployments $deployment --replicas $num } } # kubectl scale deployment with reset export def ksdr [ - d: string@"nu-complete kube deploys" + deployment: string@"nu-complete kube deploys" num: int@"nu-complete num9" --namespace (-n): string@"nu-complete kube ns" ] { @@ -707,8 +707,8 @@ export def ksdr [ "too small" } else { let ns = $namespace | with-flag -n - kubectl scale ...$ns deployments $d --replicas 0 - kubectl scale ...$ns deployments $d --replicas $num + kubectl scale ...$ns deployments $deployment --replicas 0 + kubectl scale ...$ns deployments $deployment --replicas $num } } @@ -723,23 +723,23 @@ def "nu-complete kube kind with image" [] { # kubectl set image export def ksi [ - k: string@"nu-complete kube kind with image" - r: string@"nu-complete kube res" + kind: string@"nu-complete kube kind with image" + resource: string@"nu-complete kube res" --namespace(-n): string@"nu-complete kube ns" act?: any ] { let ns = $namespace | with-flag -n - let path = match $k { + let path = match $kind { _ => '.spec.template.spec.containers[*]' } - let name = kubectl get ...$ns $k $r -o $"jsonpath={($path).name}" | split row ' ' - let image = kubectl get ...$ns $k $r -o $"jsonpath={($path).image}" | split row ' ' + let name = kubectl get ...$ns $kind $resource -o $"jsonpath={($path).name}" | split row ' ' + let image = kubectl get ...$ns $kind $resource -o $"jsonpath={($path).image}" | split row ' ' let list = $name | zip $image | reduce -f {} {|it,acc| $acc | insert $it.0 $it.1 } if ($act | describe -d).type == 'closure' { let s = do $act $list if ($s | describe -d).type == 'record' { let s = $s | transpose k v | each {|x| $"($x.k)=($x.v)"} - kubectl ...$ns set image $"($k)/($r)" ...$s + kubectl ...$ns set image $"($kind)/($resource)" ...$s } } else { $list @@ -748,14 +748,14 @@ export def ksi [ # kubectl redistribution deployment export def krd [ - d: string@"nu-complete kube deploys" + deployment: string@"nu-complete kube deploys" ...nodes: string@"nu-complete kube nodes" --namespace (-n): string@"nu-complete kube ns" ] { let ns = $namespace | with-flag -n let nums = kubectl get nodes | from ssv -a | length - kubectl scale ...$ns deployments $d --replicas $nums - let labels = kubectl get ...$ns deploy $d --output=json + kubectl scale ...$ns deployments $deployment --replicas $nums + let labels = kubectl get ...$ns deploy $deployment --output=json | from json | get spec.selector.matchLabels | transpose k v @@ -765,7 +765,7 @@ export def krd [ for p in ($pods | where NODE not-in $nodes) { kubectl delete ...$ns pod --grace-period=0 --force $p.NAME } - kubectl scale ...$ns deployments $d --replicas ($pods | where NODE in $nodes | length) + kubectl scale ...$ns deployments $deployment --replicas ($pods | where NODE in $nodes | length) } # kubectl rollout status deployment @@ -777,22 +777,22 @@ export alias kgrs = kubectl get rs export def krhd [ --namespace (-n): string@"nu-complete kube ns" --revision (-v): int - dpl: string@"nu-complete kube res via name" + deployment: string@"nu-complete kube res via name" ] { let ns = $namespace | with-flag -n let v = if ($revision|is-empty) { [] } else { [ $"--revision=($revision)" ] } - kubectl ...$ns rollout history $"deployment/($dpl)" ...$v + kubectl ...$ns rollout history $"deployment/($deployment)" ...$v } # kubectl rollout undo export def krud [ --namespace (-n): string@"nu-complete kube ns" --revision (-v): int - dpl: string@"nu-complete kube res via name" + deployment: string@"nu-complete kube res via name" ] { let ns = $namespace | with-flag -n let v = if ($revision|is-empty) { [] } else { [ $"--to-revision=($revision)" ] } - kubectl ...$ns rollout undo $"deployment/($dpl)" ...$v + kubectl ...$ns rollout undo $"deployment/($deployment)" ...$v } export alias ksss = kubectl scale statefulset export alias krsss = kubectl rollout status statefulset diff --git a/modules/network/ssh.nu b/modules/network/ssh.nu index 6a8863a6a..52b52af02 100644 --- a/modules/network/ssh.nu +++ b/modules/network/ssh.nu @@ -31,7 +31,7 @@ def "nu-complete ssh host" [] { export def parse-ssh-file [group] { $in - | parse -r '(?PHost|HostName|User|Port|IdentityFile)\s+(?P.+)' + | parse -r '(?Host|HostName|User|Port|IdentityFile)\s+(?.+)' | append { k: Host, v: null} | reduce -f { rst: [], item: {Host: null} } {|it, acc| if $it.k == 'Host' { From 74ba060f55e3ceff305caf0745313a8541eafb6c Mon Sep 17 00:00:00 2001 From: Texas Toland Date: Tue, 12 Mar 2024 10:55:07 -0500 Subject: [PATCH 3/7] [stdlib-candidate] set-env (#787) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rewrite of nushell/nushell#12156 for jdx/mise#1763. ### Why? Nushell philosophically omits a `set` list mutation. But `$env` is inherently mutable leading to issues described in nushell/nushell#12148. `set-env` provides such an operation exclusively for `$env`. ### What changed? 1. Explicit flag instead of implicit list concatenation 2. Expands updates to any `$env` field not only `$env.config` ### How is it used? ```yaml ❯ set-env -h Gracefully set an environment variable or merge a nested option. Examples: Set $env.NUPM_HOME > set-env NUPM_HOME $'($nu.home-path)/.local/share/nupm' Add to $env.NU_LIB_DIRS > set-env --append NU_LIB_DIRS $'($env.NUPM_HOME)/modules' Set a nested config option > set-env config.filesize.metric true Add a config hook > set-env -a config.hooks.pre_prompt 'ellie | print' Usage: > main {flags} Flags: -a, --append - Append to the previous value or wrap in a new list -h, --help - Display the help message for this command Parameters: field : The environment variable name or nested option cell path value : The value to set or append Input/output types: ╭───┬─────────┬─────────╮ │ # │ input │ output │ ├───┼─────────┼─────────┤ │ 0 │ nothing │ nothing │ ╰───┴─────────┴─────────╯ ``` ### How does it work? ```nushell export def --env main [ field: cell-path value: any --append (-a) ]: nothing -> nothing { # just an alias def 'get or' [default field] { get --ignore-errors $field | default $default } let value = if $append { # append to the previous value or empty list $env | get or [] $field | append $value } else { $value } # work around nushell/nushell#12168 let field = $field | to text | split row . let value = match $field { [_] => $value # if cell path is nested [$root, ..$field] => { let field = $field | into cell-path # reassigning $env would be an error # merging reserved names like PWD would be an error # so merge from 1 level deep instead $env | get or {} $root | upsert $field $value } } # avoid issues noted above load-env { ($field | first): $value } } ``` ### Where are the tests? Pending next PR for nupm integration. --- stdlib-candidate/set-env.nu | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 stdlib-candidate/set-env.nu diff --git a/stdlib-candidate/set-env.nu b/stdlib-candidate/set-env.nu new file mode 100644 index 000000000..1e0b3c490 --- /dev/null +++ b/stdlib-candidate/set-env.nu @@ -0,0 +1,37 @@ +# Gracefully set an environment variable or merge a nested option. +# +# Examples: +# Set $env.NUPM_HOME +# > set-env NUPM_HOME $'($nu.home-path)/.local/share/nupm' +# +# Add to $env.NU_LIB_DIRS +# > set-env --append NU_LIB_DIRS $'($env.NUPM_HOME)/modules' +# +# Set a nested config option +# > set-env config.filesize.metric true +# +# Add a config hook +# > set-env -a config.hooks.pre_prompt 'ellie | print' +export def --env main [ + field: cell-path # The environment variable name or nested option cell path + value: any # The value to set or append + --append (-a) # Append to the previous value or wrap in a new list +]: nothing -> nothing { + def 'get or' [default field] { + get --ignore-errors $field | default $default + } + let value = if $append { + $env | get or [] $field | append $value + } else { + $value + } + let field = $field | to text | split row . + let value = match $field { + [_] => $value + [$root, ..$field] => { + let field = $field | into cell-path + $env | get or {} $root | upsert $field $value + } + } + load-env { ($field | first): $value } +} From 45f5310e51d32e2fb2517fbdc145f1ab69c3b28d Mon Sep 17 00:00:00 2001 From: fnuttens Date: Tue, 12 Mar 2024 16:55:37 +0100 Subject: [PATCH 4/7] Add chezmoi aliases (#788) --- aliases/chezmoi/chezmoi-aliases.nu | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 aliases/chezmoi/chezmoi-aliases.nu diff --git a/aliases/chezmoi/chezmoi-aliases.nu b/aliases/chezmoi/chezmoi-aliases.nu new file mode 100644 index 000000000..99d4197c2 --- /dev/null +++ b/aliases/chezmoi/chezmoi-aliases.nu @@ -0,0 +1,6 @@ +export alias ch = chezmoi +export alias chad = chezmoi add +export alias chap = chezmoi apply +export alias chd = chezmoi diff +export alias chda = chezmoi data +export alias chs = chezmoi status From c2ef662e48223938b1ae35b95d2f28cd5b531fba Mon Sep 17 00:00:00 2001 From: Auca Coyan Date: Tue, 12 Mar 2024 16:48:08 -0300 Subject: [PATCH 5/7] =?UTF-8?q?=E2=9C=A8=20add=20a=20`nu-check`=20verifica?= =?UTF-8?q?tion=20CI=20(#771)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I made a `toolkit.nu` with a very bare bones struct, this is called via [`setup-nu`](https://github.com/hustcer/setup-nu) action, and generates the `check-files.nu` file. After that, another nu instance run that script to check files one by one. The folder `before_v0.60/` is excluded. --- .github/workflows/ci.yml | 29 +++++++++++++++++ .github/workflows/daily.yml | 33 +++++++++++++++++++ .gitignore | 2 ++ toolkit.nu | 64 +++++++++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/daily.yml create mode 100644 toolkit.nu diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..d60a230bb --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,29 @@ +on: + pull_request: + +env: + NUSHELL_CARGO_PROFILE: ci + NU_LOG_LEVEL: DEBUG + +jobs: + nu-check: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: 'Fetch main branch' + run: | + git fetch origin main --depth 1 + - uses: hustcer/setup-nu@v3.9 + with: + version: '*' + check-latest: true + features: full # dataframe and extra included + - name: toolkit check pr + shell: nu {0} + run: | + nu -c "use toolkit.nu *; check pr" + - name: run nu-check on modified files + shell: nu {0} + run: | + nu ./check-files.nu diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml new file mode 100644 index 000000000..366cc6b6c --- /dev/null +++ b/.github/workflows/daily.yml @@ -0,0 +1,33 @@ +on: + push: + branches: + - main + schedule: + - cron: '30 0 * * *' # every day at 00:30 AM UTC + +env: + NUSHELL_CARGO_PROFILE: ci + NU_LOG_LEVEL: DEBUG + +jobs: + nu-check: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: 'Fetch main branch' + run: | + git fetch origin main --depth 1 + - uses: hustcer/setup-nu@v3.9 + with: + version: '*' + check-latest: true + features: full # dataframe and extra included + - name: toolkit generate-file-list --full + shell: nu {0} + run: | + nu -c "use toolkit.nu *; generate-file-list --full" + - name: run nu-check on all files + shell: nu {0} + run: | + nu ./check-files.nu diff --git a/.gitignore b/.gitignore index 507f1f664..4f920f119 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ # ignore the git mailmap file .mailmap + +check-files.nu diff --git a/toolkit.nu b/toolkit.nu new file mode 100644 index 000000000..e038b651d --- /dev/null +++ b/toolkit.nu @@ -0,0 +1,64 @@ +# this module regroups a bunch of development tools to make the development +# process easier for anyone. +# +# the main purpose of `toolkit` is to offer an easy to use interface for the +# developer during a PR cycle. + + +# check that all the tests pass +export def test [ +] { + print "toolkit test: not implemented!" +} + +# run all the necessary checks and tests to submit a perfect PR +export def "check pr" [ +] { + generate-file-list + test +} + +export def main [] { help toolkit } + +export def generate-file-list [ --full ] { + let start = "let files = [" + + mut files = [""] + + if $full { + # all the *.nu files in the repo + # exept for `before_v0.60` + print "checking all files..." + mut $files = glob **/*.nu --exclude [before_v0.60/**] + } else { + # only the *.nu files changed in comparison with origin/main + $files = (git diff --name-only origin/main | lines | filter { str ends-with '.nu'} | each { path expand }) + } + + + let new_list = $files | str join ",\n" | append "]" + + let final = " + + mut exit_code = 0 + for file in $files { + let diagnostics_table = nu --ide-check 10 $file | to text | ['[', $in, ']'] | str join | from json + let result = $diagnostics_table | where type == \"diagnostic\" | is-empty + if $result { + print $\"✔ ($file) is ok\" + } else { + print $\"❌ ($file) has errors:\" + print ($diagnostics_table | where type == \"diagnostic\" | reject span) + $exit_code = 1 + } + } + print $\"💚 All files checked!\" + +exit $exit_code +" + + $start + | append $new_list + | append $final + | save "check-files.nu" --force +} From 191636af9cecff4e591b998552f8bc0aad94c28f Mon Sep 17 00:00:00 2001 From: Auca Coyan Date: Fri, 15 Mar 2024 08:30:31 -0300 Subject: [PATCH 6/7] :sparkles: add `flutter` completions (#792) Just a barebones `flutter` command and `flutter pub` commands, the most used ones --- .../flutter/flutter-completions.nu | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 custom-completions/flutter/flutter-completions.nu diff --git a/custom-completions/flutter/flutter-completions.nu b/custom-completions/flutter/flutter-completions.nu new file mode 100644 index 000000000..f1df4894c --- /dev/null +++ b/custom-completions/flutter/flutter-completions.nu @@ -0,0 +1,41 @@ +export extern "flutter" [ + command?: string@"nu-complete flutter commands" + --help(-h) # Print this usage information. + --verbose(-v) # Noisy logging, including all shell commands executed. + --device-id(-d) # Target device id or name (prefixes allowed). + --version # Reports the version of this tool. + --enable-analytics # Enable telemetry reporting each time a flutter or dart command runs. + --disable-analytics # Disable telemetry reporting each time a flutter or dart command runs, until it is re-enabled. + --suppress-analytics # Suppress analytics reporting for the current CLI invocation. +] + +def "nu-complete flutter commands" [] { + ^flutter --help + | into string + | str replace --regex --multiline '(Manage[\s\S]*(?=Flutter SDK))' '' + | lines + | filter { str starts-with " " } + | each { str trim } + | parse "{value} {description}" + | str trim +} + +export extern "flutter create" [ + project: string # project to create +] + +export extern "flutter pub" [ + command?: string@"nu-complete pub commands" +] + +def "nu-complete pub commands" [] { + ^flutter pub --help + | into string + | str replace --regex --multiline '(Commands[\s\S]*(?=Available subcommands))' '' + | lines + | filter { str starts-with " " } + | each { str trim } + | parse "{value} {description}" + | str trim +} + From 878bfc615cb5d0da68287ebf52f36ec31d831073 Mon Sep 17 00:00:00 2001 From: Texas Toland Date: Fri, 15 Mar 2024 12:17:31 -0500 Subject: [PATCH 7/7] Refactor toolkit.nu (#791) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #789 🍻 - Runs without first generating a script - Returns error (file) count - Requires `--and-exit` to exit with error code - Enables alternative report with env `STUB_IDE_CHECK=true` - Expands documentation - All subcommands share same file querying - Prepares for nupm test integration --- .github/workflows/ci.yml | 20 +++--- .github/workflows/daily.yml | 24 +++---- toolkit.nu | 131 +++++++++++++++++++++++------------- 3 files changed, 106 insertions(+), 69 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d60a230bb..fd76791cd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,5 @@ on: - pull_request: + pull_request: env: NUSHELL_CARGO_PROFILE: ci @@ -11,19 +11,17 @@ jobs: steps: - uses: actions/checkout@v4 - - name: 'Fetch main branch' + - name: "Fetch main branch" run: | - git fetch origin main --depth 1 + git fetch origin main --depth 1 - uses: hustcer/setup-nu@v3.9 with: - version: '*' - check-latest: true - features: full # dataframe and extra included + version: "*" + check-latest: true + features: full # dataframe and extra included - name: toolkit check pr shell: nu {0} + # nix STUB_IDE_CHECK when nushell/nushell#12208 fixed run: | - nu -c "use toolkit.nu *; check pr" - - name: run nu-check on modified files - shell: nu {0} - run: | - nu ./check-files.nu + use ${{ github.workspace }}/toolkit.nu * + STUB_IDE_CHECK=true check pr --and-exit diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index 366cc6b6c..0a874e153 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -1,9 +1,9 @@ on: push: - branches: + branches: - main schedule: - - cron: '30 0 * * *' # every day at 00:30 AM UTC + - cron: "30 0 * * *" # every day at 00:30 AM UTC env: NUSHELL_CARGO_PROFILE: ci @@ -15,19 +15,17 @@ jobs: steps: - uses: actions/checkout@v4 - - name: 'Fetch main branch' + - name: "Fetch main branch" run: | - git fetch origin main --depth 1 + git fetch origin main --depth 1 - uses: hustcer/setup-nu@v3.9 with: - version: '*' - check-latest: true - features: full # dataframe and extra included - - name: toolkit generate-file-list --full + version: "*" + check-latest: true + features: full # dataframe and extra included + - name: toolkit check pr --full shell: nu {0} + # nix STUB_IDE_CHECK when nushell/nushell#12208 fixed run: | - nu -c "use toolkit.nu *; generate-file-list --full" - - name: run nu-check on all files - shell: nu {0} - run: | - nu ./check-files.nu + use ${{ github.workspace }}/toolkit.nu * + STUB_IDE_CHECK=true check pr --full --and-exit diff --git a/toolkit.nu b/toolkit.nu index e038b651d..a24445ae7 100644 --- a/toolkit.nu +++ b/toolkit.nu @@ -4,61 +4,102 @@ # the main purpose of `toolkit` is to offer an easy to use interface for the # developer during a PR cycle. - -# check that all the tests pass +# Check that all the tests pass. +# +# Input: +# Optional file paths to check or infer them from Git export def test [ -] { - print "toolkit test: not implemented!" + --full # Check all files instead of input + --and-exit # Exit with error count +]: [list -> int, nothing -> int] { + with files --full=$full --and-exit=$and_exit { |files| + print "test: not implemented!" + [0] # success code + } } -# run all the necessary checks and tests to submit a perfect PR +# Run all the necessary checks and tests to submit a perfect PR. +# +# Input: +# Optional file paths to check or infer them from Git export def "check pr" [ -] { - generate-file-list - test + --full # Check all files instead of input + --and-exit # Exit with error count +]: [list -> int, nothing -> int] { + with files --full=$full --and-exit=$and_exit { |files| + [ + { lint } + { test } + ] | par-each { |task| $files | do $task } # TODO: buffer output + } } -export def main [] { help toolkit } - -export def generate-file-list [ --full ] { - let start = "let files = [" - - mut files = [""] +# View subcommands. +export def main []: nothing -> nothing { + help toolkit +} - if $full { - # all the *.nu files in the repo - # exept for `before_v0.60` - print "checking all files..." - mut $files = glob **/*.nu --exclude [before_v0.60/**] +# Wrap file lookup and exit codes. +def "with files" [ + task: closure + --full + --and-exit +]: [list -> int, nothing -> int] { + let files = match [$in, $full] { + [_ true] => (glob **/*.nu --exclude [before_v0.60/**]) + [null _] => (git diff --name-only origin/main | lines) + [$files _] => $files + } | where $it ends-with .nu and ($it | path exists) + let error_count = if ($files | length) == 0 { + print 'warning: no .nu files found!' + 0 } else { - # only the *.nu files changed in comparison with origin/main - $files = (git diff --name-only origin/main | lines | filter { str ends-with '.nu'} | each { path expand }) + $files + | each { path expand } + | do $task $files # run the closure with both input and param + | math sum # it MUST return a non-empty list of ints } - - - let new_list = $files | str join ",\n" | append "]" - - let final = " - - mut exit_code = 0 - for file in $files { - let diagnostics_table = nu --ide-check 10 $file | to text | ['[', $in, ']'] | str join | from json - let result = $diagnostics_table | where type == \"diagnostic\" | is-empty - if $result { - print $\"✔ ($file) is ok\" - } else { - print $\"❌ ($file) has errors:\" - print ($diagnostics_table | where type == \"diagnostic\" | reject span) - $exit_code = 1 - } + if $and_exit { + exit $error_count + } else { + $error_count } - print $\"💚 All files checked!\" +} -exit $exit_code -" +# Check the input file with nu --ide-check. +export def "lint ide-check" []: path -> int { + let file = $in + let stub = $env.STUB_IDE_CHECK? | default false | into bool + let diagnostics = if $stub { + do { nu --no-config-file --commands $"use '($file)'" } + | complete + | [[severity message]; [$in.exit_code $in.stderr]] + | where severity != 0 + } else { + nu --ide-check 10 $file + | $"[($in)]" + | from nuon + | where type == diagnostic + | select severity message + } + let error_count = $diagnostics | length + if $error_count == 0 { + print $"lint: ✔ ($file) is ok" + } else { + print $"lint: ❌ ($file) has errors:\n($diagnostics | table)" + } + $error_count +} - $start - | append $new_list - | append $final - | save "check-files.nu" --force +# Check that all the files parse. +# +# Input: +# Optional file paths to check or infer them from Git +export def lint [ + --full # Check all files instead of input + --and-exit # Exit with error count +]: [list -> int, nothing -> int] { + with files --full=$full --and-exit=$and_exit { + par-each { lint ide-check } + } }