From 547496622014203b9d4e49b2d77ca97bd0e8a6b2 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Sat, 29 Dec 2018 23:44:40 +0100 Subject: [PATCH] Begin implementing interactive mode --- main.go | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index 6e638cd..833a3af 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "os/exec" + "strconv" ) import ( @@ -13,26 +14,41 @@ import ( var settings = make(map[string]string) -func argParse() { - inputModePtr := flag.String("inputMode", "cmd", "Where to read mailq output from. Available options: \"stdin\", \"cmd\"") - mailqCommandPtr := flag.String("mailqCommand", "mailq", "Command to use for getting mailq output") - mailqCommandArgsPtr := flag.String("mailqCommandArgs", "", "Optional arguments to pass to mailqCommand") - flag.Parse() - settings["inputMode"] = *inputModePtr - settings["mailqCommand"] = *mailqCommandPtr - settings["mailqCommandArgs"] = *mailqCommandArgsPtr +func main() { + parseArguments() + if settings["interactive"] == "false" { + showQueue() + } + if settings["interactive"] == "true" { + interactiveShell() + } } -func main() { - argParse() +func parseArguments() { + inputPtr := flag.String("input", "cmd", "Where to read mailq output from. Available options: \"stdin\", \"cmd\"") + mailqCommandPtr := flag.String("mailqCommand", "mailq", "Command to use for getting mailq output") + mailqCommandArgsPtr := flag.String("mailqCommandArgs", "", "Optional arguments to pass to mailqCommand") + interactivePtr := flag.Bool("interactive", false, "Set to true for shell mode") + flag.Parse() + settings["input"] = *inputPtr + settings["mailqCommand"] = *mailqCommandPtr + settings["mailqCommandArgs"] = *mailqCommandArgsPtr + settings["interactive"] = strconv.FormatBool(*interactivePtr) +} + +func interactiveShell() { + +} + +func showQueue() { var entries []parser.QEntry var err error - if settings["inputMode"] == "stdin" { + if settings["input"] == "stdin" { entries, err = readFromStdin() - } else if settings["inputMode"] == "cmd" { + } else if settings["input"] == "cmd" { entries, err = readFromCmd(exec.Command(settings["mailqCommand"])) } else { - fmt.Printf("Unsupported inputMode!") + fmt.Printf("Unsupported input!") flag.PrintDefaults() os.Exit(1) }