(cmd *cobra.Command, args []string)
| 20 | } |
| 21 | |
| 22 | func runHistory(cmd *cobra.Command, args []string) error { |
| 23 | database, err := db.New() |
| 24 | if err != nil { |
| 25 | return err |
| 26 | } |
| 27 | defer database.Close() |
| 28 | |
| 29 | history, err := database.GetHistory(historyLimit) |
| 30 | if err != nil { |
| 31 | return err |
| 32 | } |
| 33 | |
| 34 | if len(history) == 0 { |
| 35 | fmt.Println("No query history found.") |
| 36 | return nil |
| 37 | } |
| 38 | |
| 39 | fmt.Printf("%-4s %-19s %-30s %-20s %s\n", "ID", "Time", "Products", "Region", "Results") |
| 40 | fmt.Println(repeat("-", 90)) |
| 41 | for _, h := range history { |
| 42 | ts := h.CreatedAt.Format("2006-01-02 15:04:05") |
| 43 | fmt.Printf("%-4d %-19s %-30s %-20s %d\n", |
| 44 | h.ID, ts, |
| 45 | truncate(h.ProductFamilies, 30), |
| 46 | truncate(h.Regions, 20), |
| 47 | h.ResultCount, |
| 48 | ) |
| 49 | } |
| 50 | return nil |
| 51 | } |
| 52 | |
| 53 | func truncate(s string, n int) string { |
| 54 | if len(s) <= n { |
nothing calls this directly
no test coverage detected