mirror of
https://github.com/taigrr/yq
synced 2025-01-18 04:53:17 -08:00
Updating docs
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
### Yaml to Json
|
||||
To convert output to json, use the --tojson (or -j) flag. This can be used with any command.
|
||||
To convert output to json, use the --tojson (or -j) flag. This can only be used with the read command.
|
||||
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Yaml files can be created using the 'new' command. This works in the same way as the write command, but you don't pass in an existing Yaml file.
|
||||
Yaml files can be created using the 'new' command. This works in the same way as the write command, but you don't pass in an existing Yaml file. Currently this does not support creating multiple documents in a single yaml file.
|
||||
|
||||
```
|
||||
yq n <path> <new value>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
```
|
||||
yq d <yaml_file|json_file> <path_to_delete>
|
||||
yq d <yaml_file> <path_to_delete>
|
||||
```
|
||||
{!snippets/works_with_json.md!}
|
||||
|
||||
### To Stdout
|
||||
Given a sample.yaml file of:
|
||||
@@ -60,4 +59,52 @@ yq d -i sample.yaml b.c
|
||||
will update the sample.yaml file so that the 'c' node is deleted
|
||||
|
||||
|
||||
|
||||
### Multiple Documents - delete from single document
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
something: else
|
||||
field: leaveMe
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
field: deleteMe
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq w -d1 sample.yaml field
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
something: else
|
||||
field: leaveMe
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
```
|
||||
|
||||
### Multiple Documents - delete from all documents
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
something: else
|
||||
field: deleteMe
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
field: deleteMeToo
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq w -d'*' sample.yaml field
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
something: else
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
```
|
||||
|
||||
Note that '*' is in quotes to avoid being interpreted by your shell.
|
||||
|
||||
{!snippets/keys_with_dots.md!}
|
||||
|
||||
@@ -20,7 +20,7 @@ sudo apt install yq -y
|
||||
```
|
||||
or, [Download latest binary](https://github.com/mikefarah/yq/releases/latest) or alternatively:
|
||||
```
|
||||
go get gopkg.in/mikefarah/yq.v1
|
||||
go get gopkg.in/mikefarah/yq.v2
|
||||
```
|
||||
|
||||
[View on GitHub](https://github.com/mikefarah/yq)
|
||||
|
||||
@@ -2,9 +2,9 @@ Yaml files can be merged using the 'merge' command. Each additional file merged
|
||||
set values for any key not existing already or where the key has no value.
|
||||
|
||||
```
|
||||
yq m <yaml_file|json_file> <path>...
|
||||
yq m <yaml_file> <path>...
|
||||
```
|
||||
{!snippets/works_with_json.md!}
|
||||
|
||||
|
||||
### To Stdout
|
||||
Given a data1.yaml file of:
|
||||
@@ -102,3 +102,56 @@ d: false
|
||||
|
||||
Notice that 'b' does not result in the merging of the values within an array. The underlying library does not
|
||||
currently handle merging values within an array.
|
||||
|
||||
### Multiple Documents - merge into single document
|
||||
Currently yq only has multi-document support for the _first_ document being merged into. The remaining yaml files will have their first document selected.
|
||||
|
||||
Given a data1.yaml file of:
|
||||
```yaml
|
||||
something: else
|
||||
---
|
||||
a: simple
|
||||
b: cat
|
||||
```
|
||||
and data3.yaml file of:
|
||||
```yaml
|
||||
b: dog
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq m -x -d1 data1.yaml data3.yaml
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
something: else
|
||||
---
|
||||
a: simple
|
||||
b: dog
|
||||
```
|
||||
|
||||
### Multiple Documents - merge into all documents
|
||||
Currently yq only has multi-document support for the _first_ document being merged into. The remaining yaml files will have their first document selected.
|
||||
|
||||
Given a data1.yaml file of:
|
||||
```yaml
|
||||
something: else
|
||||
---
|
||||
a: simple
|
||||
b: cat
|
||||
```
|
||||
and data3.yaml file of:
|
||||
```yaml
|
||||
b: dog
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq m -x -d'*' data1.yaml data3.yaml
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
b: dog
|
||||
something: else
|
||||
---
|
||||
a: simple
|
||||
b: dog
|
||||
```
|
||||
@@ -43,6 +43,20 @@ will output
|
||||
- apples
|
||||
```
|
||||
|
||||
### Multiple Documents
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
something: else
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq r -d1 sample.yaml b.c
|
||||
```
|
||||
will output the value of '2'.
|
||||
|
||||
### Arrays
|
||||
You can give an index to access a specific element:
|
||||
e.g.: given a sample file of
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
```
|
||||
yq w <yaml_file|json_file> <path> <new value>
|
||||
yq w <yaml_file> <path> <new value>
|
||||
```
|
||||
{!snippets/works_with_json.md!}
|
||||
|
||||
### To Stdout
|
||||
Given a sample.yaml file of:
|
||||
@@ -69,6 +68,50 @@ b:
|
||||
|
||||
Note that the path is in quotes to avoid the square brackets being interpreted by your shell.
|
||||
|
||||
### Multiple Documents - update a single document
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
something: else
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq w -d1 sample.yaml b.c 5
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
something: else
|
||||
---
|
||||
b:
|
||||
c: 5
|
||||
```
|
||||
|
||||
### Multiple Documents - update all documents
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
something: else
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq w -d'*' sample.yaml b.c 5
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
something: else
|
||||
b:
|
||||
c: 5
|
||||
---
|
||||
b:
|
||||
c: 5
|
||||
```
|
||||
|
||||
Note that '*' is in quotes to avoid being interpreted by your shell.
|
||||
|
||||
### Updating files in-place
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
|
||||
Reference in New Issue
Block a user