func ui() { gl := goline.NewGoLine(goline.StringPrompt("influx> ")) for { data, err := gl.Line() if err != nil { if err == goline.UserTerminatedError { fmt.Println("\nUser terminated.") return } else { panic(err) } } switch result := data; { case result == "": fmt.Println("") case result == "exit": fmt.Println("\n") return case result == "commands" || result == "help" || result == "?": fmt.Println("\n") printHelp() default: cmd := strings.TrimSpace(result) fmt.Println("\n") handle(cmd) } } }
func main() { gl := goline.NewGoLine(goline.StringPrompt("prompt> ")) gl.AddHandler('?', helpHandler) for { data, err := gl.Line() if err != nil { if err == goline.UserTerminatedError { fmt.Println("\nUser terminated.") return } else { panic(err) } } fmt.Printf("\nGot: '%s' (%d)\n", data, len(data)) if data == "exit" || data == "quit" { fmt.Println("Exiting.") return } } }