Skip to content

Commit 1a4b248

Browse files
authored
Merge branch 'master' into add-comment-style
2 parents 9caeb42 + 4af292f commit 1a4b248

19 files changed

+55
-40
lines changed

.golangci.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ linters:
1010
- gofmt
1111
- goimports
1212
- gosec
13-
- megacheck
13+
- gosimple
14+
- staticcheck
15+
- unused
1416
- misspell
1517
- nakedret
1618
- nolintlint
@@ -31,13 +33,6 @@ linters-settings:
3133
desc: "replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil"
3234
issues:
3335
exclude-rules:
34-
- linters:
35-
- gosec
36-
text: "Implicit memory aliasing in for loop."
37-
path: _test\.go
38-
- linters:
39-
- revive
40-
text: "unexported-return"
4136
- linters:
4237
- revive
4338
text: "var-naming"

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.23.2 as builder
1+
FROM golang:1.23.3 as builder
22

33
WORKDIR /go/src/mikefarah/yq
44

Dockerfile.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.23.2
1+
FROM golang:1.23.3
22

33
RUN apt-get update && \
44
apt-get install -y npm && \

cmd/constant.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ var outputFormat = ""
1212
var inputFormat = ""
1313

1414
var exitStatus = false
15-
var forceColor = false
16-
var forceNoColor = false
17-
var colorsEnabled = false
1815
var indent = 2
1916
var noDocSeparators = false
2017
var nullInput = false
@@ -23,6 +20,10 @@ var verbose = false
2320
var version = false
2421
var prettyPrint = false
2522

23+
var forceColor = false
24+
var forceNoColor = false
25+
var colorsEnabled = false
26+
2627
// can be either "" (off), "extract" or "process"
2728
var frontMatter = ""
2829

cmd/evaluate_all_command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func createEvaluateAllCommand() *cobra.Command {
1212
Use: "eval-all [expression] [yaml_file1]...",
1313
Aliases: []string{"ea"},
1414
Short: "Loads _all_ yaml documents of _all_ yaml files and runs expression once",
15-
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
15+
ValidArgsFunction: func(_ *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective) {
1616
if len(args) == 0 {
1717
return nil, cobra.ShellCompDirectiveNoFileComp
1818
}

cmd/evaluate_sequence_command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func createEvaluateSequenceCommand() *cobra.Command {
1313
Use: "eval [expression] [yaml_file1]...",
1414
Aliases: []string{"e"},
1515
Short: "(default) Apply the expression to each document in each yaml file in sequence",
16-
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
16+
ValidArgsFunction: func(_ *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective) {
1717
if len(args) == 0 {
1818
return nil, cobra.ShellCompDirectiveNoFileComp
1919
}

cmd/root.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ yq -P -oy sample.json
6666
return evaluateSequence(cmd, args)
6767

6868
},
69-
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
69+
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
7070
cmd.SetOut(cmd.OutOrStdout())
7171
level := logging.WARNING
7272
stringFormat := `[%{level}] %{color}%{time:15:04:05}%{color:reset} %{message}`
@@ -90,6 +90,10 @@ yq -P -oy sample.json
9090
logging.SetBackend(backend)
9191
yqlib.InitExpressionParser()
9292

93+
// when NO_COLOR environment variable presents and not an empty string the coloured output should be disabled;
94+
// refer to no-color.org
95+
forceNoColor = os.Getenv("NO_COLOR") != ""
96+
9397
return nil
9498
},
9599
}
@@ -182,7 +186,7 @@ yq -P -oy sample.json
182186
rootCmd.PersistentFlags().BoolVarP(&exitStatus, "exit-status", "e", false, "set exit status if there are no matches or null or false is returned")
183187

184188
rootCmd.PersistentFlags().BoolVarP(&forceColor, "colors", "C", false, "force print with colors")
185-
rootCmd.PersistentFlags().BoolVarP(&forceNoColor, "no-colors", "M", false, "force print with no colors")
189+
rootCmd.PersistentFlags().BoolVarP(&forceNoColor, "no-colors", "M", forceNoColor, "force print with no colors")
186190
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")
187191
if err = rootCmd.RegisterFlagCompletionFunc("front-matter", cobra.FixedCompletions([]string{"extract", "process"}, cobra.ShellCompDirectiveNoFileComp)); err != nil {
188192
panic(err)

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ require (
1616
github.com/spf13/cobra v1.8.1
1717
github.com/spf13/pflag v1.0.5
1818
github.com/yuin/gopher-lua v1.1.1
19-
golang.org/x/net v0.30.0
20-
golang.org/x/text v0.19.0
19+
golang.org/x/net v0.31.0
20+
golang.org/x/text v0.20.0
2121
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473
2222
gopkg.in/yaml.v3 v3.0.1
2323
)
@@ -26,7 +26,8 @@ require (
2626
github.com/inconshreveable/mousetrap v1.1.0 // indirect
2727
github.com/mattn/go-colorable v0.1.13 // indirect
2828
github.com/mattn/go-isatty v0.0.20 // indirect
29-
golang.org/x/sys v0.26.0 // indirect
29+
golang.org/x/sys v0.27.0 // indirect
30+
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
3031
)
3132

3233
go 1.21.0

go.sum

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,18 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
6262
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
6363
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=
6464
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
65-
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
66-
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
67-
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
68-
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
65+
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
66+
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
67+
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
68+
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
6969
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7070
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
71-
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
72-
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
73-
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
74-
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
71+
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
72+
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
73+
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
74+
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
75+
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
76+
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
7577
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
7678
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
7779
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 h1:6D+BvnJ/j6e222UW8s2qTSe3wGBtvo0MbVQG/c5k8RE=

pkg/yqlib/decoder_toml.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ func (dec *tomlDecoder) processTable(currentNode *toml.Node) (bool, error) {
286286
}
287287

288288
runAgainstCurrentExp, err = dec.decodeKeyValuesIntoMap(tableNodeValue, tableValue)
289-
if err != nil && !errors.Is(io.EOF, err) {
289+
if err != nil && !errors.Is(err, io.EOF) {
290290
return false, err
291291
}
292292
}
@@ -343,7 +343,7 @@ func (dec *tomlDecoder) processArrayTable(currentNode *toml.Node) (bool, error)
343343
tableValue := dec.parser.Expression()
344344
runAgainstCurrentExp, err := dec.decodeKeyValuesIntoMap(tableNodeValue, tableValue)
345345
log.Debugf("table node err: %w", err)
346-
if err != nil && !errors.Is(io.EOF, err) {
346+
if err != nil && !errors.Is(err, io.EOF) {
347347
return false, err
348348
}
349349
c := Context{}

0 commit comments

Comments
 (0)