command_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, &commandBucketDelete{})
  10. }
  11. type commandBucketDelete struct {
  12. }
  13. func (c *commandBucketDelete) Name() string {
  14. return "bucket.delete"
  15. }
  16. func (c *commandBucketDelete) Help() string {
  17. return `delete a bucket by a given name
  18. bucket.delete -name <bucket_name>
  19. `
  20. }
  21. func (c *commandBucketDelete) 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. }