-
Notifications
You must be signed in to change notification settings - Fork 117
/
edit.go
80 lines (66 loc) · 1.99 KB
/
edit.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
70
71
72
73
74
75
76
77
78
79
80
package org
import (
"fmt"
"github.com/rilldata/rill/cli/pkg/cmdutil"
"github.com/rilldata/rill/cli/pkg/config"
adminv1 "github.com/rilldata/rill/proto/gen/rill/admin/v1"
"github.com/spf13/cobra"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func EditCmd(cfg *config.Config) *cobra.Command {
var orgName, description string
editCmd := &cobra.Command{
Use: "edit",
Args: cobra.NoArgs,
Short: "Edit organization details",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
client, err := cmdutil.Client(cfg)
if err != nil {
return err
}
defer client.Close()
if !cmd.Flags().Changed("org") {
orgNames, err := cmdutil.OrgNames(ctx, client)
if err != nil {
return err
}
orgName = cmdutil.SelectPrompt("Select org to edit", orgNames, cfg.Org)
}
if !cmd.Flags().Changed("description") {
// Get the new org description from user if not provided in the flag
description, err = cmdutil.InputPrompt("Enter the org description", description)
if err != nil {
return err
}
}
resp, err := client.GetOrganization(ctx, &adminv1.GetOrganizationRequest{Name: orgName})
if err != nil {
if st, ok := status.FromError(err); ok {
if st.Code() != codes.NotFound {
return err
}
}
fmt.Printf("Org name %q doesn't exist, please run `rill org list` to list available orgs\n", orgName)
return nil
}
org := resp.Organization
updatedOrg, err := client.UpdateOrganization(ctx, &adminv1.UpdateOrganizationRequest{
Id: org.Id,
Name: org.Name,
Description: description,
})
if err != nil {
return err
}
cmdutil.SuccessPrinter("Updated organization")
cmdutil.TablePrinter(toRow(updatedOrg.Organization))
return nil
},
}
editCmd.Flags().SortFlags = false
editCmd.Flags().StringVar(&orgName, "org", cfg.Org, "Organization name")
editCmd.Flags().StringVar(&description, "description", "", "Description")
return editCmd
}