Rename functions for clarity

This commit is contained in:
Jan Philipp Timme 2019-01-01 16:05:25 +01:00
parent e57c011391
commit 1350399e8e
3 changed files with 8 additions and 8 deletions

View File

@ -10,7 +10,7 @@ import (
"time" "time"
) )
func ParseMailQ(dataSource io.Reader) (MailQ, error) { func ParseFromReader(dataSource io.Reader) (MailQ, 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)

View File

@ -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, ", ")) 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 { for _, entry := range queue.Entries {
fmt.Fprintf(writer, "%s\n", entry.MachineReadableString()) 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 { if len(queue.Entries) == 0 {
fmt.Fprintf(writer, "Mail queue is empty\n") fmt.Fprintf(writer, "Mail queue is empty\n")
} else { } 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) bytes, err := json.Marshal(queue)
if err != nil { if err != nil {
fmt.Fprintf(writer, "Error encoding queue to JSON: %s\n", err.Error()) fmt.Fprintf(writer, "Error encoding queue to JSON: %s\n", err.Error())

View File

@ -66,11 +66,11 @@ func showQueue() {
func printQueue(queue mailq.MailQ, writer io.Writer) { func printQueue(queue mailq.MailQ, writer io.Writer) {
if settings["outputFormat"] == "human" { if settings["outputFormat"] == "human" {
queue.PrintHumanReadable(writer) queue.WriteHumanReadable(writer)
} else if settings["outputFormat"] == "machine" { } else if settings["outputFormat"] == "machine" {
queue.PrintMachineReadable(writer) queue.WriteMachineReadable(writer)
} else if settings["outputFormat"] == "json" { } 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 { if err := cmd.Start(); err != nil {
return mailq.MailQ{}, err return mailq.MailQ{}, err
} }
result, resultError := mailq.ParseMailQ(stdout) result, resultError := mailq.ParseFromReader(stdout)
if err := cmd.Wait(); err != nil { if err := cmd.Wait(); err != nil {
return mailq.MailQ{}, err return mailq.MailQ{}, err
} }