mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
refactoring
This commit is contained in:
parent
0df6346611
commit
f08bbb72de
|
@ -24,22 +24,33 @@ func (c *commandCollectionList) Help() string {
|
||||||
|
|
||||||
func (c *commandCollectionList) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) {
|
func (c *commandCollectionList) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) {
|
||||||
|
|
||||||
|
collections, err := ListCollectionNames(commandEnv)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range collections {
|
||||||
|
fmt.Fprintf(writer, "collection:\"%s\"\n", c)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Fprintf(writer, "Total %d collections.\n", len(collections))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ListCollectionNames(commandEnv *commandEnv) (collections []string, err error) {
|
||||||
var resp *master_pb.CollectionListResponse
|
var resp *master_pb.CollectionListResponse
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
err = commandEnv.masterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error {
|
err = commandEnv.masterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error {
|
||||||
resp, err = client.CollectionList(ctx, &master_pb.CollectionListRequest{})
|
resp, err = client.CollectionList(ctx, &master_pb.CollectionListRequest{})
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range resp.Collections {
|
for _, c := range resp.Collections {
|
||||||
fmt.Fprintf(writer, "collection:\"%s\"\n", c.GetName())
|
collections = append(collections, c.Name)
|
||||||
}
|
}
|
||||||
|
return
|
||||||
fmt.Fprintf(writer, "Total %d collections.\n", len(resp.Collections))
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue