You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.1 KiB

5 years ago
5 years ago
  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)
  40. }