Skip to content

Commit

Permalink
feat: cli: sort actor CIDs alphabetically before printing (#11345)
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek authored Oct 24, 2023
1 parent 2d8dbf5 commit 018c4e8
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions cli/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1920,8 +1920,29 @@ var StateSysActorCIDsCmd = &cli.Command{
if err != nil {
return err
}
for name, cid := range actorsCids {
_, _ = fmt.Fprintf(tw, "%v\t%v\n", name, cid)

var actorsCidTuples []struct {
actorName string
actorCid cid.Cid
}

for name, actorCid := range actorsCids {
keyVal := struct {
actorName string
actorCid cid.Cid
}{
actorName: name,
actorCid: actorCid,
}
actorsCidTuples = append(actorsCidTuples, keyVal)
}

sort.Slice(actorsCidTuples, func(i, j int) bool {
return actorsCidTuples[i].actorName < actorsCidTuples[j].actorName
})

for _, keyVal := range actorsCidTuples {
_, _ = fmt.Fprintf(tw, "%v\t%v\n", keyVal.actorName, keyVal.actorCid)
}
return tw.Flush()
},
Expand Down

0 comments on commit 018c4e8

Please sign in to comment.