diff --git a/cmd/root.go b/cmd/root.go index 80ebe8e122..8af5622b8c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -71,6 +71,10 @@ yq -P -oy sample.json level := logging.WARNING stringFormat := `[%{level}] %{color}%{time:15:04:05}%{color:reset} %{message}` + // when NO_COLOR environment variable presents and not an empty string the coloured output should be disabled; + // refer to no-color.org + forceNoColor = forceNoColor || os.Getenv("NO_COLOR") != "" + if verbose && forceNoColor { level = logging.DEBUG stringFormat = `[%{level:5.5s}] %{time:15:04:05} %{shortfile:-33s} %{shortfunc:-25s} %{message}` @@ -90,10 +94,6 @@ yq -P -oy sample.json logging.SetBackend(backend) yqlib.InitExpressionParser() - // when NO_COLOR environment variable presents and not an empty string the coloured output should be disabled; - // refer to no-color.org - forceNoColor = os.Getenv("NO_COLOR") != "" - return nil }, }