Added another style example for doc

This commit is contained in:
Mike Farah 2021-04-26 14:17:52 +10:00
parent 8b327d0414
commit 38666f4db6
2 changed files with 55 additions and 0 deletions

View File

@ -1,4 +1,42 @@
The style operator can be used to get or set the style of nodes (e.g. string style, yaml style)
## Update and set style of a particular node (simple)
Given a sample.yml file of:
```yaml
a:
b: thing
c: something
```
then
```bash
yq eval '.a.b = "new" | .a.b style="double"' sample.yml
```
will output
```yaml
a:
b: "new"
c: something
```
## Update and set style of a particular node using path variables
You can use a variable to re-use a path
Given a sample.yml file of:
```yaml
a:
b: thing
c: something
```
then
```bash
yq eval '.a.b as $x | $x = "new" | $x style="double"' sample.yml
```
will output
```yaml
a:
b: "new"
c: something
```
## Set tagged style
Given a sample.yml file of:
```yaml

View File

@ -5,6 +5,23 @@ import (
)
var styleOperatorScenarios = []expressionScenario{
{
description: "Update and set style of a particular node (simple)",
document: `a: {b: thing, c: something}`,
expression: `.a.b = "new" | .a.b style="double"`,
expected: []string{
"D0, P[], (doc)::a: {b: \"new\", c: something}\n",
},
},
{
description: "Update and set style of a particular node using path variables",
subdescription: "You can use a variable to re-use a path",
document: `a: {b: thing, c: something}`,
expression: `.a.b as $x | $x = "new" | $x style="double"`,
expected: []string{
"D0, P[], (doc)::a: {b: \"new\", c: something}\n",
},
},
{
description: "Set tagged style",
document: `{a: cat, b: 5, c: 3.2, e: true}`,