You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
960 B

6 years ago
6 years ago
6 years ago
6 years ago
  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, &commandCollectionList{})
  10. }
  11. type commandCollectionList struct {
  12. }
  13. func (c *commandCollectionList) Name() string {
  14. return "collection.list"
  15. }
  16. func (c *commandCollectionList) Help() string {
  17. return `list all collections`
  18. }
  19. func (c *commandCollectionList) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) {
  20. var resp *master_pb.CollectionListResponse
  21. ctx := context.Background()
  22. err = commandEnv.masterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error {
  23. resp, err = client.CollectionList(ctx, &master_pb.CollectionListRequest{})
  24. return err
  25. })
  26. if err != nil {
  27. return err
  28. }
  29. for _, c := range resp.Collections {
  30. fmt.Fprintf(writer, "collection:\"%s\"\n", c.GetName())
  31. }
  32. fmt.Fprintf(writer, "Total %d collections.\n", len(resp.Collections))
  33. return nil
  34. }