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.

56 lines
1.2 KiB

6 years ago
6 years ago
6 years ago
6 years ago
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. collections, err := ListCollectionNames(commandEnv)
  21. if err != nil {
  22. return err
  23. }
  24. for _, c := range collections {
  25. fmt.Fprintf(writer, "collection:\"%s\"\n", c)
  26. }
  27. fmt.Fprintf(writer, "Total %d collections.\n", len(collections))
  28. return nil
  29. }
  30. func ListCollectionNames(commandEnv *commandEnv) (collections []string, err error) {
  31. var resp *master_pb.CollectionListResponse
  32. ctx := context.Background()
  33. err = commandEnv.masterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error {
  34. resp, err = client.CollectionList(ctx, &master_pb.CollectionListRequest{})
  35. return err
  36. })
  37. if err != nil {
  38. return
  39. }
  40. for _, c := range resp.Collections {
  41. collections = append(collections, c.Name)
  42. }
  43. return
  44. }