Added the option to influx CLI to execute single command and exit.

Helpful when scripting and automating installs
pull/2214/head
Dejan Golja 2015-04-10 00:27:28 +10:00
parent 019110c9c0
commit 0f7e3d259b
1 changed files with 8 additions and 1 deletions

View File

@ -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)
}
}