Skip to content

Commit

Permalink
--color -> --no-color
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-frank committed Jun 2, 2021
1 parent c79d59e commit a9105a6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
10 changes: 5 additions & 5 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
)

func getPrintOptions(cmd *cobra.Command) *pretty.PrintOptions {
colorFlag := viper.GetBool("color")
colorFlag := viper.GetBool("no-color")
if !colorFlag {
return nil
}
return &pretty.PrintOptions{
Color: true,
return &pretty.PrintOptions{
Color: true,
}
}
return nil
}

func addFilterFlags(cmd *cobra.Command) {
Expand Down
5 changes: 2 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ func init() {

// Global Flags
isTTY, _, err := utils.IsTTY(os.Stdout)
fmt.Fprintln(os.Stderr, isTTY)
cobra.CheckErr(err)
rootCmd.PersistentFlags().Bool("color", isTTY, "colorize output json") // on by default if TTY, off if not
cobra.CheckErr(viper.BindPFlag("color", rootCmd.PersistentFlags().Lookup("color"))) // allow color flag to be set in config
rootCmd.PersistentFlags().Bool("no-color", !isTTY, "disable colorized output (automatically enabled if not a TTY)") // off by default if TTY, on if not
cobra.CheckErr(viper.BindPFlag("no-color", rootCmd.PersistentFlags().Lookup("no-color"))) // allow color flag to be set in config

// Register Commands
rootCmd.AddCommand(newVersionCmd().cmd)
Expand Down

0 comments on commit a9105a6

Please sign in to comment.