-
Notifications
You must be signed in to change notification settings - Fork 0
/
approval_ruleset_list.go
65 lines (54 loc) · 1.45 KB
/
approval_ruleset_list.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
62
63
64
65
package main
import (
encjson "encoding/json"
"fmt"
"github.com/fullstaq-labs/sqedule/cli"
"github.com/fullstaq-labs/sqedule/lib/mocking"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// approvalRulesetListCmd represents the 'approval-ruleset list' command
var approvalRulesetListCmd = &cobra.Command{
Use: "list",
Short: "List approval rulesets",
RunE: func(cmd *cobra.Command, args []string) error {
err := viper.BindPFlags(cmd.Flags())
if err != nil {
return err
}
return approvalRulesetListCmd_run(viper.GetViper(), mocking.RealPrinter{})
},
}
func approvalRulesetListCmd_run(viper *viper.Viper, printer mocking.IPrinter) error {
config := cli.LoadConfigFromViper(viper)
state, err := cli.LoadStateFromFilesystem()
if err != nil {
return fmt.Errorf("Error loading state: %w", err)
}
req, err := cli.NewApiRequest(config, state)
if err != nil {
return err
}
var result interface{}
resp, err := req.
SetResult(&result).
Get("/approval-rulesets")
if err != nil {
return err
}
if resp.IsError() {
return fmt.Errorf("Error listing approval rulesets: %s", cli.GetApiErrorMessage(resp))
}
output, err := encjson.MarshalIndent(result, "", " ")
if err != nil {
return fmt.Errorf("Error formatting result as JSON: %w", err)
}
printer.PrintOutputln(string(output))
return nil
}
func init() {
cmd := approvalRulesetListCmd
flags := cmd.Flags()
approvalRulesetCmd.AddCommand(cmd)
cli.DefineServerFlags(flags)
}