case sensitive for specific command args and flags (#2390)
parent
fdcb9933f6
commit
27cc859e68
|
|
@ -31,19 +31,17 @@ func newArgs(p *Interpreter, aa []string) args {
|
|||
|
||||
case strings.Index(a, fuzzyFlag) == 0:
|
||||
i++
|
||||
args[filterKey] = strings.TrimSpace(aa[i])
|
||||
continue
|
||||
args[filterKey] = strings.ToLower(strings.TrimSpace(aa[i]))
|
||||
|
||||
case strings.Index(a, filterFlag) == 0:
|
||||
args[filterKey] = a[1:]
|
||||
args[filterKey] = strings.ToLower(a[1:])
|
||||
|
||||
case strings.Contains(a, labelFlag):
|
||||
if ll := ToLabels(a); len(ll) != 0 {
|
||||
args[labelKey] = a
|
||||
args[labelKey] = strings.ToLower(a)
|
||||
}
|
||||
|
||||
default:
|
||||
a := strings.TrimSpace(aa[i])
|
||||
switch {
|
||||
case p.IsContextCmd():
|
||||
args[contextKey] = a
|
||||
|
|
@ -53,12 +51,12 @@ func newArgs(p *Interpreter, aa []string) args {
|
|||
}
|
||||
case p.IsXrayCmd():
|
||||
if _, ok := args[topicKey]; ok {
|
||||
args[nsKey] = a
|
||||
args[nsKey] = strings.ToLower(a)
|
||||
} else {
|
||||
args[topicKey] = a
|
||||
args[topicKey] = strings.ToLower(a)
|
||||
}
|
||||
default:
|
||||
args[nsKey] = a
|
||||
args[nsKey] = strings.ToLower(a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,6 +79,16 @@ func TestFlagsNew(t *testing.T) {
|
|||
aa: []string{"app=fred", "ns1", "-f", "blee", "/zorg", "@ctx1"},
|
||||
ll: args{filterKey: "zorg", labelKey: "app=fred", nsKey: "ns1", contextKey: "ctx1"},
|
||||
},
|
||||
"caps": {
|
||||
i: NewInterpreter("po"),
|
||||
aa: []string{"app=fred", "ns1", "-f", "blee", "/zorg", "@Dev"},
|
||||
ll: args{filterKey: "zorg", labelKey: "app=fred", nsKey: "ns1", contextKey: "Dev"},
|
||||
},
|
||||
"ctx": {
|
||||
i: NewInterpreter("ctx"),
|
||||
aa: []string{"Dev"},
|
||||
ll: args{contextKey: "Dev"},
|
||||
},
|
||||
}
|
||||
|
||||
for k := range uu {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ type Interpreter struct {
|
|||
|
||||
func NewInterpreter(s string) *Interpreter {
|
||||
c := Interpreter{
|
||||
line: strings.ToLower(s),
|
||||
line: s,
|
||||
args: make(args),
|
||||
}
|
||||
c.grok()
|
||||
|
|
@ -28,7 +28,7 @@ func (c *Interpreter) grok() {
|
|||
if len(ff) == 0 {
|
||||
return
|
||||
}
|
||||
c.cmd = ff[0]
|
||||
c.cmd = strings.ToLower(ff[0])
|
||||
c.args = newArgs(c, ff[1:])
|
||||
}
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ func (c *Interpreter) Amend(c1 *Interpreter) {
|
|||
}
|
||||
|
||||
func (c *Interpreter) Reset(s string) *Interpreter {
|
||||
c.line = strings.ToLower(s)
|
||||
c.line = s
|
||||
c.grok()
|
||||
|
||||
return c
|
||||
|
|
|
|||
|
|
@ -242,6 +242,11 @@ func TestDirCmd(t *testing.T) {
|
|||
"toast-nodir": {
|
||||
cmd: "dir",
|
||||
},
|
||||
"caps": {
|
||||
cmd: "dir DirName",
|
||||
ok: true,
|
||||
dir: "DirName",
|
||||
},
|
||||
}
|
||||
|
||||
for k := range uu {
|
||||
|
|
@ -330,6 +335,11 @@ func TestContextCmd(t *testing.T) {
|
|||
"toast": {
|
||||
cmd: "ctxto ctx1",
|
||||
},
|
||||
"caps": {
|
||||
cmd: "ctx Dev",
|
||||
ok: true,
|
||||
ctx: "Dev",
|
||||
},
|
||||
}
|
||||
|
||||
for k := range uu {
|
||||
|
|
|
|||
Loading…
Reference in New Issue