Allow printing queue data in parseable format
This commit is contained in:
parent
7f4e19e285
commit
92a709d196
16
main.go
16
main.go
|
@ -30,11 +30,13 @@ func parseArguments() {
|
|||
mailqCommandArgsPtr := flag.String("mailqCommandArgs", "", "Optional arguments to pass to mailqCommand")
|
||||
interactivePtr := flag.Bool("interactive", false, "Set to true for shell mode")
|
||||
machineFormatPtr := flag.Bool("machineFormat", false, "Set to true to get output suitable for cut/awk/...")
|
||||
usePagerPtr := flag.Bool("usePager", true, "Use pager to display output?")
|
||||
flag.Parse()
|
||||
settings["mailqCommand"] = *mailqCommandPtr
|
||||
settings["mailqCommandArgs"] = *mailqCommandArgsPtr
|
||||
settings["interactive"] = strconv.FormatBool(*interactivePtr)
|
||||
settings["machineFormat"] = strconv.FormatBool(*machineFormatPtr)
|
||||
settings["usePager"] = strconv.FormatBool(*usePagerPtr)
|
||||
}
|
||||
|
||||
func interactiveShell() {
|
||||
|
@ -47,13 +49,25 @@ func showQueue() {
|
|||
fmt.Printf("Could not fetch queue entries: %s\n", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
if settings["usePager"] == "true" {
|
||||
pagerReader, pagerWriter := io.Pipe()
|
||||
pagerDone := make(chan bool)
|
||||
go launchPager(pagerReader, pagerDone)
|
||||
queue.PrintHumanReadable(pagerWriter)
|
||||
printQueue(queue, pagerWriter)
|
||||
pagerWriter.Close()
|
||||
// Wait for pager to be closed before continuing the main program
|
||||
<-pagerDone
|
||||
} else {
|
||||
printQueue(queue, os.Stdout)
|
||||
}
|
||||
}
|
||||
|
||||
func printQueue(queue parser.MailQ, writer io.Writer) {
|
||||
if settings["machineFormat"] == "true" {
|
||||
queue.PrintMachineReadable(writer)
|
||||
} else {
|
||||
queue.PrintHumanReadable(writer)
|
||||
}
|
||||
}
|
||||
|
||||
func launchPager(reader *io.PipeReader, pagerDone chan<- bool) {
|
||||
|
|
|
@ -41,7 +41,7 @@ func (m QEntry) String() string {
|
|||
}
|
||||
|
||||
func (m QEntry) MachineReadableString() string {
|
||||
return fmt.Sprintf("%s_%d_%s_%s_%s", m.Id, m.Status, m.Date.Format(SortableDateFormat), m.Size, m.Sender, m.Reason, strings.Join(m.Recipients, ","))
|
||||
return fmt.Sprintf("%s_%s_%s_%d_%s_%s_%s", m.Id, m.Status, m.Date.Format(SortableDateFormat), m.Size, m.Sender, m.Reason, strings.Join(m.Recipients, ","))
|
||||
}
|
||||
|
||||
func (m QEntry) DetailedString() string {
|
||||
|
|
Loading…
Reference in New Issue