Skip to content

Commit

Permalink
fix: show pretty error when trying to create meter event stream or se…
Browse files Browse the repository at this point in the history
…ssion
  • Loading branch information
charliecruzan-stripe committed Sep 16, 2024
1 parent 8d33a69 commit 2a788f8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
22 changes: 21 additions & 1 deletion pkg/cmd/resource/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"regexp"
"strings"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/stripe/stripe-cli/pkg/ansi"
"github.com/stripe/stripe-cli/pkg/config"
"github.com/stripe/stripe-cli/pkg/requests"
Expand Down Expand Up @@ -130,6 +130,26 @@ func (oc *OperationCmd) runOperationCmd(cmd *cobra.Command, args []string) error
// Public functions
//

// NewUnsupportedV2BillingOperationCmd returns a new cobra command for an unsupported v2 billing command.
// This is temporary until resource commands support the /v2/billing namespace.
func NewUnsupportedV2BillingOperationCmd(parentCmd *cobra.Command, name string, path string) *cobra.Command {
cmd := &cobra.Command{
Use: name,
Annotations: make(map[string]string),
Run: func(cmd *cobra.Command, args []string) {
output := `
%s is not supported by Stripe CLI yet. Please use the %s or cURL to create a %s, instead.
* Hint: If you're trying to test webhook events, you can always use %s or %s.
`

fmt.Println(fmt.Sprintf(output, ansi.Bold(path), ansi.Linkify("Dashboard", "https://dashboard.stripe.com", log.StandardLogger().Out), parentCmd.Name(), ansi.Bold("stripe trigger v1.billing.meter.no_meter_found"), ansi.Bold("stripe trigger v1.billing.meter.error_report_triggered")))
},
}
parentCmd.AddCommand(cmd)
return cmd
}

// NewOperationCmd returns a new OperationCmd.
func NewOperationCmd(parentCmd *cobra.Command, name, path, httpVerb string, propFlags map[string]string, cfg *config.Config) *OperationCmd {
urlParams := extractURLParams(path)
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/resources_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ func addAllResourcesCmds(rootCmd *cobra.Command) {
rBillingMeterEventSummarysCmd := resource.NewResourceCmd(nsBillingCmd.Cmd, "meter_event_summarys")
rBillingMeterEventsCmd := resource.NewResourceCmd(nsBillingCmd.Cmd, "meter_events")
rBillingMetersCmd := resource.NewResourceCmd(nsBillingCmd.Cmd, "meters")
rBillingMeterEventSessionCmd := resource.NewResourceCmd(nsBillingCmd.Cmd, "meter_event_session")
rBillingMeterEventStreamCmd := resource.NewResourceCmd(nsBillingCmd.Cmd, "meter_event_stream")
rBillingPortalConfigurationsCmd := resource.NewResourceCmd(nsBillingPortalCmd.Cmd, "configurations")
rBillingPortalSessionsCmd := resource.NewResourceCmd(nsBillingPortalCmd.Cmd, "sessions")
rCheckoutSessionsCmd := resource.NewResourceCmd(nsCheckoutCmd.Cmd, "sessions")
Expand Down Expand Up @@ -3246,6 +3248,8 @@ func addAllResourcesCmds(rootCmd *cobra.Command) {
resource.NewOperationCmd(rBillingMetersCmd.Cmd, "update", "/v1/billing/meters/{id}", http.MethodPost, map[string]string{
"display_name": "string",
}, &Config)
resource.NewUnsupportedV2BillingOperationCmd(rBillingMeterEventSessionCmd.Cmd, "create", "/v2/billing/meter_event_session")
resource.NewUnsupportedV2BillingOperationCmd(rBillingMeterEventStreamCmd.Cmd, "create", "/v2/billing/meter_event_stream")
resource.NewOperationCmd(rBillingPortalConfigurationsCmd.Cmd, "create", "/v1/billing_portal/configurations", http.MethodPost, map[string]string{
"business_profile.headline": "string",
"business_profile.privacy_policy_url": "string",
Expand Down

0 comments on commit 2a788f8

Please sign in to comment.