mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-12 19:25:37 +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:
|
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
|
||||||
```
|
```
|
||||||
|
@ -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
|
||||||
|
@ -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",
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user