(ch *cmdutil.Helper)
| 7 | ) |
| 8 | |
| 9 | func EditCmd(ch *cmdutil.Helper) *cobra.Command { |
| 10 | var plan string |
| 11 | var force bool |
| 12 | |
| 13 | editCmd := &cobra.Command{ |
| 14 | Use: "edit", |
| 15 | Args: cobra.NoArgs, |
| 16 | Short: "Edit organization subscription", |
| 17 | RunE: func(cmd *cobra.Command, args []string) error { |
| 18 | ctx := cmd.Context() |
| 19 | |
| 20 | client, err := ch.Client() |
| 21 | if err != nil { |
| 22 | return err |
| 23 | } |
| 24 | |
| 25 | subResp, err := client.GetBillingSubscription(ctx, &adminv1.GetBillingSubscriptionRequest{ |
| 26 | Org: ch.Org, |
| 27 | SuperuserForceAccess: force, |
| 28 | }) |
| 29 | if err != nil { |
| 30 | return err |
| 31 | } |
| 32 | |
| 33 | if subResp.Subscription == nil { |
| 34 | ch.PrintfWarn("Organization %q has no subscription\n", ch.Org) |
| 35 | } else { |
| 36 | ch.PrintfBold("Organization %q has the following subscription\n", ch.Org) |
| 37 | ch.PrintSubscriptions([]*adminv1.Subscription{subResp.Subscription}) |
| 38 | } |
| 39 | |
| 40 | ch.PrintfWarn("\nEditing plan for organization %q. Plan change will take place immediately.\n", ch.Org) |
| 41 | if ch.Interactive { |
| 42 | ch.PrintfWarn("\nTo renew a cancelled subscription, please use `rill billing subscription renew` command.\n") |
| 43 | |
| 44 | if err := cmdutil.ConfirmPrompt("Do you want to continue?", false); err != nil { |
| 45 | return err |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | resp, err := client.UpdateBillingSubscription(cmd.Context(), &adminv1.UpdateBillingSubscriptionRequest{ |
| 50 | Org: ch.Org, |
| 51 | PlanName: plan, |
| 52 | SuperuserForceAccess: force, |
| 53 | }) |
| 54 | if err != nil { |
| 55 | return err |
| 56 | } |
| 57 | |
| 58 | ch.PrintfSuccess("Successfully subscribed to plan %q for org %q\n", plan, ch.Org) |
| 59 | ch.PrintSubscriptions([]*adminv1.Subscription{resp.Subscription}) |
| 60 | return nil |
| 61 | }, |
| 62 | } |
| 63 | editCmd.Flags().StringVar(&plan, "plan", "", "Plan Name to change subscription to") |
| 64 | editCmd.Flags().BoolVar(&force, "force", false, "Allows superusers to bypass certain checks") |
| 65 | _ = editCmd.Flags().MarkHidden("force") |
| 66 |
no test coverage detected