From 5def18a9af03d66f75fda324327704486bcfe626 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Mon, 26 Jul 2021 19:47:44 +0200 Subject: [PATCH] fix: sort by server and type for app listing --- cli/app.go | 2 +- config/env.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cli/app.go b/cli/app.go index d4559e616..b021618cc 100644 --- a/cli/app.go +++ b/cli/app.go @@ -59,7 +59,7 @@ var appListCommand = &cli.Command{ logrus.Fatal(err) } apps, err := config.GetApps(appFiles) - sort.Sort(config.ByServer(apps)) + sort.Sort(config.ByServerAndType(apps)) tableCol := []string{"Server", "Type", "Name"} table := createTable(tableCol) table.SetAutoMergeCellsByColumnIndex([]int{0}) diff --git a/config/env.go b/config/env.go index 015ea5ba2..ca596b0ef 100644 --- a/config/env.go +++ b/config/env.go @@ -40,6 +40,18 @@ func (a ByServer) Less(i, j int) bool { return strings.ToLower(a[i].File.Server) < strings.ToLower(a[j].File.Server) } +type ByServerAndType []App + +func (a ByServerAndType) Len() int { return len(a) } +func (a ByServerAndType) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a ByServerAndType) Less(i, j int) bool { + if a[i].File.Server == a[j].File.Server { + return strings.ToLower(a[i].Type) < strings.ToLower(a[j].Type) + } else { + return strings.ToLower(a[i].File.Server) < strings.ToLower(a[j].File.Server) + } +} + type ByType []App func (a ByType) Len() int { return len(a) }