(ch *cmdutil.Helper)
| 11 | ) |
| 12 | |
| 13 | func 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 | } |
no test coverage detected