forked from toolshed/abra
WIP: app list command sorting
This commit is contained in:
21
cli/app.go
21
cli/app.go
@ -3,6 +3,7 @@ package cli
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"coopcloud.tech/abra/client"
|
||||
@ -51,29 +52,25 @@ var appRestoreCommand = &cli.Command{
|
||||
var appListCommand = &cli.Command{
|
||||
Name: "list",
|
||||
Aliases: []string{"ls"},
|
||||
Flags: []cli.Flag{StatusFlag, ServerFlag, TypeFlag},
|
||||
Flags: []cli.Flag{StatusFlag, ServerFlag, TypeFlag}, // FIXME: implement flags
|
||||
Action: func(c *cli.Context) error {
|
||||
// FIXME: Needs status flag implementing
|
||||
// TODO: Sorting of output to make servers in alphabetical
|
||||
// Looks like sorting a 2d slice of strings might be messy though
|
||||
apps, err := config.LoadAppFiles(Server)
|
||||
appFiles, err := config.LoadAppFiles(Server)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
tableCol := []string{"Name", "Type", "Server"}
|
||||
apps, err := config.GetApps(appFiles)
|
||||
sort.Sort(config.ByServer(apps))
|
||||
tableCol := []string{"Server", "Type", "Name"}
|
||||
table := createTable(tableCol)
|
||||
for name, appFile := range apps {
|
||||
app, err := config.GetApp(apps, name)
|
||||
if err != nil {
|
||||
logrus.Fatal(err.Error())
|
||||
}
|
||||
for _, app := range apps {
|
||||
if app.Type == Type || Type == "" {
|
||||
// If type flag is set, check for it, if not, Type == ""
|
||||
tableRow := []string{name, app.Type, appFile.Server}
|
||||
tableRow := []string{app.File.Server, app.Type, app.Name}
|
||||
table.Append(tableRow)
|
||||
}
|
||||
|
||||
}
|
||||
table.SetAutoMergeCells(true)
|
||||
table.Render()
|
||||
return nil
|
||||
},
|
||||
|
Reference in New Issue
Block a user