feat: abra server ls

WE DID IT! The first actual command to be ported.

Code is still a mess in terms of UX but its a milestone!
This commit is contained in:
2021-07-18 04:21:26 +01:00
parent e13948f37e
commit 38f610bdec
5 changed files with 239 additions and 15 deletions

View File

@ -3,6 +3,8 @@ package cli
import (
"fmt"
"coopcloud.tech/abra/client"
"coopcloud.tech/abra/config"
"github.com/urfave/cli/v2"
)
@ -12,6 +14,33 @@ var serverListCommand = &cli.Command{
Usage: "List locally-defined servers.",
ArgsUsage: emptyArgsUsage,
HideHelp: true,
Action: func(c *cli.Context) error {
dockerContextStore := client.NewDefaultDockerContextStore()
contexts, err := dockerContextStore.Store.List()
if err != nil {
panic(err)
}
tableColumns := []string{"Name", "Connection"}
table := createTable(tableColumns)
defer table.Render()
serverNames := config.ReadServerNames()
for _, serverName := range serverNames {
var row []string
for _, ctx := range contexts {
if ctx.Name == serverName {
row = []string{serverName, client.GetContextEndpoint(ctx)}
}
}
if len(row) == 0 {
row = []string{serverName, "UNKNOWN"}
}
table.Append(row)
}
return nil
},
}
var serverAddCommand = &cli.Command{