Skip to content

Commit

Permalink
hide status command (#1090)
Browse files Browse the repository at this point in the history
* hide status command

* update comment

* comment out status cmd
  • Loading branch information
etsai-stripe committed Jun 27, 2023
1 parent a4f13c9 commit 98ae134
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 86 deletions.
4 changes: 3 additions & 1 deletion pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ func init() {
rootCmd.AddCommand(newResourcesCmd().cmd)
rootCmd.AddCommand(newSamplesCmd().cmd)
rootCmd.AddCommand(newServeCmd().cmd)
rootCmd.AddCommand(newStatusCmd().cmd)
// current stripe status site is being deprecated
// hide status command until status site v2 is released
// rootCmd.AddCommand(newStatusCmd().cmd)
rootCmd.AddCommand(newTriggerCmd().cmd)
rootCmd.AddCommand(newVersionCmd().cmd)
rootCmd.AddCommand(newPostinstallCmd(&Config).cmd)
Expand Down
170 changes: 85 additions & 85 deletions pkg/cmd/status.go
Original file line number Diff line number Diff line change
@@ -1,87 +1,87 @@
package cmd

import (
"fmt"
"os"
"time"

"github.com/spf13/cobra"

"github.com/stripe/stripe-cli/pkg/ansi"
"github.com/stripe/stripe-cli/pkg/status"
"github.com/stripe/stripe-cli/pkg/validators"
"github.com/stripe/stripe-cli/pkg/version"
)

type statusCmd struct {
cmd *cobra.Command

format string
hideSpinner bool
poll bool
pollRate int
verbose bool
}

func newStatusCmd() *statusCmd {
sc := &statusCmd{}
sc.cmd = &cobra.Command{
Use: "status",
Args: validators.NoArgs,
Short: "Check the status of the Stripe API",
Example: `stripe status
stripe status --poll
stripe status --poll --verbose`,
RunE: sc.runStatusCmd,
}

sc.cmd.Flags().StringVar(&sc.format, "format", "default", "The format to print the status as (either 'default' or 'json')")
sc.cmd.Flags().BoolVar(&sc.verbose, "verbose", false, "Show status for all Stripe systems")
sc.cmd.Flags().BoolVar(&sc.poll, "poll", false, "Keep polling for status updates")
sc.cmd.Flags().IntVar(&sc.pollRate, "poll-rate", 60, "How many seconds to wait between status updates (minimum: 5)")
sc.cmd.Flags().BoolVar(&sc.hideSpinner, "hide-spinner", false, "Hide the loading spinner when polling")

return sc
}

func (sc *statusCmd) runStatusCmd(cmd *cobra.Command, args []string) error {
if sc.format != "json" {
version.CheckLatestVersion()
}

if sc.pollRate < 5 {
return fmt.Errorf("poll-rate must be at least 5 seconds, received %d", sc.pollRate)
}

if sc.format != "default" && sc.format != "json" {
return fmt.Errorf("invalid format, must be one of 'default' or 'json', received %s", sc.format)
}

for {
stripeStatus, err := status.GetStatus()
if err != nil {
return err
}

formattedStatus, err := stripeStatus.FormattedMessage(sc.format, sc.verbose)
if err != nil {
return err
}

fmt.Println(formattedStatus)

if !sc.poll {
break
}

if sc.hideSpinner {
time.Sleep(time.Duration(sc.pollRate) * time.Second)
} else {
spinner := ansi.StartNewSpinner("", os.Stderr)
time.Sleep(time.Duration(sc.pollRate) * time.Second)
ansi.StopSpinner(spinner, "", os.Stderr)
}
}

return nil
}
// import (
// "fmt"
// "os"
// "time"

// "github.com/spf13/cobra"

// "github.com/stripe/stripe-cli/pkg/ansi"
// "github.com/stripe/stripe-cli/pkg/status"
// "github.com/stripe/stripe-cli/pkg/validators"
// "github.com/stripe/stripe-cli/pkg/version"
// )

// type statusCmd struct {
// cmd *cobra.Command

// format string
// hideSpinner bool
// poll bool
// pollRate int
// verbose bool
// }

// func newStatusCmd() *statusCmd {
// sc := &statusCmd{}
// sc.cmd = &cobra.Command{
// Use: "status",
// Args: validators.NoArgs,
// Short: "Check the status of the Stripe API",
// Example: `stripe status
// stripe status --poll
// stripe status --poll --verbose`,
// RunE: sc.runStatusCmd,
// }

// sc.cmd.Flags().StringVar(&sc.format, "format", "default", "The format to print the status as (either 'default' or 'json')")
// sc.cmd.Flags().BoolVar(&sc.verbose, "verbose", false, "Show status for all Stripe systems")
// sc.cmd.Flags().BoolVar(&sc.poll, "poll", false, "Keep polling for status updates")
// sc.cmd.Flags().IntVar(&sc.pollRate, "poll-rate", 60, "How many seconds to wait between status updates (minimum: 5)")
// sc.cmd.Flags().BoolVar(&sc.hideSpinner, "hide-spinner", false, "Hide the loading spinner when polling")

// return sc
// }

// func (sc *statusCmd) runStatusCmd(cmd *cobra.Command, args []string) error {
// if sc.format != "json" {
// version.CheckLatestVersion()
// }

// if sc.pollRate < 5 {
// return fmt.Errorf("poll-rate must be at least 5 seconds, received %d", sc.pollRate)
// }

// if sc.format != "default" && sc.format != "json" {
// return fmt.Errorf("invalid format, must be one of 'default' or 'json', received %s", sc.format)
// }

// for {
// stripeStatus, err := status.GetStatus()
// if err != nil {
// return err
// }

// formattedStatus, err := stripeStatus.FormattedMessage(sc.format, sc.verbose)
// if err != nil {
// return err
// }

// fmt.Println(formattedStatus)

// if !sc.poll {
// break
// }

// if sc.hideSpinner {
// time.Sleep(time.Duration(sc.pollRate) * time.Second)
// } else {
// spinner := ansi.StartNewSpinner("", os.Stderr)
// time.Sleep(time.Duration(sc.pollRate) * time.Second)
// ansi.StopSpinner(spinner, "", os.Stderr)
// }
// }

// return nil
// }

0 comments on commit 98ae134

Please sign in to comment.