generated from brevdev/seed
-
Notifications
You must be signed in to change notification settings - Fork 10
/
workspacegroups.go
69 lines (61 loc) · 1.76 KB
/
workspacegroups.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package workspacegroups
import (
"os"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/spf13/cobra"
"github.com/brevdev/brev-cli/pkg/entity"
breverrors "github.com/brevdev/brev-cli/pkg/errors"
"github.com/brevdev/brev-cli/pkg/terminal"
)
type WorkspaceGroupsStore interface {
GetWorkspaceGroups(organizationID string) ([]entity.WorkspaceGroup, error)
GetActiveOrganizationOrDefault() (*entity.Organization, error)
}
func NewCmdWorkspaceGroups(t *terminal.Terminal, store WorkspaceGroupsStore) *cobra.Command {
cmd := &cobra.Command{
Use: "workspacegroups",
DisableFlagsInUseLine: true,
Short: "TODO",
Long: "TODO",
Example: "TODO",
RunE: func(cmd *cobra.Command, args []string) error {
err := RunWorkspaceGroups(t, args, store)
if err != nil {
return breverrors.WrapAndTrace(err)
}
return nil
},
}
return cmd
}
func RunWorkspaceGroups(_ *terminal.Terminal, _ []string, store WorkspaceGroupsStore) error {
org, err := store.GetActiveOrganizationOrDefault()
if err != nil {
return breverrors.WrapAndTrace(err)
}
wsgs, err := store.GetWorkspaceGroups(org.ID)
if err != nil {
return breverrors.WrapAndTrace(err)
}
ta := table.NewWriter()
ta.SetOutputMirror(os.Stdout)
ta.Style().Options = getBrevTableOptions()
header := table.Row{"NAME", "PLATFORM ID", "PLATFORM TYPE"}
ta.AppendHeader(header)
for _, w := range wsgs {
workspaceRow := []table.Row{{
w.Name, w.PlatformID, w.Platform,
}}
ta.AppendRows(workspaceRow)
}
ta.Render()
return nil
}
func getBrevTableOptions() table.Options {
options := table.OptionsDefault
options.DrawBorder = false
options.SeparateColumns = false
options.SeparateRows = false
options.SeparateHeader = false
return options
}