command_s3_bucket_delete.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package shell
  2. import (
  3. "flag"
  4. "fmt"
  5. "io"
  6. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  7. )
  8. func init() {
  9. Commands = append(Commands, &commandS3BucketDelete{})
  10. }
  11. type commandS3BucketDelete struct {
  12. }
  13. func (c *commandS3BucketDelete) Name() string {
  14. return "s3.bucket.delete"
  15. }
  16. func (c *commandS3BucketDelete) Help() string {
  17. return `delete a bucket by a given name
  18. s3.bucket.delete -name <bucket_name>
  19. `
  20. }
  21. func (c *commandS3BucketDelete) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  22. bucketCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  23. bucketName := bucketCommand.String("name", "", "bucket name")
  24. if err = bucketCommand.Parse(args); err != nil {
  25. return nil
  26. }
  27. if *bucketName == "" {
  28. return fmt.Errorf("empty bucket name")
  29. }
  30. _, parseErr := commandEnv.parseUrl(findInputDirectory(bucketCommand.Args()))
  31. if parseErr != nil {
  32. return parseErr
  33. }
  34. var filerBucketsPath string
  35. filerBucketsPath, err = readFilerBucketsPath(commandEnv)
  36. if err != nil {
  37. return fmt.Errorf("read buckets: %v", err)
  38. }
  39. return filer_pb.Remove(commandEnv, filerBucketsPath, *bucketName, false, true, true, false, nil)
  40. }