-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathmustgathers.go
61 lines (53 loc) · 1.36 KB
/
mustgathers.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 (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"reflect"
"github.com/gmeghnag/omc/cmd/helpers"
"github.com/gmeghnag/omc/types"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// contextsCmd represents the mg command
var MustGather = &cobra.Command{
Use: "mg",
Aliases: []string{"must-gather", "must-gathers"},
Short: "List or delete previously used must-gathers.",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
os.Exit(0)
},
}
var GetMustGather = &cobra.Command{
Use: "get",
Aliases: []string{"ls", "list"},
Short: "List must-gathers saved in omc config file.",
Run: func(cmd *cobra.Command, args []string) {
file, _ := ioutil.ReadFile(viper.ConfigFileUsed())
omcConfigJson := types.Config{}
_ = json.Unmarshal([]byte(file), &omcConfigJson)
var data [][]string
var emptyData [][]string
headers := []string{"current", "id", "path", "namespace"}
var mg []types.Context
mg = omcConfigJson.Contexts
for _, context := range mg {
_list := []string{context.Current, context.Id, context.Path, context.Project}
data = append(data, _list)
}
if reflect.DeepEqual(data, emptyData) {
fmt.Fprintln(os.Stderr, "There are no must-gather resources defined.")
os.Exit(1)
} else {
helpers.PrintTable(headers, data)
}
},
}
func init() {
MustGather.AddCommand(
GetMustGather,
DeleteCmd,
)
}