Skip to content

Commit

Permalink
Add --force-color flag.
Browse files Browse the repository at this point in the history
Helpful when using watch for example.
  • Loading branch information
Gerrit91 committed Jan 23, 2024
1 parent 58e47b5 commit c0ae637
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cmd/output/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"text/template"

"github.com/Masterminds/sprig/v3"
"github.com/fatih/color"
"github.com/fi-ts/cloud-go/api/client/cluster"
"github.com/fi-ts/cloud-go/api/models"
"github.com/fi-ts/cloudctl/pkg/api"
Expand Down Expand Up @@ -169,6 +170,16 @@ func newPrinter(format, order, tpl string, noHeaders bool, writer io.Writer) (Pr
default:
return nil, fmt.Errorf("unknown format:%s", format)
}

if viper.IsSet("force-color") {
enabled := viper.GetBool("force-color")
if enabled {
color.NoColor = false
} else {
color.NoColor = true
}
}

return printer, nil
}

Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func newRootCmd() *cobra.Command {
rootCmd.PersistentFlags().StringP("order", "", "", "order by (comma separated) column(s)")
rootCmd.PersistentFlags().BoolP("no-headers", "", false, "ommit headers in tables")
rootCmd.PersistentFlags().BoolP("debug", "", false, "enable debug")
rootCmd.PersistentFlags().Bool("force-color", false, "force colored output even without tty")
rootCmd.PersistentFlags().StringP("output-format", "o", "table", "output format (table|wide|markdown|json|yaml|template), wide is a table with more columns.")
rootCmd.PersistentFlags().StringP("template", "", "", `output template for template output-format, go template format.
For property names inspect the output of -o json for reference.
Expand Down

0 comments on commit c0ae637

Please sign in to comment.