Skip to content

Commit

Permalink
cmd: add --no-color flag
Browse files Browse the repository at this point in the history
This PR adds a new flag to disable color via the `--no-color`.
  • Loading branch information
fatih committed May 24, 2021
1 parent a79e30b commit 84ab472
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"strings"

"github.com/fatih/color"
"github.com/planetscale/cli/internal/cmd/auth"
"github.com/planetscale/cli/internal/cmd/backup"
"github.com/planetscale/cli/internal/cmd/branch"
Expand All @@ -45,8 +46,10 @@ import (
"github.com/spf13/viper"
)

var cfgFile string
var replacer = strings.NewReplacer("-", "_", ".", "_")
var (
cfgFile string
replacer = strings.NewReplacer("-", "_", ".", "_")
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Expand Down Expand Up @@ -122,6 +125,11 @@ func Execute(ver, commit, buildDate string) error {
rootCmd.PersistentFlags().StringVar(&cfg.ServiceToken,
"service-token", "", "Service Token for authenticating.")

rootCmd.PersistentFlags().BoolVar(&color.NoColor, "no-color", false, "Disable color output")
if err := viper.BindPFlag("no-color", rootCmd.PersistentFlags().Lookup("no-color")); err != nil {
return err
}

// We don't want to show the default value
rootCmd.PersistentFlags().Lookup("api-token").DefValue = ""

Expand Down

0 comments on commit 84ab472

Please sign in to comment.