Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/local-app/cmd/organization-list.go
2497 views
1
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package cmd
6
7
import (
8
"context"
9
"time"
10
11
"github.com/bufbuild/connect-go"
12
v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1"
13
"github.com/gitpod-io/local-app/pkg/prettyprint"
14
"github.com/spf13/cobra"
15
)
16
17
// organizationListCmd lists all available organizations
18
var organizationListCmd = &cobra.Command{
19
Use: "list",
20
Short: "Lists organizations",
21
Aliases: []string{"ls"},
22
RunE: func(cmd *cobra.Command, args []string) error {
23
ctx, cancel := context.WithTimeout(cmd.Context(), 5*time.Second)
24
defer cancel()
25
26
gitpod, err := getGitpodClient(ctx)
27
if err != nil {
28
return err
29
}
30
31
orgs, err := gitpod.Teams.ListTeams(ctx, connect.NewRequest(&v1.ListTeamsRequest{}))
32
if err != nil {
33
return err
34
}
35
36
res := make([]tabularTeam, 0, len(orgs.Msg.GetTeams()))
37
for _, org := range orgs.Msg.GetTeams() {
38
res = append(res, tabularTeam{
39
ID: org.Id,
40
Name: org.Name,
41
})
42
}
43
return WriteTabular(res, organizationListOpts.Format, prettyprint.WriterFormatWide)
44
},
45
}
46
47
type tabularTeam struct {
48
ID string `print:"id"`
49
Name string `print:"name"`
50
}
51
52
var organizationListOpts struct {
53
Format formatOpts
54
}
55
56
func init() {
57
organizationCmd.AddCommand(organizationListCmd)
58
addFormatFlags(organizationListCmd, &organizationListOpts.Format)
59
}
60
61