From 1f62ace524e70f825c3bed6eb504efaf8976f726 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Mon, 26 Jul 2021 15:43:35 +0200 Subject: [PATCH] refactor: use method to sort recipe apps listing --- cli/recipe.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cli/recipe.go b/cli/recipe.go index 7ca5e322..1a6bdccc 100644 --- a/cli/recipe.go +++ b/cli/recipe.go @@ -54,6 +54,15 @@ type App struct { type Apps map[string]App +func (a Apps) SortByName() []string { + var names []string + for name := range a { + names = append(names, name) + } + sort.Strings(names) + return names +} + var httpClient = &http.Client{Timeout: 5 * time.Second} var AppsUrl = "https://apps.coopcloud.tech" @@ -147,15 +156,6 @@ func ReadAppsWeb(target interface{}) error { return nil } -func SortByAppName(apps Apps) []string { - var names []string - for name := range apps { - names = append(names, name) - } - sort.Strings(names) - return names -} - var recipeListCommand = &cli.Command{ Name: "list", Aliases: []string{"ls"}, @@ -166,7 +166,7 @@ var recipeListCommand = &cli.Command{ } tableCol := []string{"Name", "Category", "Status"} table := createTable(tableCol) - for _, name := range SortByAppName(apps) { + for _, name := range apps.SortByName() { app := apps[name] status := fmt.Sprintf("%v", app.Features.Status) tableRow := []string{app.Name, app.Category, status}