Skip to content

Commit

Permalink
Added the option to influx CLI to execute single command and exit.
Browse files Browse the repository at this point in the history
Helpful when scripting and automating installs
  • Loading branch information
dgolja committed Apr 9, 2015
1 parent 019110c commit 0f7e3d2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmd/influx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
Expand Down Expand Up @@ -86,6 +88,11 @@ func main() {
return
}

if c.Execute != "" {
c.executeQuery(c.Execute)
return
}

fmt.Println("InfluxDB shell " + version)

var historyFile string
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 0f7e3d2

Please sign in to comment.