From 0f7e3d259b5aff7c2a0b9aed87d923d891314112 Mon Sep 17 00:00:00 2001 From: Dejan Golja Date: Fri, 10 Apr 2015 00:27:28 +1000 Subject: [PATCH] Added the option to influx CLI to execute single command and exit. Helpful when scripting and automating installs --- cmd/influx/main.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/influx/main.go b/cmd/influx/main.go index e11d2274538..be75b898c8e 100644 --- a/cmd/influx/main.go +++ b/cmd/influx/main.go @@ -42,6 +42,7 @@ type CommandLine struct { Pretty bool // controls pretty print for json Format string // controls the output format. Valid values are json, csv, or column ShouldDump bool + Execute string } func main() { @@ -55,6 +56,7 @@ func main() { fs.StringVar(&c.Database, "database", c.Database, "database to connect to the server.") fs.StringVar(&c.Format, "output", default_format, "format specifies the format of the server responses: json, csv, or column") fs.BoolVar(&c.ShouldDump, "dump", false, "dump the contents of the given database to stdout") + fs.StringVar(&c.Execute, "execute", c.Execute, "Execute command and quit.") fs.Parse(os.Args[1:]) var promptForPassword bool @@ -86,6 +88,11 @@ func main() { return } + if c.Execute != "" { + c.executeQuery(c.Execute) + return + } + fmt.Println("InfluxDB shell " + version) var historyFile string @@ -211,7 +218,7 @@ func (c *CommandLine) connect(cmd string) { fmt.Printf("Failed to connect to %s\n", c.Client.Addr()) } else { c.Version = v - if !c.ShouldDump { + if !c.ShouldDump && c.Execute == "" { fmt.Printf("Connected to %s version %s\n", c.Client.Addr(), c.Version) } }