-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrubric.go
More file actions
178 lines (163 loc) · 4.68 KB
/
rubric.go
File metadata and controls
178 lines (163 loc) · 4.68 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package cmd
import (
"encoding/json"
"fmt"
"github.com/opslevel/opslevel-go/v2025"
"github.com/opslevel/cli/common"
"github.com/spf13/cobra"
)
var exampleCategoryCmd = &cobra.Command{
Use: "category",
Aliases: []string{"cat"},
Short: "Example rubric category",
Long: `Example rubric category`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(getExample(opslevel.CategoryCreateInput{
Name: "example_name",
}))
},
}
var createCategoryCmd = &cobra.Command{
Use: "category NAME",
Aliases: []string{"cat"},
Short: "Create a rubric category",
Long: `Create a rubric category`,
Args: cobra.ExactArgs(1),
ArgAliases: []string{"NAME"},
Run: func(cmd *cobra.Command, args []string) {
category, err := getClientGQL().CreateCategory(opslevel.CategoryCreateInput{
Name: args[0],
})
cobra.CheckErr(err)
fmt.Println(category.Id)
},
}
var getCategoryCmd = &cobra.Command{
Use: "category ID",
Aliases: []string{"cat"},
Short: "Get details about a rubric category",
Long: `Get details about a rubric category`,
Args: cobra.ExactArgs(1),
ArgAliases: []string{"ID"},
Run: func(cmd *cobra.Command, args []string) {
key := args[0]
category, err := getClientGQL().GetCategory(opslevel.ID(key))
cobra.CheckErr(err)
common.PrettyPrint(category)
},
}
var listCategoryCmd = &cobra.Command{
Use: "category",
Aliases: []string{"categories", "cat", "cats"},
Short: "Lists rubric categories",
Long: `Lists rubric categories`,
Run: func(cmd *cobra.Command, args []string) {
resp, err := getClientGQL().ListCategories(nil)
cobra.CheckErr(err)
list := resp.Nodes
if isJsonOutput() {
common.JsonPrint(json.MarshalIndent(list, "", " "))
} else {
w := common.NewTabWriter("NAME", "ALIAS", "ID")
for _, item := range list {
fmt.Fprintf(w, "%s\t%s\t%s\t\n", item.Name, item.Alias(), item.Id)
}
w.Flush()
}
},
}
var deleteCategoryCmd = &cobra.Command{
Use: "category ID",
Aliases: []string{"cat"},
Short: "Delete a rubric category",
Long: `Delete a rubric category`,
Args: cobra.ExactArgs(1),
ArgAliases: []string{"ID"},
Run: func(cmd *cobra.Command, args []string) {
key := args[0]
err := getClientGQL().DeleteCategory(opslevel.ID(key))
cobra.CheckErr(err)
fmt.Printf("deleted '%s' category\n", key)
},
}
var exampleLevelCmd = &cobra.Command{
Use: "level",
Short: "Example rubric level",
Long: `Example rubric level`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(getExample(opslevel.LevelCreateInput{
Name: "example_name",
}))
},
}
var createLevelCmd = &cobra.Command{
Use: "level NAME",
Short: "Create a rubric level",
Long: `Create a rubric level`,
Args: cobra.ExactArgs(1),
ArgAliases: []string{"NAME"},
Run: func(cmd *cobra.Command, args []string) {
category, err := getClientGQL().CreateLevel(opslevel.LevelCreateInput{
Name: args[0],
})
cobra.CheckErr(err)
fmt.Println(category.Id)
},
}
var getLevelCmd = &cobra.Command{
Use: "level ID",
Short: "Get details about a rubric level",
Long: `Get details about a rubric level`,
Args: cobra.ExactArgs(1),
ArgAliases: []string{"ID"},
Run: func(cmd *cobra.Command, args []string) {
key := args[0]
level, err := getClientGQL().GetLevel(opslevel.ID(key))
cobra.CheckErr(err)
common.PrettyPrint(level)
},
}
var listLevelCmd = &cobra.Command{
Use: "level",
Aliases: []string{"levels"},
Short: "Lists rubric levels",
Long: `Lists rubric levels`,
Run: func(cmd *cobra.Command, args []string) {
resp, err := getClientGQL().ListLevels(nil)
cobra.CheckErr(err)
if isJsonOutput() {
common.JsonPrint(json.MarshalIndent(resp.Nodes, "", " "))
} else {
w := common.NewTabWriter("NAME", "ALIAS", "ID")
for _, item := range resp.Nodes {
fmt.Fprintf(w, "%s\t%s\t%s\t\n", item.Name, item.Alias, item.Id)
}
w.Flush()
}
},
}
var deleteLevelCmd = &cobra.Command{
Use: "level ID",
Short: "Delete a rubric level",
Long: `Delete a rubric level`,
Args: cobra.ExactArgs(1),
ArgAliases: []string{"ID"},
Run: func(cmd *cobra.Command, args []string) {
key := args[0]
err := getClientGQL().DeleteLevel(opslevel.ID(key))
cobra.CheckErr(err)
fmt.Printf("deleted '%s' level\n", key)
},
}
func init() {
exampleCmd.AddCommand(exampleCategoryCmd)
createCmd.AddCommand(createCategoryCmd)
getCmd.AddCommand(getCategoryCmd)
listCmd.AddCommand(listCategoryCmd)
deleteCmd.AddCommand(deleteCategoryCmd)
exampleCmd.AddCommand(exampleLevelCmd)
createCmd.AddCommand(createLevelCmd)
getCmd.AddCommand(getLevelCmd)
listCmd.AddCommand(listLevelCmd)
deleteCmd.AddCommand(deleteLevelCmd)
}