Influx CLI: Make cli case insensitive
parent
975655af9b
commit
1dfdc30377
|
@ -294,6 +294,9 @@ func (c *CommandLine) ParseCommand(cmd string) error {
|
|||
|
||||
// Connect connects to a server.
|
||||
func (c *CommandLine) Connect(cmd string) error {
|
||||
// normalize cmd
|
||||
cmd = strings.ToLower(cmd)
|
||||
|
||||
// Remove the "connect" keyword if it exists
|
||||
addr := strings.TrimSpace(strings.Replace(cmd, "connect", "", -1))
|
||||
if addr == "" {
|
||||
|
@ -551,10 +554,10 @@ func (c *CommandLine) SetPrecision(cmd string) {
|
|||
|
||||
// SetFormat sets output format.
|
||||
func (c *CommandLine) SetFormat(cmd string) {
|
||||
// Remove the "format" keyword if it exists
|
||||
cmd = strings.TrimSpace(strings.Replace(cmd, "format", "", -1))
|
||||
// normalize cmd
|
||||
cmd = strings.ToLower(cmd)
|
||||
// Remove the "format" keyword if it exists
|
||||
cmd = strings.TrimSpace(strings.Replace(cmd, "format", "", -1))
|
||||
|
||||
switch cmd {
|
||||
case "json", "csv", "column":
|
||||
|
@ -566,10 +569,10 @@ func (c *CommandLine) SetFormat(cmd string) {
|
|||
|
||||
// SetWriteConsistency sets write consistency level.
|
||||
func (c *CommandLine) SetWriteConsistency(cmd string) {
|
||||
// Remove the "consistency" keyword if it exists
|
||||
cmd = strings.TrimSpace(strings.Replace(cmd, "consistency", "", -1))
|
||||
// normalize cmd
|
||||
cmd = strings.ToLower(cmd)
|
||||
// Remove the "consistency" keyword if it exists
|
||||
cmd = strings.TrimSpace(strings.Replace(cmd, "consistency", "", -1))
|
||||
|
||||
_, err := models.ParseConsistencyLevel(cmd)
|
||||
if err != nil {
|
||||
|
|
|
@ -147,6 +147,16 @@ func TestSetPrecision(t *testing.T) {
|
|||
if c.ClientConfig.Precision != p {
|
||||
t.Fatalf("Precision is %s but should be %s", c.ClientConfig.Precision, p)
|
||||
}
|
||||
up := "NS"
|
||||
c.SetPrecision("PRECISION " + up)
|
||||
if c.ClientConfig.Precision != p {
|
||||
t.Fatalf("Precision is %s but should be %s", c.ClientConfig.Precision, p)
|
||||
}
|
||||
mixed := "ns"
|
||||
c.SetPrecision("PRECISION " + mixed)
|
||||
if c.ClientConfig.Precision != p {
|
||||
t.Fatalf("Precision is %s but should be %s", c.ClientConfig.Precision, p)
|
||||
}
|
||||
|
||||
// validate set default precision which equals empty string
|
||||
p = "rfc3339"
|
||||
|
@ -154,6 +164,11 @@ func TestSetPrecision(t *testing.T) {
|
|||
if c.ClientConfig.Precision != "" {
|
||||
t.Fatalf("Precision is %s but should be empty", c.ClientConfig.Precision)
|
||||
}
|
||||
p = "RFC3339"
|
||||
c.SetPrecision("precision " + p)
|
||||
if c.ClientConfig.Precision != "" {
|
||||
t.Fatalf("Precision is %s but should be empty", c.ClientConfig.Precision)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetFormat(t *testing.T) {
|
||||
|
@ -169,6 +184,17 @@ func TestSetFormat(t *testing.T) {
|
|||
if c.Format != f {
|
||||
t.Fatalf("Format is %s but should be %s", c.Format, f)
|
||||
}
|
||||
|
||||
uf := "JSON"
|
||||
c.SetFormat("format " + uf)
|
||||
if c.Format != f {
|
||||
t.Fatalf("Format is %s but should be %s", c.Format, f)
|
||||
}
|
||||
mixed := "json"
|
||||
c.SetFormat("FORMAT " + mixed)
|
||||
if c.Format != f {
|
||||
t.Fatalf("Format is %s but should be %s", c.Format, f)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_SetChunked(t *testing.T) {
|
||||
|
@ -263,6 +289,18 @@ func TestSetWriteConsistency(t *testing.T) {
|
|||
t.Fatalf("WriteConsistency is %s but should be %s", c.ClientConfig.WriteConsistency, consistency)
|
||||
}
|
||||
|
||||
consistency = "QUORUM"
|
||||
c.SetWriteConsistency("consistency " + consistency)
|
||||
if c.ClientConfig.WriteConsistency != "quorum" {
|
||||
t.Fatalf("WriteConsistency is %s but should be %s", c.ClientConfig.WriteConsistency, "quorum")
|
||||
}
|
||||
|
||||
consistency = "quorum"
|
||||
c.SetWriteConsistency("CONSISTENCY " + consistency)
|
||||
if c.ClientConfig.WriteConsistency != consistency {
|
||||
t.Fatalf("WriteConsistency is %s but should be %s", c.ClientConfig.WriteConsistency, consistency)
|
||||
}
|
||||
|
||||
// set invalid write consistency and verify there was no change
|
||||
invalidConsistency := "invalid_consistency"
|
||||
c.SetWriteConsistency("consistency " + invalidConsistency)
|
||||
|
|
Loading…
Reference in New Issue