mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-13 22:38:04 +00:00
README now links to doco
This commit is contained in:
parent
fb73a793bd
commit
124c57f9d9
183
README.md
183
README.md
@ -21,12 +21,15 @@ go get github.com/mikefarah/yaml
|
||||
- Convert from yaml to json
|
||||
- Pipe data in by using '-'
|
||||
|
||||
## Read examples
|
||||
## [Usage](http://mikefarah.github.io/yaml/)
|
||||
|
||||
Check out the [documentation](http://mikefarah.github.io/yaml/) for more detailed and advanced usage.
|
||||
|
||||
### Read
|
||||
```
|
||||
yaml r <yaml file> <path>
|
||||
```
|
||||
|
||||
### Basic
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
b:
|
||||
@ -38,86 +41,10 @@ yaml r sample.yaml b.c
|
||||
```
|
||||
will output the value of '2'.
|
||||
|
||||
### Reading from STDIN
|
||||
Given a sample.yaml file of:
|
||||
```bash
|
||||
cat sample.yaml | yaml r - b.c
|
||||
```
|
||||
will output the value of '2'.
|
||||
|
||||
### Splat
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
---
|
||||
bob:
|
||||
item1:
|
||||
cats: bananas
|
||||
item2:
|
||||
cats: apples
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yaml r sample.yaml bob.*.cats
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
- bananas
|
||||
- apples
|
||||
```
|
||||
|
||||
### Handling '.' in the yaml key
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
b.x:
|
||||
c: 2
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yaml r sample.yaml \"b.x\".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
|
||||
```yaml
|
||||
b:
|
||||
e:
|
||||
- name: fred
|
||||
value: 3
|
||||
- name: sam
|
||||
value: 4
|
||||
```
|
||||
then
|
||||
```
|
||||
yaml r sample.yaml b.e[1].name
|
||||
```
|
||||
will output 'sam'
|
||||
|
||||
### Array Splat
|
||||
e.g.: given a sample file of
|
||||
```yaml
|
||||
b:
|
||||
e:
|
||||
- name: fred
|
||||
value: 3
|
||||
- name: sam
|
||||
value: 4
|
||||
```
|
||||
then
|
||||
```
|
||||
yaml r sample.yaml b.e[*].name
|
||||
```
|
||||
will output:
|
||||
```
|
||||
- fred
|
||||
- sam
|
||||
```
|
||||
|
||||
## Update examples
|
||||
## Update
|
||||
Existing yaml files can be updated via the write command
|
||||
|
||||
### Update to stdout
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
b:
|
||||
@ -133,76 +60,7 @@ b:
|
||||
c: cat
|
||||
```
|
||||
|
||||
### Update from STDIN
|
||||
```bash
|
||||
cat sample.yaml | yaml w - b.c blah
|
||||
```
|
||||
|
||||
### Adding new fields
|
||||
Any missing fields in the path will be created on the fly.
|
||||
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
b:
|
||||
c: 2
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yaml w sample.yaml b.d[0] "new thing"
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
b:
|
||||
c: cat
|
||||
d:
|
||||
- new thing
|
||||
```
|
||||
|
||||
### Updating yaml in-place
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
b:
|
||||
c: 2
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yaml w -i sample.yaml b.c cat
|
||||
```
|
||||
will update the sample.yaml file so that the value of 'c' is cat.
|
||||
|
||||
|
||||
### Updating multiple values with a script
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
b:
|
||||
c: 2
|
||||
e:
|
||||
- name: Billy Bob
|
||||
```
|
||||
and a script update_instructions.yaml of:
|
||||
```yaml
|
||||
b.c: 3
|
||||
b.e[0].name: Howdy Partner
|
||||
```
|
||||
then
|
||||
|
||||
```bash
|
||||
yaml w -s update_instructions.yaml sample.yaml
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
b:
|
||||
c: 3
|
||||
e:
|
||||
- name: Howdy Partner
|
||||
```
|
||||
|
||||
And, of course, you can pipe the instructions in using '-':
|
||||
```bash
|
||||
cat update_instructions.yaml | yaml w -s - sample.yaml
|
||||
```
|
||||
|
||||
## New Examples
|
||||
## Create
|
||||
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.
|
||||
|
||||
### Creating a simple yaml file
|
||||
@ -215,33 +73,6 @@ b:
|
||||
c: cat
|
||||
```
|
||||
|
||||
### Creating using a create script
|
||||
Create scripts follow the same format as the update scripts.
|
||||
|
||||
Given a script create_instructions.yaml of:
|
||||
```yaml
|
||||
b.c: 3
|
||||
b.e[0].name: Howdy Partner
|
||||
```
|
||||
then
|
||||
|
||||
```bash
|
||||
yaml n -s create_instructions.yaml
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
b:
|
||||
c: 3
|
||||
e:
|
||||
- name: Howdy Partner
|
||||
```
|
||||
|
||||
You can also pipe the instructions in:
|
||||
|
||||
```bash
|
||||
cat create_instructions.yaml | yaml n -s -
|
||||
```
|
||||
|
||||
## Converting to and from json
|
||||
|
||||
### Yaml2json
|
||||
|
Loading…
Reference in New Issue
Block a user