-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathremove.go
44 lines (37 loc) · 1.14 KB
/
remove.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
package remove
import (
"context"
"github.com/itera-io/taikun-cli/cmd/cmderr"
"github.com/itera-io/taikun-cli/cmd/cmdutils"
"github.com/itera-io/taikun-cli/utils/out"
tk "github.com/itera-io/taikungoclient"
"github.com/spf13/cobra"
)
func NewCmdDelete() *cobra.Command {
cmd := cobra.Command{
Use: "delete <billing-rule-id>...",
Short: "Delete one or more billing rules",
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
ids, err := cmdutils.ArgsToNumericalIDs(args)
if err != nil {
return cmderr.ErrIDArgumentNotANumber
}
return cmdutils.DeleteMultiple(ids, deleteRun)
},
Aliases: cmdutils.DeleteAliases,
}
return &cmd
}
func deleteRun(billingRuleID int32) (err error) {
// Create and authenticated client to the Taikun API
myApiClient := tk.NewClient()
// Execute a query into the API + graceful exit
response, err := myApiClient.Client.PrometheusRulesAPI.PrometheusrulesDelete(context.TODO(), billingRuleID).Execute()
if err != nil {
return tk.CreateError(response, err)
}
// Manipulate the gathered data
out.PrintDeleteSuccess("Billing rule", billingRuleID)
return
}