command_collection_delete.go 962 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package shell
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
  6. "io"
  7. )
  8. func init() {
  9. Commands = append(Commands, &commandCollectionDelete{})
  10. }
  11. type commandCollectionDelete struct {
  12. }
  13. func (c *commandCollectionDelete) Name() string {
  14. return "collection.delete"
  15. }
  16. func (c *commandCollectionDelete) Help() string {
  17. return `delete specified collection
  18. collection.delete <collection_name>
  19. `
  20. }
  21. func (c *commandCollectionDelete) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  22. if len(args) == 0 {
  23. return nil
  24. }
  25. collectionName := args[0]
  26. ctx := context.Background()
  27. err = commandEnv.MasterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error {
  28. _, err = client.CollectionDelete(ctx, &master_pb.CollectionDeleteRequest{
  29. Name: collectionName,
  30. })
  31. return err
  32. })
  33. if err != nil {
  34. return
  35. }
  36. fmt.Fprintf(writer, "collection %s is deleted.\n", collectionName)
  37. return nil
  38. }