Skip to content

Commit

Permalink
rename cmd parse to argx to improve importing (nushell#671)
Browse files Browse the repository at this point in the history
- imports `*` are unnecessary
- shorter names for easier reference in task scripts
- `cmd` is too common and may cause potential conflicts

Co-authored-by: nash <[email protected]>
  • Loading branch information
fj0r and nashvi committed Nov 18, 2023
1 parent 09d6c7e commit 9d02fb1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions modules/cmd_parse/cmd_parse.nu → modules/argx/argx.nu
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export def get-sign [cmd] {
{ switch: $s, name: $n, positional: ($p ++ $pr), rest: $r }
}

# "test -h [123 (3213 3)] 123 `a sdf` --cd --ef sadf -g" | cmd token
export def "cmd token" [] {
# "test -h [123 (3213 3)] 123 `a sdf` --cd --ef sadf -g" | token
export def token [] {
let s = ($in | split row '' | range 1..-2)
let s = if ($s | last) == ' ' { $s } else { $s | append ' ' }
mut par = []
Expand Down Expand Up @@ -76,8 +76,8 @@ export def "cmd token" [] {
return $res
}

export def "cmd parse" [] {
let token = ($in | cmd token)
export def parse [] {
let token = ($in | token)
let sign = (get-sign $token.0)
mut sw = ''
mut pos = []
Expand Down
4 changes: 2 additions & 2 deletions modules/git/git-v2.nu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cmd_parse.nu *
use argx.nu

def agree [
prompt
Expand Down Expand Up @@ -632,7 +632,7 @@ export def remote_braches [] {
}

def "nu-complete git remote branches" [context: string, offset: int] {
let ctx = ($context | cmd parse)
let ctx = ($context | argx parse)
let rb = (remote_braches)
if ($ctx._args | length) < 3 {
$rb | each {|x| {value: $x.1, description: $x.0} }
Expand Down
20 changes: 10 additions & 10 deletions modules/kubernetes/kubernetes.nu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cmd_parse.nu *
use argx.nu

export def ensure-cache-by-lines [cache path action] {
let ls = (do -i { open $path | lines | length })
Expand Down Expand Up @@ -126,12 +126,12 @@ export def kgh [
}

def "nu-complete helm list" [context: string, offset: int] {
let ctx = ($context | cmd parse)
let ctx = ($context | argx parse)
kgh -n $ctx.namespace? | each {|x| {value: $x.name description: $x.updated} }
}

def "nu-complete helm charts" [context: string, offset: int] {
let ctx = ($context | cmd parse)
let ctx = ($context | argx parse)
let path = ($ctx | get _pos.chart)
let path = if ($path | is-empty) { '.' } else { $path }
let paths = (do -i { ls $"($path)*" | each {|x| if $x.type == dir { $"($x.name)/"} else { $x.name }} })
Expand Down Expand Up @@ -378,21 +378,21 @@ def "nu-complete kube kind" [] {
}

def "nu-complete kube res" [context: string, offset: int] {
let ctx = ($context | cmd parse)
let ctx = ($context | argx parse)
let kind = ($ctx | get _args.1)
let ns = if ($ctx.namespace? | is-empty) { [] } else { [-n $ctx.namespace] }
kubectl get $ns $kind | from ssv -a | get NAME
}

def "nu-complete kube res via name" [context: string, offset: int] {
let ctx = ($context | cmd parse)
let ctx = ($context | argx parse)
let kind = ($env.KUBERNETES_RESOURCE_ABBR | get ($ctx | get _args.0 | str substring (-1..)))
let ns = if ($ctx.namespace? | is-empty) { [] } else { [-n $ctx.namespace] }
kubectl get $ns $kind | from ssv -a | get NAME
}

def "nu-complete kube jsonpath" [context: string] {
let ctx = ($context | cmd parse)
let ctx = ($context | argx parse)
let kind = ($ctx | get _args.1)
let res = ($ctx | get _args.2)
let path = $ctx.jsonpath?
Expand Down Expand Up @@ -542,14 +542,14 @@ export def kgno [] {
}

def "nu-complete kube pods" [context: string, offset: int] {
let ctx = ($context | cmd parse)
let ctx = ($context | argx parse)
let ns = (do -i { $ctx | get namespace })
let ns = (spr [-n $ns])
kubectl get $ns pods | from ssv -a | get NAME
}

def "nu-complete kube ctns" [context: string, offset: int] {
let ctx = ($context | cmd parse)
let ctx = ($context | argx parse)
let ns = (do -i { $ctx | get namespace })
let ns = (spr [-n $ns])
let ctn = (do -i { $ctx | get container })
Expand Down Expand Up @@ -660,7 +660,7 @@ def "nu-complete port forward type" [] {
}

def "nu-complete kube port" [context: string, offset: int] {
let ctx = ($context | cmd parse)
let ctx = ($context | argx parse)
let kind = ($ctx | get _args.1)
let ns = if ($ctx.namespace? | is-empty) { [] } else { [-n $ctx.namespace] }
let res = ($ctx | get _args.2)
Expand Down Expand Up @@ -689,7 +689,7 @@ export def kpf [
}

def "nu-complete kube cp" [cmd: string, offset: int] {
let ctx = ($cmd | str substring ..$offset | cmd parse)
let ctx = ($cmd | str substring ..$offset | argx parse)
let p = ($ctx._args | get (($ctx._args | length) - 1))
let ns = (do -i { $ctx | get namespace })
let ns = (spr [-n $ns])
Expand Down

0 comments on commit 9d02fb1

Please sign in to comment.