From 1350399e8ea080f5a684072eb748bde84222d601 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Tue, 1 Jan 2019 16:05:25 +0100 Subject: [PATCH] Rename functions for clarity --- mailq/parser.go | 2 +- mailq/string.go | 6 +++--- main.go | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mailq/parser.go b/mailq/parser.go index e030acd..89ac5a8 100644 --- a/mailq/parser.go +++ b/mailq/parser.go @@ -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) diff --git a/mailq/string.go b/mailq/string.go index 67c390a..56e8eba 100644 --- a/mailq/string.go +++ b/mailq/string.go @@ -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()) diff --git a/main.go b/main.go index 463c380..edc756d 100644 --- a/main.go +++ b/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 }