Skip to content

Commit

Permalink
Merge pull request #2214 from n1tr0g/exec_cmd
Browse files Browse the repository at this point in the history
Added the option to influx CLI to execute single command and exit.
  • Loading branch information
corylanou committed Apr 9, 2015
2 parents b369667 + 0f7e3d2 commit 14042e3
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 14042e3

Please sign in to comment.