Fix reading from command not passing arguments
This commit is contained in:
parent
5474966220
commit
d087d8d746
16
main.go
16
main.go
|
@ -25,12 +25,10 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseArguments() {
|
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")
|
mailqCommandPtr := flag.String("mailqCommand", "mailq", "Command to use for getting mailq output")
|
||||||
mailqCommandArgsPtr := flag.String("mailqCommandArgs", "", "Optional arguments to pass to mailqCommand")
|
mailqCommandArgsPtr := flag.String("mailqCommandArgs", "", "Optional arguments to pass to mailqCommand")
|
||||||
interactivePtr := flag.Bool("interactive", false, "Set to true for shell mode")
|
interactivePtr := flag.Bool("interactive", false, "Set to true for shell mode")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
settings["input"] = *inputPtr
|
|
||||||
settings["mailqCommand"] = *mailqCommandPtr
|
settings["mailqCommand"] = *mailqCommandPtr
|
||||||
settings["mailqCommandArgs"] = *mailqCommandArgsPtr
|
settings["mailqCommandArgs"] = *mailqCommandArgsPtr
|
||||||
settings["interactive"] = strconv.FormatBool(*interactivePtr)
|
settings["interactive"] = strconv.FormatBool(*interactivePtr)
|
||||||
|
@ -43,15 +41,7 @@ func interactiveShell() {
|
||||||
func showQueue() {
|
func showQueue() {
|
||||||
var entries []parser.QEntry
|
var entries []parser.QEntry
|
||||||
var err error
|
var err error
|
||||||
if settings["input"] == "stdin" {
|
entries, err = readFromCmd(exec.Command(settings["mailqCommand"], settings["mailqCommandArgs"]))
|
||||||
entries, err = readFromStdin()
|
|
||||||
} else if settings["input"] == "cmd" {
|
|
||||||
entries, err = readFromCmd(exec.Command(settings["mailqCommand"]))
|
|
||||||
} else {
|
|
||||||
fmt.Printf("Unsupported input!")
|
|
||||||
flag.PrintDefaults()
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error reading: %s\n", err.Error())
|
fmt.Printf("Error reading: %s\n", err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -61,10 +51,6 @@ func showQueue() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func readFromStdin() ([]parser.QEntry, error) {
|
|
||||||
return parser.ParseMailQ(os.Stdin)
|
|
||||||
}
|
|
||||||
|
|
||||||
func readFromCmd(cmd *exec.Cmd) ([]parser.QEntry, error) {
|
func readFromCmd(cmd *exec.Cmd) ([]parser.QEntry, error) {
|
||||||
stdout, err := cmd.StdoutPipe()
|
stdout, err := cmd.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -39,9 +39,10 @@ func ParseMailQ(dataSource io.Reader) ([]QEntry, error) {
|
||||||
const dateFormat = "2006 Mon Jan _2 15:04:05"
|
const dateFormat = "2006 Mon Jan _2 15:04:05"
|
||||||
var messageIdStart = regexp.MustCompile("^[0-9A-Za-z]+[*!]? ")
|
var messageIdStart = regexp.MustCompile("^[0-9A-Za-z]+[*!]? ")
|
||||||
scanner := bufio.NewScanner(dataSource)
|
scanner := bufio.NewScanner(dataSource)
|
||||||
scanner.Scan()
|
var line string
|
||||||
line := scanner.Text()
|
scanner.Scan()
|
||||||
if strings.HasPrefix(line, "Mail queue is empty") {
|
line = scanner.Text()
|
||||||
|
if strings.HasPrefix(line, "Mail queue is empty") {
|
||||||
// If mail queue is empty, there is nothing to do
|
// If mail queue is empty, there is nothing to do
|
||||||
return nil, errors.New(line)
|
return nil, errors.New(line)
|
||||||
} else if strings.HasPrefix(line, "-Queue ID-") == false {
|
} else if strings.HasPrefix(line, "-Queue ID-") == false {
|
||||||
|
|
Loading…
Reference in New Issue