command_collection_delete.go 945 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. err = commandEnv.MasterClient.WithClient(func(client master_pb.SeaweedClient) error {
  27. _, err = client.CollectionDelete(context.Background(), &master_pb.CollectionDeleteRequest{
  28. Name: collectionName,
  29. })
  30. return err
  31. })
  32. if err != nil {
  33. return
  34. }
  35. fmt.Fprintf(writer, "collection %s is deleted.\n", collectionName)
  36. return nil
  37. }