mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Improved tips and tricks
This commit is contained in:
parent
8b04d972f3
commit
b4db4496d5
@ -5,7 +5,7 @@ The Sort Keys operator sorts maps by their keys (based on their string value). T
|
||||
Sort is particularly useful for diffing two different yaml documents:
|
||||
|
||||
```bash
|
||||
yq eval -i 'sortKeys(..)' file1.yml
|
||||
yq eval -i 'sortKeys(..)' file2.yml
|
||||
yq eval -i -P 'sort_keys(..)' file1.yml
|
||||
yq eval -i -P 'sort_keys(..)' file2.yml
|
||||
diff file1.yml file2.yml
|
||||
```
|
||||
|
@ -5,8 +5,8 @@ The Sort Keys operator sorts maps by their keys (based on their string value). T
|
||||
Sort is particularly useful for diffing two different yaml documents:
|
||||
|
||||
```bash
|
||||
yq eval -i 'sortKeys(..)' file1.yml
|
||||
yq eval -i 'sortKeys(..)' file2.yml
|
||||
yq eval -i -P 'sort_keys(..)' file1.yml
|
||||
yq eval -i -P 'sort_keys(..)' file2.yml
|
||||
diff file1.yml file2.yml
|
||||
```
|
||||
|
||||
@ -19,7 +19,7 @@ b: bing
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval 'sortKeys(.)' sample.yml
|
||||
yq eval 'sort_keys(.)' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
@ -49,7 +49,7 @@ aParent:
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval 'sortKeys(..)' sample.yml
|
||||
yq eval 'sort_keys(..)' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
|
@ -8,7 +8,7 @@ var sortKeysOperatorScenarios = []expressionScenario{
|
||||
{
|
||||
description: "Sort keys of map",
|
||||
document: `{c: frog, a: blah, b: bing}`,
|
||||
expression: `sortKeys(.)`,
|
||||
expression: `sort_keys(.)`,
|
||||
expected: []string{
|
||||
"D0, P[], (doc)::{a: blah, b: bing, c: frog}\n",
|
||||
},
|
||||
@ -16,7 +16,7 @@ var sortKeysOperatorScenarios = []expressionScenario{
|
||||
{
|
||||
skipDoc: true,
|
||||
document: `{c: frog}`,
|
||||
expression: `sortKeys(.d)`,
|
||||
expression: `sort_keys(.d)`,
|
||||
expected: []string{
|
||||
"D0, P[], (doc)::{c: frog}\n",
|
||||
},
|
||||
@ -25,7 +25,7 @@ var sortKeysOperatorScenarios = []expressionScenario{
|
||||
description: "Sort keys recursively",
|
||||
subdescription: "Note the array elements are left unsorted, but maps inside arrays are sorted",
|
||||
document: `{bParent: {c: dog, array: [3,1,2]}, aParent: {z: donkey, x: [{c: yum, b: delish}, {b: ew, a: apple}]}}`,
|
||||
expression: `sortKeys(..)`,
|
||||
expression: `sort_keys(..)`,
|
||||
expected: []string{
|
||||
"D0, P[], (!!map)::{aParent: {x: [{b: delish, c: yum}, {a: apple, b: ew}], z: donkey}, bParent: {array: [3, 1, 2], c: dog}}\n",
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user