mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-07 14:25:38 +00:00
Updating go-yaml from v3 to v4
This commit is contained in:
parent
6251e95af8
commit
6957399dc0
@ -3,7 +3,7 @@ package yqlib
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
yaml "go.yaml.in/yaml/v3"
|
yaml "go.yaml.in/yaml/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
func MapYamlStyle(original yaml.Style) Style {
|
func MapYamlStyle(original yaml.Style) Style {
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
yaml "go.yaml.in/yaml/v3"
|
yaml "go.yaml.in/yaml/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
type yamlDecoder struct {
|
type yamlDecoder struct {
|
||||||
|
|||||||
@ -198,12 +198,6 @@ then
|
|||||||
yq 'explode(.f)' sample.yml
|
yq 'explode(.f)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
|
||||||
f:
|
|
||||||
a: cat
|
|
||||||
cat: b
|
|
||||||
```
|
|
||||||
|
|
||||||
## Dereference and update a field
|
## Dereference and update a field
|
||||||
Use explode with multiply to dereference an object
|
Use explode with multiply to dereference an object
|
||||||
|
|
||||||
@ -345,139 +339,3 @@ x: 1
|
|||||||
y: 2
|
y: 2
|
||||||
```
|
```
|
||||||
|
|
||||||
## FIXED: Explode with merge anchors
|
|
||||||
Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour (flag will default to true in late 2025).
|
|
||||||
Observe that foobarList.b property is still foobarList_b.
|
|
||||||
|
|
||||||
Given a sample.yml file of:
|
|
||||||
```yaml
|
|
||||||
foo: &foo
|
|
||||||
a: foo_a
|
|
||||||
thing: foo_thing
|
|
||||||
c: foo_c
|
|
||||||
bar: &bar
|
|
||||||
b: bar_b
|
|
||||||
thing: bar_thing
|
|
||||||
c: bar_c
|
|
||||||
foobarList:
|
|
||||||
b: foobarList_b
|
|
||||||
!!merge <<:
|
|
||||||
- *foo
|
|
||||||
- *bar
|
|
||||||
c: foobarList_c
|
|
||||||
foobar:
|
|
||||||
c: foobar_c
|
|
||||||
!!merge <<: *foo
|
|
||||||
thing: foobar_thing
|
|
||||||
```
|
|
||||||
then
|
|
||||||
```bash
|
|
||||||
yq 'explode(.)' sample.yml
|
|
||||||
```
|
|
||||||
will output
|
|
||||||
```yaml
|
|
||||||
foo:
|
|
||||||
a: foo_a
|
|
||||||
thing: foo_thing
|
|
||||||
c: foo_c
|
|
||||||
bar:
|
|
||||||
b: bar_b
|
|
||||||
thing: bar_thing
|
|
||||||
c: bar_c
|
|
||||||
foobarList:
|
|
||||||
b: foobarList_b
|
|
||||||
a: foo_a
|
|
||||||
thing: foo_thing
|
|
||||||
c: foobarList_c
|
|
||||||
foobar:
|
|
||||||
c: foobar_c
|
|
||||||
a: foo_a
|
|
||||||
thing: foobar_thing
|
|
||||||
```
|
|
||||||
|
|
||||||
## FIXED: Merge multiple maps
|
|
||||||
Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour (flag will default to true in late 2025).
|
|
||||||
Taken from https://yaml.org/type/merge.html. Same values as legacy, but with the correct key order.
|
|
||||||
|
|
||||||
Given a sample.yml file of:
|
|
||||||
```yaml
|
|
||||||
- &CENTER
|
|
||||||
x: 1
|
|
||||||
y: 2
|
|
||||||
- &LEFT
|
|
||||||
x: 0
|
|
||||||
y: 2
|
|
||||||
- &BIG
|
|
||||||
r: 10
|
|
||||||
- &SMALL
|
|
||||||
r: 1
|
|
||||||
- !!merge <<:
|
|
||||||
- *CENTER
|
|
||||||
- *BIG
|
|
||||||
```
|
|
||||||
then
|
|
||||||
```bash
|
|
||||||
yq '.[4] | explode(.)' sample.yml
|
|
||||||
```
|
|
||||||
will output
|
|
||||||
```yaml
|
|
||||||
x: 1
|
|
||||||
y: 2
|
|
||||||
r: 10
|
|
||||||
```
|
|
||||||
|
|
||||||
## FIXED: Override
|
|
||||||
Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour (flag will default to true in late 2025).
|
|
||||||
Taken from https://yaml.org/type/merge.html. Same values as legacy, but with the correct key order.
|
|
||||||
|
|
||||||
Given a sample.yml file of:
|
|
||||||
```yaml
|
|
||||||
- &CENTER
|
|
||||||
x: 1
|
|
||||||
y: 2
|
|
||||||
- &LEFT
|
|
||||||
x: 0
|
|
||||||
y: 2
|
|
||||||
- &BIG
|
|
||||||
r: 10
|
|
||||||
- &SMALL
|
|
||||||
r: 1
|
|
||||||
- !!merge <<:
|
|
||||||
- *BIG
|
|
||||||
- *LEFT
|
|
||||||
- *SMALL
|
|
||||||
x: 1
|
|
||||||
```
|
|
||||||
then
|
|
||||||
```bash
|
|
||||||
yq '.[4] | explode(.)' sample.yml
|
|
||||||
```
|
|
||||||
will output
|
|
||||||
```yaml
|
|
||||||
r: 10
|
|
||||||
y: 2
|
|
||||||
x: 1
|
|
||||||
```
|
|
||||||
|
|
||||||
## Exploding inline merge anchor
|
|
||||||
Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour (flag will default to true in late 2025).
|
|
||||||
|
|
||||||
|
|
||||||
Given a sample.yml file of:
|
|
||||||
```yaml
|
|
||||||
a:
|
|
||||||
b: &b 42
|
|
||||||
!!merge <<:
|
|
||||||
c: *b
|
|
||||||
```
|
|
||||||
then
|
|
||||||
```bash
|
|
||||||
yq 'explode(.) | sort_keys(.)' sample.yml
|
|
||||||
```
|
|
||||||
will output
|
|
||||||
```yaml
|
|
||||||
a:
|
|
||||||
b: 42
|
|
||||||
c: 42
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"go.yaml.in/yaml/v3"
|
"go.yaml.in/yaml/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
type yamlEncoder struct {
|
type yamlEncoder struct {
|
||||||
|
|||||||
@ -464,7 +464,7 @@ var anchorOperatorScenarios = []expressionScenario{
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
document: `{f : {a: &a cat, b: &b {foo: *a}, *a: *b}}`,
|
document: `{f : {a: &a cat, b: &b {foo: *a}, *a : *b}}`,
|
||||||
expression: `explode(.f)`,
|
expression: `explode(.f)`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (!!map)::{f: {a: cat, b: {foo: cat}, cat: {foo: cat}}}\n",
|
"D0, P[], (!!map)::{f: {a: cat, b: {foo: cat}, cat: {foo: cat}}}\n",
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import (
|
|||||||
"container/list"
|
"container/list"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"go.yaml.in/yaml/v3"
|
"go.yaml.in/yaml/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
type nodeInfoPrinter struct {
|
type nodeInfoPrinter struct {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user