-
Notifications
You must be signed in to change notification settings - Fork 0
/
history.go
43 lines (36 loc) · 900 Bytes
/
history.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package command
import (
"fmt"
"os"
"text/tabwriter"
"github.com/spf13/cobra"
"github.com/virtualtam/walric/cmd/walric/formatter"
)
// NewHistoryCommand initializes a CLI command to display the history of the
// selected entries.
func NewHistoryCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "history",
Short: "Display the history of selected entries",
Run: func(cmd *cobra.Command, args []string) {
history, err := historyService.All()
if err != nil {
cobra.CheckErr(err)
}
writer := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
for _, entry := range history {
fmt.Fprintf(
writer,
"%s\t%s\t%d x %d\t%s\n",
formatter.FormatDateAsUTC(entry.Date),
entry.Submission.PostID,
entry.Submission.ImageWidthPx,
entry.Submission.ImageHeightPx,
entry.Submission.Title,
)
}
writer.Flush()
},
}
return cmd
}