fix: sort by server and type for app listing

This commit is contained in:
decentral1se 2021-07-26 19:47:44 +02:00
parent 8656ae947a
commit 5def18a9af
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
2 changed files with 13 additions and 1 deletions

View File

@ -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})

View File

@ -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) }