-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathscorecard.go
More file actions
134 lines (124 loc) · 3.84 KB
/
scorecard.go
File metadata and controls
134 lines (124 loc) · 3.84 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package cmd
import (
"encoding/json"
"fmt"
"github.com/opslevel/opslevel-go/v2025"
"github.com/opslevel/cli/common"
"github.com/spf13/cobra"
)
var exampleScorecardCmd = &cobra.Command{
Use: "scorecard",
Aliases: []string{"sc"},
Short: "Example Scorecard",
Long: `Example Scorecard`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(getExample(opslevel.ScorecardInput{
Name: "example_name",
Description: opslevel.RefOf("example_description"),
OwnerId: opslevel.ID("Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"),
AffectsOverallServiceLevels: opslevel.RefOf(false),
}))
},
}
var createScorecardCmd = &cobra.Command{
Use: "scorecard",
Aliases: []string{"sc"},
Short: "Create a scorecard",
Long: "Create a scorecard",
Example: `
cat << EOF | opslevel create scorecard -f -
name: "new scorecard"
description: "a newly created scorecard"
ownerId: "XXX_team_id_XXX"
affectsOverallServiceLevels: false
EOF`,
Run: func(cmd *cobra.Command, args []string) {
input, err := readResourceInput[opslevel.ScorecardInput]()
cobra.CheckErr(err)
result, err := getClientGQL().CreateScorecard(*input)
cobra.CheckErr(err)
fmt.Printf("created scorecard: %s\n", result.Id)
},
}
var getScorecardCmd = &cobra.Command{
Use: "scorecard ID|ALIAS",
Aliases: []string{"sc"},
Short: "Get details about a scorecard",
Long: "Get details about a scorecard",
Args: cobra.ExactArgs(1),
ArgAliases: []string{"ID", "ALIAS"},
Run: func(cmd *cobra.Command, args []string) {
key := args[0]
scorecard, err := getClientGQL().GetScorecard(key)
cobra.CheckErr(err)
common.PrettyPrint(scorecard)
},
}
var listScorecardCmd = &cobra.Command{
Use: "scorecard",
Aliases: []string{"scorecards", "sc", "scs"},
Short: "List scorecards",
Long: "List scorecards",
Example: `
opslevel list scorecards -o json | jq 'map( {(.Name): (.ServiceCount)} )'
`,
Run: func(cmd *cobra.Command, args []string) {
resp, err := getClientGQL().ListScorecards(nil)
cobra.CheckErr(err)
list := resp.Nodes
if isJsonOutput() {
common.JsonPrint(json.MarshalIndent(list, "", " "))
} else {
w := common.NewTabWriter("ID", "NAME", "PASSING_CHECKS", "CHECKS_COUNT", "SERVICE_COUNT")
for _, item := range list {
fmt.Fprintf(w, "%s\t%s\t%d\t%d\t%d\n", item.Id, item.Name, item.PassingChecks, item.TotalChecks, item.ServiceCount)
}
w.Flush()
}
},
}
var updateScorecardCmd = &cobra.Command{
Use: "scorecard ID|ALIAS",
Aliases: []string{"sc"},
Short: "Update a scorecard",
Long: "Update a scorecard",
Example: `
cat << EOF | opslevel update scorecard $ID -f -
name: "updated scorecard"
description: "an updated scorecard"
ownerId: "XXX_team_id_XXX"
affectsOverallServiceLevels: true
EOF`,
Args: cobra.ExactArgs(1),
ArgAliases: []string{"ID", "ALIAS"},
Run: func(cmd *cobra.Command, args []string) {
key := args[0]
input, err := readResourceInput[opslevel.ScorecardInput]()
cobra.CheckErr(err)
scorecard, err := getClientGQL().UpdateScorecard(key, *input)
cobra.CheckErr(err)
common.JsonPrint(json.MarshalIndent(scorecard, "", " "))
},
}
var deleteScorecardCmd = &cobra.Command{
Use: "scorecard ID|ALIAS",
Aliases: []string{"sc"},
Short: "Delete a scorecard",
Long: "Delete a scorecard",
Args: cobra.ExactArgs(1),
ArgAliases: []string{"ID", "ALIAS"},
Run: func(cmd *cobra.Command, args []string) {
key := args[0]
deletedScorecardId, err := getClientGQL().DeleteScorecard(key)
cobra.CheckErr(err)
fmt.Printf("deleted scorecard: %s\n", *deletedScorecardId)
},
}
func init() {
exampleCmd.AddCommand(exampleScorecardCmd)
createCmd.AddCommand(createScorecardCmd)
updateCmd.AddCommand(updateScorecardCmd)
getCmd.AddCommand(getScorecardCmd)
listCmd.AddCommand(listScorecardCmd)
deleteCmd.AddCommand(deleteScorecardCmd)
}