/
environment_cancel.go
56 lines (45 loc) · 1.7 KB
/
environment_cancel.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
package cmd
import (
"context"
"os"
"github.com/qovery/qovery-cli/utils"
"github.com/qovery/qovery-client-go"
"github.com/spf13/cobra"
)
var environmentCancelCmd = &cobra.Command{
Use: "cancel",
Short: "Cancel an environment deployment",
Run: func(cmd *cobra.Command, args []string) {
utils.Capture(cmd)
tokenType, token, err := utils.GetAccessToken()
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
client := utils.GetQoveryClient(tokenType, token)
_, _, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
_, _, err = client.EnvironmentActionsAPI.CancelEnvironmentDeployment(context.Background(), envId).Execute()
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
utils.Println("Environment is canceling!")
if watchFlag {
utils.WatchEnvironment(envId, qovery.STATEENUM_CANCELED, client)
}
},
}
func init() {
environmentCmd.AddCommand(environmentCancelCmd)
environmentCancelCmd.Flags().StringVarP(&organizationName, "organization", "", "", "Organization Name")
environmentCancelCmd.Flags().StringVarP(&projectName, "project", "", "", "Project Name")
environmentCancelCmd.Flags().StringVarP(&environmentName, "environment", "", "", "Environment Name")
environmentCancelCmd.Flags().BoolVarP(&watchFlag, "watch", "w", false, "Watch environment status until it's ready or an error occurs")
}