From fbc9e3cfccb3d9bc7d5f64a94c3e48b6347fc5d8 Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Thu, 8 Dec 2016 09:52:10 -0600 Subject: [PATCH] add clear command to cli --- CHANGELOG.md | 1 + cmd/influx/cli/cli.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c964271a77..83b5056ba0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ The stress tool `influx_stress` will be removed in a subsequent release. We reco - [#7356](https://github.com/influxdata/influxdb/issues/7356): Use X-Forwarded-For IP address in HTTP logger if present. - [#7066](https://github.com/influxdata/influxdb/issues/7066): Add support for secure transmission via collectd. - [#7036](https://github.com/influxdata/influxdb/issues/7036): Switch logging to use structured logging everywhere. +- [#7709](https://github.com/influxdata/influxdb/pull/7709): Add clear command to cli. ### Bugfixes diff --git a/cmd/influx/cli/cli.go b/cmd/influx/cli/cli.go index 3797136467..e40b9d0f4e 100644 --- a/cmd/influx/cli/cli.go +++ b/cmd/influx/cli/cli.go @@ -258,6 +258,8 @@ func (c *CommandLine) ParseCommand(cmd string) error { c.use(cmd) case "insert": return c.Insert(cmd) + case "clear": + c.clear(cmd) default: return c.ExecuteQuery(cmd) } @@ -342,6 +344,34 @@ func (c *CommandLine) SetAuth(cmd string) { c.Client.SetAuth(c.ClientConfig.Username, c.ClientConfig.Password) } +func (c *CommandLine) clear(cmd string) { + args := strings.Split(strings.TrimSuffix(strings.TrimSpace(cmd), ";"), " ") + v := strings.ToLower(strings.Join(args[1:], " ")) + switch v { + case "database", "db": + c.Database = "" + fmt.Println("database context cleared") + return + case "retention policy", "rp": + c.RetentionPolicy = "" + fmt.Println("retention policy context cleared") + return + default: + if len(args) > 1 { + fmt.Printf("invalid command %q.\n", v) + } + fmt.Println(`Possible commands for 'clear' are: + # Clear the database context + clear database + clear db + + # Clear the retention policy context + clear retention policy + clear rp + `) + } +} + func (c *CommandLine) use(cmd string) { args := strings.Split(strings.TrimSuffix(strings.TrimSpace(cmd), ";"), " ") if len(args) != 2 { @@ -790,6 +820,7 @@ func (c *CommandLine) help() { consistency sets write consistency level: any, one, quorum, or all history displays command history settings outputs the current settings for the shell + clear clears settings such as database or retention policy. run 'clear' for help exit/quit/ctrl+d quits the influx shell show databases show database names