mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-13 22:38:04 +00:00
When split expression includes an extension, dont add .yml automatically
This commit is contained in:
parent
f63d76f006
commit
dfd396b480
1
.gitignore
vendored
1
.gitignore
vendored
@ -41,6 +41,7 @@ yq*.snap
|
||||
|
||||
test.yml
|
||||
test*.yml
|
||||
test*.yaml
|
||||
0.yml
|
||||
1.yml
|
||||
2.yml
|
||||
|
@ -25,6 +25,31 @@ EOM
|
||||
assertEquals "$expectedDoc2" "$doc2"
|
||||
}
|
||||
|
||||
testBasicSplitWithNameCustomExtension() {
|
||||
rm test*.yaml || true
|
||||
cat >test.yml <<EOL
|
||||
a: test_doc1
|
||||
---
|
||||
a: test_doc2
|
||||
EOL
|
||||
|
||||
./yq e test.yml -s '.a + ".yaml"'
|
||||
|
||||
doc1=$(cat test_doc1.yaml)
|
||||
|
||||
assertEquals "a: test_doc1" "$doc1"
|
||||
|
||||
doc2=$(cat test_doc2.yaml)
|
||||
read -r -d '' expectedDoc2 << EOM
|
||||
---
|
||||
a: test_doc2
|
||||
EOM
|
||||
assertEquals "$expectedDoc2" "$doc2"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
testSplitFromFile() {
|
||||
cat >test.yml <<EOL
|
||||
a: test_doc1
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"regexp"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
@ -67,7 +68,10 @@ func (sp *multiPrintWriter) GetWriter(node *CandidateNode) (*bufio.Writer, error
|
||||
if result.MatchingNodes.Len() > 0 {
|
||||
name = result.MatchingNodes.Front().Value.(*CandidateNode).Node.Value
|
||||
}
|
||||
name = fmt.Sprintf("%v.%v", name, sp.extension)
|
||||
var extensionRegexp = regexp.MustCompile(`\.[a-zA-Z0-9]+$`)
|
||||
if !extensionRegexp.MatchString(name) {
|
||||
name = fmt.Sprintf("%v.%v", name, sp.extension)
|
||||
}
|
||||
|
||||
f, err := os.Create(name)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user