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.

59 lines
1.3 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, true, true)
  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, includeNormalVolumes, includeEcVolumes bool) (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. IncludeNormalVolumes: includeNormalVolumes,
  36. IncludeEcVolumes: includeEcVolumes,
  37. })
  38. return err
  39. })
  40. if err != nil {
  41. return
  42. }
  43. for _, c := range resp.Collections {
  44. collections = append(collections, c.Name)
  45. }
  46. return
  47. }