cmd/hakurei/print: serialise array for ps
All checks were successful
Test / Create distribution (push) Successful in 35s
Test / Sandbox (push) Successful in 40s
Test / Sandbox (race detector) (push) Successful in 42s
Test / Hakurei (push) Successful in 2m25s
Test / Hakurei (race detector) (push) Successful in 3m7s
Test / Hpkg (push) Successful in 3m13s
Test / Flake checks (push) Successful in 1m27s

Wanted to do this for a long time, since the key is redundant. This also makes it easier to migrate to the new store interface.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2025-11-02 16:15:09 +09:00
parent 23ae7822bf
commit 0e5ca74b98
5 changed files with 55 additions and 11 deletions

View File

@@ -1,9 +1,11 @@
package main
import (
"bytes"
"fmt"
"io"
"log"
"maps"
"slices"
"strconv"
"strings"
@@ -177,10 +179,8 @@ func printPs(output io.Writer, now time.Time, s store.Compat, short, flagJSON bo
}
if !short && flagJSON {
es := make(map[string]*hst.State, len(entries))
for id, instance := range entries {
es[id.String()] = instance
}
es := slices.Collect(maps.Values(entries))
slices.SortFunc(es, func(a, b *hst.State) int { return bytes.Compare(a.ID[:], b.ID[:]) })
encodeJSON(log.Fatal, output, short, es)
return
}