Begin implementing interactive mode

This commit is contained in:
Jan Philipp Timme 2018-12-29 23:44:40 +01:00
parent 24afa08970
commit 5474966220
1 changed files with 29 additions and 13 deletions

42
main.go
View File

@ -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)
}