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