add flag to disable ci colors (close #2072) (#2634)

* added log-level flag

* fix up the colors

* fix description
This commit is contained in:
Daven Paul Casia
2019-07-30 00:55:38 -06:00
committed by Shahidh K Muhammed
parent 4aef5b4c26
commit 7f06470082
2 changed files with 13 additions and 1 deletions

View File

@@ -21,7 +21,7 @@ import (
"github.com/briandowns/spinner"
"github.com/gofrs/uuid"
"github.com/hasura/graphql-engine/cli/version"
colorable "github.com/mattn/go-colorable"
"github.com/mattn/go-colorable"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
@@ -171,6 +171,9 @@ type ExecutionContext struct {
// LogLevel indicates the logrus default logging level
LogLevel string
// NoColor indicates if the outputs shouldn't be colorized
NoColor bool
// Telemetry collects the telemetry data throughout the execution
Telemetry *telemetry.Data
@@ -343,6 +346,7 @@ func (ec *ExecutionContext) Spin(message string) {
func (ec *ExecutionContext) setupLogger() {
if ec.Logger == nil {
logger := logrus.New()
logger.Formatter = &logrus.TextFormatter{
ForceColors: true,
DisableTimestamp: true,
@@ -351,6 +355,13 @@ func (ec *ExecutionContext) setupLogger() {
ec.Logger = logger
}
if ec.NoColor {
ec.Logger.Formatter = &logrus.TextFormatter{
DisableColors: true,
DisableTimestamp: true,
}
}
if ec.LogLevel != "" {
level, err := logrus.ParseLevel(ec.LogLevel)
if err != nil {

View File

@@ -70,6 +70,7 @@ func init() {
f.StringVar(&ec.LogLevel, "log-level", "INFO", "log level (DEBUG, INFO, WARN, ERROR, FATAL)")
f.StringVar(&ec.ExecutionDirectory, "project", "", "directory where commands are executed (default: current dir)")
f.BoolVar(&ec.SkipUpdateCheck, "skip-update-check", false, "Skip automatic update check on command execution")
f.BoolVar(&ec.NoColor, "no-color", false, "do not colorize output (default: false)")
}
// Execute executes the command and returns the error