Add basic inspect feature
This commit is contained in:
parent
47f133f418
commit
f1a6259256
|
@ -1,6 +1,8 @@
|
|||
package mailq
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -21,3 +23,12 @@ type QEntry struct {
|
|||
Recipients []string
|
||||
Reason string
|
||||
}
|
||||
|
||||
func (q MailQ) GetMessageById(id string) (QEntry, error) {
|
||||
for _, entry := range q.Entries {
|
||||
if entry.Id == id {
|
||||
return entry, nil
|
||||
}
|
||||
}
|
||||
return QEntry{}, errors.New(fmt.Sprintf("No message with id '%s' available!", id))
|
||||
}
|
||||
|
|
20
shell.go
20
shell.go
|
@ -48,6 +48,20 @@ func updateSortConfig(fields []string, state shellState) shellState {
|
|||
return state
|
||||
}
|
||||
|
||||
func displayMessageDetails(fields []string, writer io.Writer, state shellState) {
|
||||
if len(fields) < 2 {
|
||||
fmt.Fprintln(writer, "Please state the Id of the message to inspect!")
|
||||
return
|
||||
}
|
||||
messageId := fields[1]
|
||||
message, err := state.Queue.GetMessageById(messageId)
|
||||
if err != nil {
|
||||
fmt.Fprintf(writer, "Could not inspect message with id '%s': '%s'\n", messageId, err.Error())
|
||||
} else {
|
||||
fmt.Fprintf(writer, "%s\n", message.DetailedString())
|
||||
}
|
||||
}
|
||||
|
||||
func interactiveShell(reader io.Reader, writer io.Writer) {
|
||||
var state shellState = initialShellState()
|
||||
fmt.Fprintln(writer, "Let's try an interactive shell!")
|
||||
|
@ -67,8 +81,10 @@ func interactiveShell(reader io.Reader, writer io.Writer) {
|
|||
switch cmd {
|
||||
case "help", "?":
|
||||
printHelp(writer)
|
||||
case "exit", "quit":
|
||||
case "exit":
|
||||
state.QuitShell = true
|
||||
case "inspect":
|
||||
displayMessageDetails(textFields, writer, state)
|
||||
case "sort":
|
||||
state = updateSortConfig(textFields, state)
|
||||
case "show":
|
||||
|
@ -94,5 +110,5 @@ func interactiveShell(reader io.Reader, writer io.Writer) {
|
|||
func printHelp(writer io.Writer) {
|
||||
fmt.Fprintln(writer, "Available commands:")
|
||||
fmt.Fprintln(writer, "?, help: display this output")
|
||||
fmt.Fprintln(writer, "exit, quit: quit this program")
|
||||
fmt.Fprintln(writer, "exit: quit this program")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue