command_collection_delete.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package shell
  2. import (
  3. "context"
  4. "flag"
  5. "fmt"
  6. "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
  7. "io"
  8. )
  9. func init() {
  10. Commands = append(Commands, &commandCollectionDelete{})
  11. }
  12. type commandCollectionDelete struct {
  13. }
  14. func (c *commandCollectionDelete) Name() string {
  15. return "collection.delete"
  16. }
  17. func (c *commandCollectionDelete) Help() string {
  18. return `delete specified collection
  19. collection.delete -collectin <collection_name> -force
  20. `
  21. }
  22. func (c *commandCollectionDelete) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  23. if err = commandEnv.confirmIsLocked(); err != nil {
  24. return
  25. }
  26. colDeleteCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  27. collectionName := colDeleteCommand.String("collection", "", "collection to delete")
  28. applyBalancing := colDeleteCommand.Bool("force", false, "apply the collection")
  29. if err = colDeleteCommand.Parse(args); err != nil {
  30. return nil
  31. }
  32. if !*applyBalancing {
  33. fmt.Fprintf(writer, "collection %s will be deleted. Use -force to apply the change.\n", *collectionName)
  34. return nil
  35. }
  36. err = commandEnv.MasterClient.WithClient(func(client master_pb.SeaweedClient) error {
  37. _, err = client.CollectionDelete(context.Background(), &master_pb.CollectionDeleteRequest{
  38. Name: *collectionName,
  39. })
  40. return err
  41. })
  42. if err != nil {
  43. return
  44. }
  45. fmt.Fprintf(writer, "collection %s is deleted.\n", *collectionName)
  46. return nil
  47. }