Skip to content

Commit

Permalink
sort transports listed by skywire-cli list-transports command
Browse files Browse the repository at this point in the history
  • Loading branch information
mungujn committed Apr 1, 2019
1 parent 5d5f0d7 commit 6971872
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmd/skywire-cli/commands/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"text/tabwriter"
"time"
"sort"

"github.com/google/uuid"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -155,6 +156,7 @@ func init() {
}

func printTransports(tps ...*node.TransportSummary) {
sortTransports(tps...)
w := tabwriter.NewWriter(os.Stdout, 0, 0, 5, ' ', tabwriter.TabIndent)
_, err := fmt.Fprintln(w, "type\tid\tlocal\tremote")
catch(err)
Expand All @@ -176,3 +178,9 @@ func printTransportEntries(entries ...*transport.EntryWithStatus) {
}
catch(w.Flush())
}

func sortTransports(tps ...*node.TransportSummary) {
sort.Slice(tps, func(i, j int) bool {
return tps[i].ID.String() < tps[j].ID.String()
})
}

0 comments on commit 6971872

Please sign in to comment.