-
Notifications
You must be signed in to change notification settings - Fork 117
/
org.go
50 lines (40 loc) · 1.05 KB
/
org.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
package org
import (
"context"
"fmt"
"github.com/rilldata/rill/cli/pkg/cmdutil"
adminv1 "github.com/rilldata/rill/proto/gen/rill/admin/v1"
"github.com/spf13/cobra"
)
func OrgCmd(ch *cmdutil.Helper) *cobra.Command {
orgCmd := &cobra.Command{
Use: "org",
Short: "Manage organisations",
PersistentPreRunE: cmdutil.CheckAuth(ch),
}
orgCmd.AddCommand(CreateCmd(ch))
orgCmd.AddCommand(EditCmd(ch))
orgCmd.AddCommand(SwitchCmd(ch))
orgCmd.AddCommand(ListCmd(ch))
orgCmd.AddCommand(DeleteCmd(ch))
orgCmd.AddCommand(RenameCmd(ch))
return orgCmd
}
func orgNames(ctx context.Context, ch *cmdutil.Helper) ([]string, error) {
c, err := ch.Client()
if err != nil {
return nil, err
}
resp, err := c.ListOrganizations(ctx, &adminv1.ListOrganizationsRequest{})
if err != nil {
return nil, err
}
if len(resp.Organizations) == 0 {
return nil, fmt.Errorf("you are not a member of any orgs")
}
var orgNames []string
for _, org := range resp.Organizations {
orgNames = append(orgNames, org.Name)
}
return orgNames, nil
}