/
logs.go
61 lines (48 loc) · 1.33 KB
/
logs.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package cmd
import (
"fmt"
"github.com/elasticpath/epcc-cli/external/profiles"
"github.com/spf13/cobra"
"strconv"
)
var LogsClear = &cobra.Command{
Use: "clear",
Short: "Clears all HTTP request and response logs",
RunE: func(cmd *cobra.Command, args []string) error {
return profiles.ClearAllRequestLogs()
},
}
var LogsList = &cobra.Command{
Use: "list",
Short: "List all HTTP logs",
RunE: func(cmd *cobra.Command, args []string) error {
files, err := profiles.GetAllRequestLogTitles()
if err != nil {
return err
}
for idx, name := range files {
fmt.Printf("%d %s\n", idx, name)
}
return nil
},
}
var LogsShow = &cobra.Command{
Use: "show <NUMBER>",
Short: "Show HTTP logs for specific number, negative values are from the last value",
Args: cobra.MinimumNArgs(1),
// Hopefully this allows you to run `epcc logs show -1` without error
DisableFlagParsing: true,
RunE: func(cmd *cobra.Command, args []string) error {
i, err := strconv.Atoi(args[0])
if err != nil {
return fmt.Errorf("could not get the %s entry => %w", args[0], err)
}
content, err := profiles.GetNthRequestLog(i)
if err != nil {
return fmt.Errorf("couldn't print logs: %v", err)
}
fmt.Println(content)
return nil
},
}
var Logs = &cobra.Command{Use: "logs", Short: "Retrieve information about previous requests"}