Rename functions for clarity
This commit is contained in:
parent
e57c011391
commit
1350399e8e
|
@ -10,7 +10,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func ParseMailQ(dataSource io.Reader) (MailQ, error) {
|
||||
func ParseFromReader(dataSource io.Reader) (MailQ, error) {
|
||||
const dateFormat = "2006 Mon Jan _2 15:04:05"
|
||||
var messageIdStart = regexp.MustCompile("^[0-9A-Za-z]+[*!]? ")
|
||||
scanner := bufio.NewScanner(dataSource)
|
||||
|
|
|
@ -30,13 +30,13 @@ func (m QEntry) DetailedString() string {
|
|||
return fmt.Sprintf("Id: %s\nDate: %s\nStatus: %s\nReason: %s\nSize: %d\nSender: %s\nRecipients: %s", m.Id, m.Date.Format(SortableDateFormat), m.Status, reasonStr, m.Size, m.Sender, strings.Join(m.Recipients, ", "))
|
||||
}
|
||||
|
||||
func (queue MailQ) PrintMachineReadable(writer io.Writer) {
|
||||
func (queue MailQ) WriteMachineReadable(writer io.Writer) {
|
||||
for _, entry := range queue.Entries {
|
||||
fmt.Fprintf(writer, "%s\n", entry.MachineReadableString())
|
||||
}
|
||||
}
|
||||
|
||||
func (queue MailQ) PrintHumanReadable(writer io.Writer) {
|
||||
func (queue MailQ) WriteHumanReadable(writer io.Writer) {
|
||||
if len(queue.Entries) == 0 {
|
||||
fmt.Fprintf(writer, "Mail queue is empty\n")
|
||||
} else {
|
||||
|
@ -54,7 +54,7 @@ func (queue MailQ) PrintHumanReadable(writer io.Writer) {
|
|||
}
|
||||
}
|
||||
|
||||
func (queue MailQ) PrintJSON(writer io.Writer) {
|
||||
func (queue MailQ) WriteJSON(writer io.Writer) {
|
||||
bytes, err := json.Marshal(queue)
|
||||
if err != nil {
|
||||
fmt.Fprintf(writer, "Error encoding queue to JSON: %s\n", err.Error())
|
||||
|
|
8
main.go
8
main.go
|
@ -66,11 +66,11 @@ func showQueue() {
|
|||
|
||||
func printQueue(queue mailq.MailQ, writer io.Writer) {
|
||||
if settings["outputFormat"] == "human" {
|
||||
queue.PrintHumanReadable(writer)
|
||||
queue.WriteHumanReadable(writer)
|
||||
} else if settings["outputFormat"] == "machine" {
|
||||
queue.PrintMachineReadable(writer)
|
||||
queue.WriteMachineReadable(writer)
|
||||
} else if settings["outputFormat"] == "json" {
|
||||
queue.PrintJSON(writer)
|
||||
queue.WriteJSON(writer)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ func readFromCmd(cmd *exec.Cmd) (mailq.MailQ, error) {
|
|||
if err := cmd.Start(); err != nil {
|
||||
return mailq.MailQ{}, err
|
||||
}
|
||||
result, resultError := mailq.ParseMailQ(stdout)
|
||||
result, resultError := mailq.ParseFromReader(stdout)
|
||||
if err := cmd.Wait(); err != nil {
|
||||
return mailq.MailQ{}, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue