mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-24 14:45:39 +00:00
cmd: force no color output when NO_COLOR env presents
This commit is contained in:
parent
b8607bacb9
commit
f071a25fa9
@ -1,5 +1,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
|
import "os"
|
||||||
|
|
||||||
var unwrapScalarFlag = newUnwrapFlag()
|
var unwrapScalarFlag = newUnwrapFlag()
|
||||||
|
|
||||||
var unwrapScalar = false
|
var unwrapScalar = false
|
||||||
@ -12,9 +14,6 @@ var outputFormat = ""
|
|||||||
var inputFormat = ""
|
var inputFormat = ""
|
||||||
|
|
||||||
var exitStatus = false
|
var exitStatus = false
|
||||||
var forceColor = false
|
|
||||||
var forceNoColor = false
|
|
||||||
var colorsEnabled = false
|
|
||||||
var indent = 2
|
var indent = 2
|
||||||
var noDocSeparators = false
|
var noDocSeparators = false
|
||||||
var nullInput = false
|
var nullInput = false
|
||||||
@ -23,6 +22,16 @@ var verbose = false
|
|||||||
var version = false
|
var version = false
|
||||||
var prettyPrint = false
|
var prettyPrint = false
|
||||||
|
|
||||||
|
var forceColor = false
|
||||||
|
var forceNoColor = false
|
||||||
|
var colorsEnabled = false
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// when NO_COLOR environment variable presents and not an empty string the colored output should be disabled;
|
||||||
|
// refer to no-color.org
|
||||||
|
forceNoColor = os.Getenv("NO_COLOR") != ""
|
||||||
|
}
|
||||||
|
|
||||||
// can be either "" (off), "extract" or "process"
|
// can be either "" (off), "extract" or "process"
|
||||||
var frontMatter = ""
|
var frontMatter = ""
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ yq -P -oy sample.json
|
|||||||
rootCmd.PersistentFlags().BoolVarP(&exitStatus, "exit-status", "e", false, "set exit status if there are no matches or null or false is returned")
|
rootCmd.PersistentFlags().BoolVarP(&exitStatus, "exit-status", "e", false, "set exit status if there are no matches or null or false is returned")
|
||||||
|
|
||||||
rootCmd.PersistentFlags().BoolVarP(&forceColor, "colors", "C", false, "force print with colors")
|
rootCmd.PersistentFlags().BoolVarP(&forceColor, "colors", "C", false, "force print with colors")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&forceNoColor, "no-colors", "M", false, "force print with no colors")
|
rootCmd.PersistentFlags().BoolVarP(&forceNoColor, "no-colors", "M", forceNoColor, "force print with no colors")
|
||||||
rootCmd.PersistentFlags().StringVarP(&frontMatter, "front-matter", "f", "", "(extract|process) first input as yaml front-matter. Extract will pull out the yaml content, process will run the expression against the yaml content, leaving the remaining data intact")
|
rootCmd.PersistentFlags().StringVarP(&frontMatter, "front-matter", "f", "", "(extract|process) first input as yaml front-matter. Extract will pull out the yaml content, process will run the expression against the yaml content, leaving the remaining data intact")
|
||||||
if err = rootCmd.RegisterFlagCompletionFunc("front-matter", cobra.FixedCompletions([]string{"extract", "process"}, cobra.ShellCompDirectiveNoFileComp)); err != nil {
|
if err = rootCmd.RegisterFlagCompletionFunc("front-matter", cobra.FixedCompletions([]string{"extract", "process"}, cobra.ShellCompDirectiveNoFileComp)); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user