commit
261ff11fe3
|
@ -84,13 +84,19 @@ func main() {
|
||||||
c.connect("")
|
c.connect("")
|
||||||
|
|
||||||
if c.ShouldDump {
|
if c.ShouldDump {
|
||||||
c.dump()
|
if err := c.dump(); err != nil {
|
||||||
return
|
os.Exit(1)
|
||||||
|
} else {
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Execute != "" {
|
if c.Execute != "" {
|
||||||
c.executeQuery(c.Execute)
|
if err := c.executeQuery(c.Execute); err != nil {
|
||||||
return
|
os.Exit(1)
|
||||||
|
} else {
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("InfluxDB shell " + version)
|
fmt.Println("InfluxDB shell " + version)
|
||||||
|
@ -264,33 +270,38 @@ func (c *CommandLine) SetFormat(cmd string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CommandLine) dump() {
|
func (c *CommandLine) dump() error {
|
||||||
response, err := c.Client.Dump(c.Database)
|
response, err := c.Client.Dump(c.Database)
|
||||||
defer response.Close()
|
defer response.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Dump failed. %s\n", err)
|
fmt.Printf("Dump failed. %s\n", err)
|
||||||
|
return err
|
||||||
} else {
|
} else {
|
||||||
_, err := io.Copy(os.Stdout, response)
|
_, err := io.Copy(os.Stdout, response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Dump failed. %s\n", err)
|
fmt.Printf("Dump failed. %s\n", err)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CommandLine) executeQuery(query string) {
|
func (c *CommandLine) executeQuery(query string) error {
|
||||||
response, err := c.Client.Query(client.Query{Command: query, Database: c.Database})
|
response, err := c.Client.Query(client.Query{Command: query, Database: c.Database})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("ERR: %s\n", err)
|
fmt.Printf("ERR: %s\n", err)
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
c.FormatResponse(response, os.Stdout)
|
c.FormatResponse(response, os.Stdout)
|
||||||
if response.Error() != nil {
|
if err := response.Error(); err != nil {
|
||||||
fmt.Printf("ERR: %s\n", response.Error())
|
fmt.Printf("ERR: %s\n", response.Error())
|
||||||
if c.Database == "" {
|
if c.Database == "" {
|
||||||
fmt.Println("Warning: It is possible this error is due to not setting a database.")
|
fmt.Println("Warning: It is possible this error is due to not setting a database.")
|
||||||
fmt.Println(`Please set a database with the command "use <database>".`)
|
fmt.Println(`Please set a database with the command "use <database>".`)
|
||||||
}
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CommandLine) FormatResponse(response *client.Response, w io.Writer) {
|
func (c *CommandLine) FormatResponse(response *client.Response, w io.Writer) {
|
||||||
|
|
Loading…
Reference in New Issue