mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-07 14:25:38 +00:00
Compare commits
8 Commits
951467c733
...
da11ea3bbb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da11ea3bbb | ||
|
|
f73c862cc5 | ||
|
|
294a1709ad | ||
|
|
342efb23ff | ||
|
|
2201381235 | ||
|
|
5273715428 | ||
|
|
e204677ff8 | ||
|
|
9883ebc313 |
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -44,7 +44,7 @@ jobs:
|
|||||||
./scripts/xcompile.sh
|
./scripts/xcompile.sh
|
||||||
|
|
||||||
- name: Release
|
- name: Release
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v2
|
||||||
with:
|
with:
|
||||||
files: build/*
|
files: build/*
|
||||||
draft: true
|
draft: true
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
setUp() {
|
setUp() {
|
||||||
rm test*.yml || true
|
rm test*.yml || true
|
||||||
|
rm -rf test_dir* || true
|
||||||
}
|
}
|
||||||
|
|
||||||
testBasicSplitWithName() {
|
testBasicSplitWithName() {
|
||||||
@ -204,4 +205,23 @@ EOM
|
|||||||
assertEquals "$expectedDoc3" "$doc3"
|
assertEquals "$expectedDoc3" "$doc3"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testSplitWithDirectories() {
|
||||||
|
cat >test.yml <<EOL
|
||||||
|
f: test_dir1/file1
|
||||||
|
---
|
||||||
|
f: test_dir2/dir22/file2
|
||||||
|
---
|
||||||
|
f: file3
|
||||||
|
EOL
|
||||||
|
|
||||||
|
./yq e --no-doc -s ".f" test.yml
|
||||||
|
|
||||||
|
doc1=$(cat test_dir1/file1.yml)
|
||||||
|
assertEquals "f: test_dir1/file1" "$doc1"
|
||||||
|
doc2=$(cat test_dir2/dir22/file2.yml)
|
||||||
|
assertEquals "f: test_dir2/dir22/file2" "$doc2"
|
||||||
|
doc3=$(cat file3.yml)
|
||||||
|
assertEquals "f: file3" "$doc3"
|
||||||
|
}
|
||||||
|
|
||||||
source ./scripts/shunit2
|
source ./scripts/shunit2
|
||||||
10
cmd/root.go
10
cmd/root.go
@ -71,6 +71,10 @@ yq -P -oy sample.json
|
|||||||
level := logging.WARNING
|
level := logging.WARNING
|
||||||
stringFormat := `[%{level}] %{color}%{time:15:04:05}%{color:reset} %{message}`
|
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 {
|
if verbose && forceNoColor {
|
||||||
level = logging.DEBUG
|
level = logging.DEBUG
|
||||||
stringFormat = `[%{level:5.5s}] %{time:15:04:05} %{shortfile:-33s} %{shortfunc:-25s} %{message}`
|
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)
|
logging.SetBackend(backend)
|
||||||
yqlib.InitExpressionParser()
|
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
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -197,7 +197,7 @@ yq -P -oy sample.json
|
|||||||
}
|
}
|
||||||
rootCmd.PersistentFlags().BoolVarP(&yqlib.ConfiguredYamlPreferences.LeadingContentPreProcessing, "header-preprocess", "", true, "Slurp any header comments and separators before processing expression.")
|
rootCmd.PersistentFlags().BoolVarP(&yqlib.ConfiguredYamlPreferences.LeadingContentPreProcessing, "header-preprocess", "", true, "Slurp any header comments and separators before processing expression.")
|
||||||
|
|
||||||
rootCmd.PersistentFlags().StringVarP(&splitFileExp, "split-exp", "s", "", "print each result (or doc) into a file named (exp). [exp] argument must return a string. You can use $index in the expression as the result counter.")
|
rootCmd.PersistentFlags().StringVarP(&splitFileExp, "split-exp", "s", "", "print each result (or doc) into a file named (exp). [exp] argument must return a string. You can use $index in the expression as the result counter. The necessary directories will be created.")
|
||||||
if err = rootCmd.RegisterFlagCompletionFunc("split-exp", cobra.NoFileCompletions); err != nil {
|
if err = rootCmd.RegisterFlagCompletionFunc("split-exp", cobra.NoFileCompletions); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@ var (
|
|||||||
GitDescribe string
|
GitDescribe string
|
||||||
|
|
||||||
// Version is main version number that is being run at the moment.
|
// Version is main version number that is being run at the moment.
|
||||||
Version = "v4.44.5"
|
Version = "v4.44.6"
|
||||||
|
|
||||||
// VersionPrerelease is a pre-release marker for the version. If this is "" (empty string)
|
// VersionPrerelease is a pre-release marker for the version. If this is "" (empty string)
|
||||||
// then it means that it is a final release. Otherwise, this is a pre-release
|
// then it means that it is a final release. Otherwise, this is a pre-release
|
||||||
|
|||||||
@ -153,6 +153,10 @@ func repeatString(lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error
|
|||||||
count, err := parseInt(intNode.Value)
|
count, err := parseInt(intNode.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
} else if count < 0 {
|
||||||
|
return nil, fmt.Errorf("Cannot repeat string by a negative number (%v)", count)
|
||||||
|
} else if count > 10000000 {
|
||||||
|
return nil, fmt.Errorf("Cannot repeat string by more than 100 million (%v)", count)
|
||||||
}
|
}
|
||||||
target.Value = strings.Repeat(stringNode.Value, count)
|
target.Value = strings.Repeat(stringNode.Value, count)
|
||||||
|
|
||||||
|
|||||||
@ -201,6 +201,21 @@ var multiplyOperatorScenarios = []expressionScenario{
|
|||||||
fmt.Sprintf("D0, P[], (!!str)::%s\n", strings.Repeat("banana", 4)),
|
fmt.Sprintf("D0, P[], (!!str)::%s\n", strings.Repeat("banana", 4)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "Multiply string X by negative int",
|
||||||
|
skipDoc: true,
|
||||||
|
document: `n: -4`,
|
||||||
|
expression: `"banana" * .n`,
|
||||||
|
expectedError: "Cannot repeat string by a negative number (-4)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "Multiply string X by more than 100 million",
|
||||||
|
// very large string.repeats causes a panic
|
||||||
|
skipDoc: true,
|
||||||
|
document: `n: 100000001`,
|
||||||
|
expression: `"banana" * .n`,
|
||||||
|
expectedError: "Cannot repeat string by more than 100 million (100000001)",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "Multiply int node X string",
|
description: "Multiply int node X string",
|
||||||
document: `n: 4
|
document: `n: 4
|
||||||
|
|||||||
@ -264,7 +264,7 @@ func doTraverseMap(newMatches *orderedmap.OrderedMap, node *CandidateNode, wante
|
|||||||
// if we don't find a match directly on this node first.
|
// if we don't find a match directly on this node first.
|
||||||
|
|
||||||
var contents = node.Content
|
var contents = node.Content
|
||||||
for index := 0; index < len(contents); index = index + 2 {
|
for index := 0; index+1 < len(contents); index = index + 2 {
|
||||||
key := contents[index]
|
key := contents[index]
|
||||||
value := contents[index+1]
|
value := contents[index+1]
|
||||||
|
|
||||||
|
|||||||
@ -35,6 +35,15 @@ steps:
|
|||||||
`
|
`
|
||||||
|
|
||||||
var traversePathOperatorScenarios = []expressionScenario{
|
var traversePathOperatorScenarios = []expressionScenario{
|
||||||
|
{
|
||||||
|
skipDoc: true,
|
||||||
|
description: "strange map with key but no value",
|
||||||
|
document: "!!null\n-",
|
||||||
|
expression: ".x",
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[x], (!!null)::null\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
description: "access merge anchors",
|
description: "access merge anchors",
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -70,6 +71,10 @@ func (sp *multiPrintWriter) GetWriter(node *CandidateNode) (*bufio.Writer, error
|
|||||||
name = fmt.Sprintf("%v.%v", name, sp.extension)
|
name = fmt.Sprintf("%v.%v", name, sp.extension)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = os.MkdirAll(filepath.Dir(name), 0750)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
f, err := os.Create(name)
|
f, err := os.Create(name)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -1,3 +1,10 @@
|
|||||||
|
4.44.6:
|
||||||
|
- Fixed deleting items in array bug #2027, #2172; Thanks @jandubois
|
||||||
|
- Docker image for armv7 / raspberry pi3, Thanks @brianegge
|
||||||
|
- Fixed no-colors regression #2218
|
||||||
|
- Fixed various panic scenarios #2211
|
||||||
|
- Bumped dependencies
|
||||||
|
|
||||||
4.44.5:
|
4.44.5:
|
||||||
- Fixing release pipeline
|
- Fixing release pipeline
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
name: yq
|
name: yq
|
||||||
version: 'v4.44.5'
|
version: 'v4.44.6'
|
||||||
summary: A lightweight and portable command-line data file processor
|
summary: A lightweight and portable command-line data file processor
|
||||||
description: |
|
description: |
|
||||||
`yq` uses [jq](https://github.com/stedolan/jq) like syntax but works with yaml, json, xml, csv, properties and TOML files.
|
`yq` uses [jq](https://github.com/stedolan/jq) like syntax but works with yaml, json, xml, csv, properties and TOML files.
|
||||||
@ -24,6 +24,6 @@ parts:
|
|||||||
build-environment:
|
build-environment:
|
||||||
- CGO_ENABLED: 0
|
- CGO_ENABLED: 0
|
||||||
source: https://github.com/mikefarah/yq.git
|
source: https://github.com/mikefarah/yq.git
|
||||||
source-tag: v4.44.5
|
source-tag: v4.44.6
|
||||||
build-snaps:
|
build-snaps:
|
||||||
- go/latest/stable
|
- go/latest/stable
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user