Improved tips and tricks

This commit is contained in:
Mike Farah 2021-12-05 11:12:09 +11:00
parent 8b04d972f3
commit b4db4496d5
3 changed files with 9 additions and 9 deletions

View File

@ -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: Sort is particularly useful for diffing two different yaml documents:
```bash ```bash
yq eval -i 'sortKeys(..)' file1.yml yq eval -i -P 'sort_keys(..)' file1.yml
yq eval -i 'sortKeys(..)' file2.yml yq eval -i -P 'sort_keys(..)' file2.yml
diff file1.yml file2.yml diff file1.yml file2.yml
``` ```

View File

@ -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: Sort is particularly useful for diffing two different yaml documents:
```bash ```bash
yq eval -i 'sortKeys(..)' file1.yml yq eval -i -P 'sort_keys(..)' file1.yml
yq eval -i 'sortKeys(..)' file2.yml yq eval -i -P 'sort_keys(..)' file2.yml
diff file1.yml file2.yml diff file1.yml file2.yml
``` ```
@ -19,7 +19,7 @@ b: bing
``` ```
then then
```bash ```bash
yq eval 'sortKeys(.)' sample.yml yq eval 'sort_keys(.)' sample.yml
``` ```
will output will output
```yaml ```yaml
@ -49,7 +49,7 @@ aParent:
``` ```
then then
```bash ```bash
yq eval 'sortKeys(..)' sample.yml yq eval 'sort_keys(..)' sample.yml
``` ```
will output will output
```yaml ```yaml

View File

@ -8,7 +8,7 @@ var sortKeysOperatorScenarios = []expressionScenario{
{ {
description: "Sort keys of map", description: "Sort keys of map",
document: `{c: frog, a: blah, b: bing}`, document: `{c: frog, a: blah, b: bing}`,
expression: `sortKeys(.)`, expression: `sort_keys(.)`,
expected: []string{ expected: []string{
"D0, P[], (doc)::{a: blah, b: bing, c: frog}\n", "D0, P[], (doc)::{a: blah, b: bing, c: frog}\n",
}, },
@ -16,7 +16,7 @@ var sortKeysOperatorScenarios = []expressionScenario{
{ {
skipDoc: true, skipDoc: true,
document: `{c: frog}`, document: `{c: frog}`,
expression: `sortKeys(.d)`, expression: `sort_keys(.d)`,
expected: []string{ expected: []string{
"D0, P[], (doc)::{c: frog}\n", "D0, P[], (doc)::{c: frog}\n",
}, },
@ -25,7 +25,7 @@ var sortKeysOperatorScenarios = []expressionScenario{
description: "Sort keys recursively", description: "Sort keys recursively",
subdescription: "Note the array elements are left unsorted, but maps inside arrays are sorted", 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}]}}`, 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{ 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", "D0, P[], (!!map)::{aParent: {x: [{b: delish, c: yum}, {a: apple, b: ew}], z: donkey}, bParent: {array: [3, 1, 2], c: dog}}\n",
}, },