MCPcopy Create free account
hub / github.com/OverloadBlitz/cloudcent-cli / runHistory

Function runHistory

cmd/history.go:22–51  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

20}
21
22func 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
53func truncate(s string, n int) string {
54 if len(s) <= n {

Callers

nothing calls this directly

Calls 5

NewFunction · 0.92
repeatFunction · 0.85
CloseMethod · 0.80
GetHistoryMethod · 0.80
truncateFunction · 0.70

Tested by

no test coverage detected