This repository has been archived by the owner on Oct 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster_delete.go
68 lines (58 loc) · 1.73 KB
/
cluster_delete.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
66
67
68
package command
import (
"flag"
"fmt"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/awsutil"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/takasing/screwdriver/aws"
"github.com/takasing/screwdriver/utils"
)
// ClusterDeleteCommand is a Command implementation used to
// delete ECS cluster.
type ClusterDeleteCommand struct{}
// Run is Command implementation method for ClusterDeleteCommand.
func (c *ClusterDeleteCommand) Run(args []string) int {
var name string
flags := flag.NewFlagSet("cluster", flag.ContinueOnError)
flags.StringVar(&name, "name", "", "cluster name")
flags.Usage = func() { c.Help() }
if err := flags.Parse(args); err != nil {
utils.ErrorOutputf("Error parsing CLI flags: %s", err)
fmt.Println(c.Help())
return 1
}
if name == "" {
utils.ErrorOutput("Error: -name option required.")
return 1
}
input := &ecs.DeleteClusterInput{
Cluster: &name,
}
client := aws.GetClient()
resp, err := client.ClusterDelete(input)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
utils.ErrorOutput(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
if reqErr, ok := err.(awserr.RequestFailure); ok {
utils.ErrorOutput(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
}
} else {
utils.ErrorOutput(err.Error())
}
return 1
}
fmt.Println(awsutil.StringValue(resp))
return 0
}
// Help show Command implementation method for ClusterDeleteCommand.
func (c *ClusterDeleteCommand) Help() string {
return `
Usage: screwdriver cluster delete [options]
-name The name of the ECS cluster.
`
}
// Synopsis Command implementation method for ClusterDeleteCommand.
func (c *ClusterDeleteCommand) Synopsis() string {
return "delete ECS cluster"
}