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.

39 lines
720 B

6 years ago
  1. package shell
  2. import (
  3. "context"
  4. "fmt"
  5. "io"
  6. )
  7. func init() {
  8. commands = append(commands, &commandCollectionList{})
  9. }
  10. type commandCollectionList struct {
  11. }
  12. func (c *commandCollectionList) Name() string {
  13. return "collection.list"
  14. }
  15. func (c *commandCollectionList) Help() string {
  16. return "# list all collections"
  17. }
  18. func (c *commandCollectionList) Do(args []string, commandEnv *commandEnv, writer io.Writer) error {
  19. resp, err := commandEnv.masterClient.CollectionList(context.Background())
  20. if err != nil {
  21. return err
  22. }
  23. for _, c := range resp.Collections {
  24. fmt.Fprintf(writer, "collection:\"%s\"\n", c.GetName())
  25. }
  26. fmt.Fprintf(writer, "Total %d collections.\n", len(resp.Collections))
  27. return nil
  28. }