From fde8786fc16acca7ea3eda09e9efc3c000589ab5 Mon Sep 17 00:00:00 2001 From: amela Date: Tue, 22 Oct 2024 11:29:07 +0200 Subject: [PATCH] feat(cmd/network/status): Sort paratimes --- cmd/network/status.go | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/cmd/network/status.go b/cmd/network/status.go index 80ca427f..7318be13 100644 --- a/cmd/network/status.go +++ b/cmd/network/status.go @@ -3,12 +3,15 @@ package network import ( "context" "fmt" + "sort" "strings" "time" "github.com/spf13/cobra" flag "github.com/spf13/pflag" + coreCommon "github.com/oasisprotocol/oasis-core/go/common" + "github.com/oasisprotocol/oasis-sdk/client-sdk/go/connection" "github.com/oasisprotocol/cli/cmd/common" @@ -132,7 +135,31 @@ var ( fmt.Println("==== ParaTimes ====") } - for _, runtime := range nodeStatus.Runtimes { + keys := make([]coreCommon.Namespace, 0, len(nodeStatus.Runtimes)) + for key := range nodeStatus.Runtimes { + keys = append(keys, key) + } + sort.Slice(keys, func(i, j int) bool { + var iParatimeName, jParatimeName string + + iDescriptor := nodeStatus.Runtimes[keys[i]].Descriptor + jDescriptor := nodeStatus.Runtimes[keys[j]].Descriptor + + if iDescriptor != nil { + iDescriptorID := iDescriptor.ID.String() + iParatimeName = getParatimeName(cfg, iDescriptorID) + iDescriptorID + } + + if jDescriptor != nil { + jDescriptorID := jDescriptor.ID.String() + jParatimeName = getParatimeName(cfg, jDescriptorID) + jDescriptorID + } + + return iParatimeName < jParatimeName + }) + + for _, key := range keys { + runtime := nodeStatus.Runtimes[key] descriptor := runtime.Descriptor if descriptor != nil { paratimeName := getParatimeName(cfg, descriptor.ID.String())