-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlist-teams.go
More file actions
61 lines (51 loc) · 1.21 KB
/
list-teams.go
File metadata and controls
61 lines (51 loc) · 1.21 KB
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
/*
Copyright © 2025 Codesphere Inc. <support@codesphere.com>
*/
package cmd
import (
"fmt"
"github.com/codesphere-cloud/cs-go/pkg/out"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/spf13/cobra"
)
type ListTeamsCmd struct {
cmd *cobra.Command
opts GlobalOptions
}
func addListTeamsCmd(p *cobra.Command, opts GlobalOptions) {
l := ListTeamsCmd{
cmd: &cobra.Command{
Use: "teams",
Short: "list teams",
Long: `list teams available in Codesphere`,
Example: `
List all teams:
$ cs list teams
`,
},
opts: opts,
}
l.cmd.RunE = l.RunE
p.AddCommand(l.cmd)
}
func (l *ListTeamsCmd) RunE(_ *cobra.Command, args []string) (err error) {
client, err := NewClient(l.opts)
if err != nil {
return fmt.Errorf("failed to create Codesphere client: %e", err)
}
teams, err := client.ListTeams()
if err != nil {
return fmt.Errorf("failed to list teams: %e", err)
}
t := out.GetTableWriter()
t.AppendHeader(table.Row{"P", "ID", "Name", "Role", "Default DC"})
for _, team := range teams {
first := ""
if team.IsFirst != nil && *team.IsFirst {
first = "*"
}
t.AppendRow(table.Row{first, team.Id, team.Name, GetRoleName(int(team.Role)), team.DefaultDataCenterId})
}
t.Render()
return nil
}