mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Adding another xml test; spelling fixes
This commit is contained in:
parent
05ad1dad90
commit
0cf3adf5dd
2
debian/changelog
vendored
2
debian/changelog
vendored
@ -127,7 +127,7 @@ yq (4.9.6) focal; urgency=medium
|
||||
|
||||
* Added darwin/arm64 build, thanks @alecthomas
|
||||
* Incremented docker alpine base version, thanks @da6d6i7-bronga
|
||||
* Bug fix: multine expression
|
||||
* Bug fix: multiline expression
|
||||
* Bug fix: special character
|
||||
|
||||
-- Roberto Mier Escandon <rmescandon@gmail.com> Tue, 29 Jun 2021 21:32:14 +0200
|
||||
|
@ -29,7 +29,7 @@ It pipes the current, lets call it 'root' context through the `lhs` expression o
|
||||
cat
|
||||
```
|
||||
|
||||
Sidenote: this node holds not only its value 'cat', but comments and metadata too, including path and parent information.
|
||||
Side note: this node holds not only its value 'cat', but comments and metadata too, including path and parent information.
|
||||
|
||||
The `=` operator then pipes the 'root' context through the `rhs` expression of `.b` to return the node
|
||||
|
||||
|
@ -13,7 +13,7 @@ myMap:
|
||||
cat: meow
|
||||
dog: bark
|
||||
thing: hamster
|
||||
hamster: squeek
|
||||
hamster: squeak
|
||||
```
|
||||
then
|
||||
```bash
|
||||
@ -22,7 +22,7 @@ yq '.myMap |= pick(["hamster", "cat", "goat"])' sample.yml
|
||||
will output
|
||||
```yaml
|
||||
myMap:
|
||||
hamster: squeek
|
||||
hamster: squeak
|
||||
cat: meow
|
||||
```
|
||||
|
||||
|
@ -128,6 +128,25 @@ zoo:
|
||||
- cat
|
||||
```
|
||||
|
||||
## Parse xml: force all as an array
|
||||
Because of the way yq works, when updating everything you need to update the children before the parents. By default `..` will match parents first, so we reverse that before updating.
|
||||
|
||||
Given a sample.xml file of:
|
||||
```xml
|
||||
<zoo><thing><frog>boing</frog></thing></zoo>
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq -oy '([..] | reverse | .[]) |= [] + .' sample.xml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
- zoo:
|
||||
- thing:
|
||||
- frog:
|
||||
- boing
|
||||
```
|
||||
|
||||
## Parse xml: attributes
|
||||
Attributes are converted to fields, with the default attribute prefix '+'. Use '--xml-attribute-prefix` to set your own.
|
||||
|
||||
|
@ -233,7 +233,7 @@ func (e *xmlEncoder) encodeComment(encoder *xml.Encoder, commentStr string) erro
|
||||
commentStr = chompRegexp.ReplaceAllString(commentStr, "")
|
||||
log.Debugf("chompRegexp [%v]", commentStr)
|
||||
commentStr = xmlEncodeMultilineCommentRegex.ReplaceAllString(commentStr, "$1$2")
|
||||
log.Debugf("processed multine [%v]", commentStr)
|
||||
log.Debugf("processed multiline [%v]", commentStr)
|
||||
// if the first line is non blank, add a space
|
||||
if commentStr[0] != '\n' && commentStr[0] != ' ' {
|
||||
commentStr = " " + commentStr
|
||||
|
@ -38,7 +38,6 @@ func (ye *yamlEncoder) PrintDocumentSeparator(writer io.Writer) error {
|
||||
}
|
||||
|
||||
func (ye *yamlEncoder) PrintLeadingContent(writer io.Writer, content string) error {
|
||||
// log.Debug("headcommentwas [%v]", content)
|
||||
reader := bufio.NewReader(strings.NewReader(content))
|
||||
|
||||
for {
|
||||
|
@ -175,7 +175,7 @@ func handleToken(tokens []*token, index int, postProcessedTokens []*token) (toke
|
||||
if index != len(tokens)-1 && currentToken.CheckForPostTraverse &&
|
||||
tokens[index+1].TokenType == openCollect {
|
||||
|
||||
log.Debug(" adding traverArray because next is opencollect")
|
||||
log.Debug(" adding traverseArray because next is opencollect")
|
||||
op := &Operation{OperationType: traverseArrayOpType}
|
||||
postProcessedTokens = append(postProcessedTokens, &token{TokenType: operationToken, Operation: op})
|
||||
}
|
||||
|
@ -8,28 +8,28 @@ var pickOperatorScenarios = []expressionScenario{
|
||||
{
|
||||
description: "Pick keys from map",
|
||||
subdescription: "Note that the order of the keys matches the pick order and non existent keys are skipped.",
|
||||
document: "myMap: {cat: meow, dog: bark, thing: hamster, hamster: squeek}\n",
|
||||
document: "myMap: {cat: meow, dog: bark, thing: hamster, hamster: squeak}\n",
|
||||
expression: `.myMap |= pick(["hamster", "cat", "goat"])`,
|
||||
expected: []string{
|
||||
"D0, P[], (doc)::myMap: {hamster: squeek, cat: meow}\n",
|
||||
"D0, P[], (doc)::myMap: {hamster: squeak, cat: meow}\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Pick keys from map",
|
||||
skipDoc: true,
|
||||
document: "!things myMap: {cat: meow, dog: bark, thing: hamster, hamster: squeek}\n",
|
||||
document: "!things myMap: {cat: meow, dog: bark, thing: hamster, hamster: squeak}\n",
|
||||
expression: `.myMap |= pick(["hamster", "cat", "goat"])`,
|
||||
expected: []string{
|
||||
"D0, P[], (doc)::!things myMap: {hamster: squeek, cat: meow}\n",
|
||||
"D0, P[], (doc)::!things myMap: {hamster: squeak, cat: meow}\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Pick keys from map with comments",
|
||||
skipDoc: true,
|
||||
document: "# abc\nmyMap: {cat: meow, dog: bark, thing: hamster, hamster: squeek}\n# xyz\n",
|
||||
document: "# abc\nmyMap: {cat: meow, dog: bark, thing: hamster, hamster: squeak}\n# xyz\n",
|
||||
expression: `.myMap |= pick(["hamster", "cat", "goat"])`,
|
||||
expected: []string{
|
||||
"D0, P[], (doc)::# abc\nmyMap: {hamster: squeek, cat: meow}\n# xyz\n",
|
||||
"D0, P[], (doc)::# abc\nmyMap: {hamster: squeak, cat: meow}\n# xyz\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -363,6 +363,13 @@ var xmlScenarios = []formatScenario{
|
||||
expression: ".zoo.animal |= ([] + .)",
|
||||
expected: "zoo:\n animal:\n - cat\n",
|
||||
},
|
||||
{
|
||||
description: "Parse xml: force all as an array",
|
||||
subdescription: "Because of the way yq works, when updating everything you need to update the children before the parents. By default `..` will match parents first, so we reverse that before updating.",
|
||||
input: "<zoo><thing><frog>boing</frog></thing></zoo>",
|
||||
expression: "([..] | reverse | .[]) |= [] + .",
|
||||
expected: "- zoo:\n - thing:\n - frog:\n - boing\n",
|
||||
},
|
||||
{
|
||||
description: "Parse xml: attributes",
|
||||
subdescription: "Attributes are converted to fields, with the default attribute prefix '+'. Use '--xml-attribute-prefix` to set your own.",
|
||||
|
@ -96,7 +96,6 @@ gota
|
||||
goversion
|
||||
GOVERSION
|
||||
haha
|
||||
headcommentwas
|
||||
hellno
|
||||
herbygillot
|
||||
hexdump
|
||||
@ -138,7 +137,6 @@ mitchellh
|
||||
mktemp
|
||||
multidoc
|
||||
multimaint
|
||||
multine
|
||||
myenv
|
||||
myenvnonexisting
|
||||
myfile
|
||||
@ -161,7 +159,6 @@ Oneshot
|
||||
opencollect
|
||||
opstack
|
||||
orderedmap
|
||||
original
|
||||
osarch
|
||||
overridign
|
||||
pacman
|
||||
@ -199,11 +196,9 @@ shellvars
|
||||
shortfunc
|
||||
shortpipe
|
||||
shunit
|
||||
Sidenote
|
||||
snapcraft
|
||||
somevalue
|
||||
splt
|
||||
squeek
|
||||
srcdir
|
||||
stackoverflow
|
||||
stiched
|
||||
@ -227,7 +222,6 @@ timezones
|
||||
Timezones
|
||||
tojson
|
||||
Tokenvalue
|
||||
traver
|
||||
tsvd
|
||||
Tuan
|
||||
tzdata
|
||||
|
Loading…
Reference in New Issue
Block a user