/
deleteBucket.go
87 lines (68 loc) · 1.55 KB
/
deleteBucket.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package cmd
import (
"github.com/aws/aws-sdk-go/service/s3"
"github.com/paulmatencio/s3c/gLog"
"github.com/paulmatencio/s3c/api"
"github.com/paulmatencio/s3c/datatype"
"github.com/paulmatencio/s3c/utils"
"github.com/spf13/cobra"
)
// deleteBucketCmd represents the deleteBucket command
var (
dbshort = "Command to delete a bucket"
deleteBucketCmd = &cobra.Command{
Use: "delBucket",
Short: dbshort,
Long: ``,
// Hidden: true,
Run:deleteBucket,
}
removeBucketCmd = &cobra.Command{
Use: "rmBucket",
Short: dbshort,
Long: ``,
Run:deleteBucket,
}
rbCmd = &cobra.Command{
Use: "db",
Short: dbshort,
Long: ``,
Hidden: true,
Run:deleteBucket,
}
dbCmd = &cobra.Command{
Use: "rb",
Short: dbshort,
Hidden: true,
Long: ``,
Run:deleteBucket,
}
)
func initRbFlags(cmd *cobra.Command) {
cmd.Flags().StringVarP(&bucket,"bucket","b","","the name of the buket to be deleted")
}
func init() {
RootCmd.AddCommand(deleteBucketCmd)
RootCmd.AddCommand(dbCmd)
RootCmd.AddCommand(removeBucketCmd)
RootCmd.AddCommand(rbCmd)
initRbFlags(deleteBucketCmd)
initRbFlags(removeBucketCmd)
initRbFlags(rbCmd)
initRbFlags(dbCmd)
}
func deleteBucket(cmd *cobra.Command,args []string) (){
start := utils.LumberPrefix(cmd)
if len(bucket) == 0 {
gLog.Warning.Printf("%s",missingBucket)
return
}
req := datatype.DeleteBucketRequest {
Service : s3.New(api.CreateSession()),
Bucket : bucket,
}
if _,err := api.DeleteBucket(req); err != nil {
gLog.Error.Printf("Delete bucket fails [%v]",err)
}
utils.Return(start)
}