Exemplo n.º 1
0
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
		}

	}
}
Exemplo n.º 2
0
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)
		}

	}

}
Exemplo n.º 3
0
func (shell *Shell) Run() {
	shell.prompt = NewPrompt()
	shell.refreshClient()

	gl := goline.NewGoLine(shell.prompt)

	for {
		line, err := gl.Line()
		if err != nil {
			if err == goline.UserTerminatedError {
				return
			}
			util.LogError(err.Error())
		} else {
			fmt.Println()
			line = strings.TrimSpace(line)
			if len(line) > 0 {
				command, arguments := parseLine(line)

				method := reflect.ValueOf(shell).MethodByName(command)
				if method.IsValid() {
					method.Call([]reflect.Value{reflect.ValueOf(arguments)})
				} else {
					util.LogError(fmt.Sprint("Unknown command: '", command, "'"))
				}
			}
		}
	}
}