seaweedfs/weed/shell/command_collection_delete.go

72 lines
1.7 KiB
Go
Raw Normal View History

2019-05-30 16:47:54 +00:00
package shell
import (
"context"
"flag"
2019-05-30 16:47:54 +00:00
"fmt"
"io"
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
2019-05-30 16:47:54 +00:00
)
func init() {
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
2020-11-20 14:50:46 +00:00
collection.delete -collection <collection_name> -force
2019-05-30 16:47:54 +00:00
`
}
func (c *commandCollectionDelete) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
2019-05-30 16:47:54 +00:00
colDeleteCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
collectionName := colDeleteCommand.String("collection", "", "collection to delete. Use '_default_' for the empty-named collection.")
applyBalancing := colDeleteCommand.Bool("force", false, "apply the collection")
if err = colDeleteCommand.Parse(args); err != nil {
2019-05-30 16:47:54 +00:00
return nil
}
2022-05-31 21:48:46 +00:00
infoAboutSimulationMode(writer, *applyBalancing, "-force")
2019-05-30 16:47:54 +00:00
2021-12-10 21:24:38 +00:00
if err = commandEnv.confirmIsLocked(args); err != nil {
return
}
if *collectionName == "" {
return fmt.Errorf("empty collection name is not allowed")
}
if *collectionName == "_default_" {
*collectionName = ""
}
if !*applyBalancing {
fmt.Fprintf(writer, "collection '%s' will be deleted. Use -force to apply the change.\n", *collectionName)
return nil
}
2019-05-30 16:47:54 +00:00
err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
_, err = client.CollectionDelete(context.Background(), &master_pb.CollectionDeleteRequest{
Name: *collectionName,
2019-05-30 16:47:54 +00:00
})
return err
})
if err != nil {
return
}
2020-09-20 15:47:30 +00:00
fmt.Fprintf(writer, "collection %s is deleted.\n", *collectionName)
2019-05-30 16:47:54 +00:00
return nil
}