2019-05-31 00:47:54 +08:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-06-05 16:30:24 +08:00
|
|
|
Commands = append(Commands, &commandCollectionDelete{})
|
2019-05-31 00:47:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type commandCollectionDelete struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandCollectionDelete) Name() string {
|
|
|
|
return "collection.delete"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandCollectionDelete) Help() string {
|
|
|
|
return `delete specified collection
|
|
|
|
|
|
|
|
collection.delete <collection_name>
|
|
|
|
|
|
|
|
`
|
|
|
|
}
|
|
|
|
|
2019-06-05 16:30:24 +08:00
|
|
|
func (c *commandCollectionDelete) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
2019-05-31 00:47:54 +08:00
|
|
|
|
|
|
|
if len(args) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
collectionName := args[0]
|
|
|
|
|
2020-02-26 13:50:12 +08:00
|
|
|
err = commandEnv.MasterClient.WithClient(func(client master_pb.SeaweedClient) error {
|
|
|
|
_, err = client.CollectionDelete(context.Background(), &master_pb.CollectionDeleteRequest{
|
2019-05-31 00:47:54 +08:00
|
|
|
Name: collectionName,
|
|
|
|
})
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(writer, "collection %s is deleted.\n", collectionName)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|