[#333] Sort containers by ID
All checks were successful
DCO action / DCO (pull_request) Successful in 1m23s
Vulncheck / Vulncheck (pull_request) Successful in 2m46s
Build / Build Components (1.20) (pull_request) Successful in 4m45s
Tests and linters / Staticcheck (pull_request) Successful in 5m30s
Tests and linters / Tests (1.20) (pull_request) Successful in 5m59s
Tests and linters / Tests (1.21) (pull_request) Successful in 5m56s
Tests and linters / Tests with -race (pull_request) Successful in 5m56s
Tests and linters / Lint (pull_request) Successful in 6m13s
Build / Build Components (1.21) (pull_request) Successful in 7m5s

Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
This commit is contained in:
Ekaterina Lebedeva 2023-09-25 09:58:26 +03:00
parent c14c9a023c
commit b8c3c2486d
2 changed files with 11 additions and 1 deletions

View file

@ -71,6 +71,16 @@ func ListContainers(ctx context.Context, prm ListContainersPrm) (res ListContain
return
}
// SortedIDList returns sorted list of identifiers of user's containers.
func (x ListContainersRes) SortedIDList() []cid.ID {
list := x.cliRes.Containers()
sort.Slice(list, func(i, j int) bool {
lhs, rhs := list[i].EncodeToString(), list[j].EncodeToString()
return strings.Compare(lhs, rhs) < 0
})
return list
}
// PutContainerPrm groups parameters of PutContainer operation.
type PutContainerPrm struct {
Client *client.Client

View file

@ -56,7 +56,7 @@ var listContainersCmd = &cobra.Command{
Client: cli,
}
containerIDs := res.IDList()
containerIDs := res.SortedIDList()
for _, cnrID := range containerIDs {
if flagVarListName == "" && !flagVarListPrintAttr {
cmd.Println(cnrID.String())