package main import ( "bufio" "fmt" "io" "strings" ) import ( "mailq-inspector/mailq" ) type shellState struct { SortConfig mailq.QEntrySortConfig QuitShell bool } func initialShellState() shellState { var state shellState = shellState{} state.QuitShell = false state.SortConfig = defaultSortConfig() return state } func interactiveShell(reader io.Reader, writer io.Writer) { var state shellState = initialShellState() fmt.Fprintln(writer, "Let's try an interactive shell!") scanner := bufio.NewScanner(reader) for { fmt.Fprint(writer, "> ") if !scanner.Scan() { break } text := strings.Trim(scanner.Text(), " ") textFields := strings.Fields(text) if len(textFields) == 0 { continue } cmd := textFields[0] fmt.Fprintf(writer, "DEBUG - Read input: %q\n", textFields) switch cmd { case "help", "?": printHelp(writer) case "exit", "quit": state.QuitShell = true case "sort": fmt.Println("TODO: Implement this!") default: fmt.Fprintf(writer, "Unknown command '%s'\n", cmd) fmt.Fprintln(writer, "Use 'help' to display help command") } if state.QuitShell == true { break } } fmt.Fprintln(writer, "\nGoodbye!\n") } func printHelp(writer io.Writer) { fmt.Fprintln(writer, "Available commands:") fmt.Fprintln(writer, "?, help: display this output") fmt.Fprintln(writer, "exit, quit: quit this program") }