Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/local-app/cmd/organization-get.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/config"
14
"github.com/gitpod-io/local-app/pkg/prettyprint"
15
"github.com/spf13/cobra"
16
)
17
18
// organizationGetCmd gets a single organization
19
var organizationGetCmd = &cobra.Command{
20
Use: "get [organization-id]",
21
Short: "Retrieves metadata about a given organization",
22
Args: cobra.MaximumNArgs(1),
23
RunE: func(cmd *cobra.Command, args []string) error {
24
if len(args) < 1 {
25
cfg := config.FromContext(cmd.Context())
26
gpctx, err := cfg.GetActiveContext()
27
if err != nil {
28
return err
29
}
30
args = append(args, gpctx.OrganizationID)
31
}
32
33
var organizations []tabularTeam
34
for _, orgId := range args {
35
if len(orgId) == 0 {
36
return cmd.Help()
37
}
38
39
ctx, cancel := context.WithTimeout(cmd.Context(), 5*time.Second)
40
defer cancel()
41
42
gitpod, err := getGitpodClient(ctx)
43
if err != nil {
44
return err
45
}
46
47
orgs, err := gitpod.Teams.GetTeam(ctx, connect.NewRequest(&v1.GetTeamRequest{TeamId: orgId}))
48
if err != nil {
49
return err
50
}
51
52
organizations = append(organizations, tabularTeam{
53
ID: orgs.Msg.GetTeam().Id,
54
Name: orgs.Msg.GetTeam().Name,
55
})
56
}
57
return WriteTabular(organizations, organizationGetOpts.Format, prettyprint.WriterFormatNarrow)
58
},
59
}
60
61
var organizationGetOpts struct {
62
Format formatOpts
63
}
64
65
func init() {
66
organizationCmd.AddCommand(organizationGetCmd)
67
addFormatFlags(organizationGetCmd, &organizationGetOpts.Format)
68
}
69
70