MCPcopy Create free account
hub / github.com/rilldata/rill / EditCmd

Function EditCmd

cli/cmd/service/edit.go:13–66  ·  view source on GitHub ↗
(ch *cmdutil.Helper)

Source from the content-addressed store, hash-verified

11)
12
13func EditCmd(ch *cmdutil.Helper) *cobra.Command {
14 var newName string
15 var attributes string
16
17 editCmd := &cobra.Command{
18 Use: "edit <service-name>",
19 Args: cobra.ExactArgs(1),
20 Short: "edit service properties",
21 RunE: func(cmd *cobra.Command, args []string) error {
22 client, err := ch.Client()
23 if err != nil {
24 return err
25 }
26
27 req := &adminv1.UpdateServiceRequest{
28 Name: args[0],
29 Org: ch.Org,
30 }
31
32 if newName != "" {
33 req.NewName = &newName
34 }
35
36 if cmd.Flags().Changed("attributes") {
37 if attributes == "" {
38 attributes = "{}" // Default to empty JSON object if not provided
39 }
40 var attrs map[string]any
41 if err = json.Unmarshal([]byte(attributes), &attrs); err != nil {
42 return fmt.Errorf("failed to parse --attributes as JSON: %w", err)
43 }
44 req.Attributes, err = structpb.NewStruct(attrs)
45 if err != nil {
46 return fmt.Errorf("failed to convert attributes to struct: %w", err)
47 }
48 }
49
50 res, err := client.UpdateService(cmd.Context(), req)
51 if err != nil {
52 return err
53 }
54
55 ch.PrintfSuccess("Updated service\n")
56 ch.PrintServices([]*adminv1.Service{res.Service})
57
58 return nil
59 },
60 }
61 editCmd.Flags().SortFlags = false
62 editCmd.Flags().StringVar(&newName, "new-name", "", "New service name")
63 editCmd.Flags().StringVar(&attributes, "attributes", "", "JSON object of key-value pairs for service attributes")
64
65 return editCmd
66}

Callers 1

ServiceCmdFunction · 0.70

Calls 6

PrintfSuccessMethod · 0.80
PrintServicesMethod · 0.80
ErrorfMethod · 0.65
UpdateServiceMethod · 0.65
ContextMethod · 0.65
ClientMethod · 0.45

Tested by

no test coverage detected