Updated readme

This commit is contained in:
Mike Farah 2017-04-12 21:17:54 +10:00
parent 82f1230db8
commit b1ff47022b

View File

@ -14,6 +14,9 @@ go get github.com/mikefarah/yaml
- Deep read a yaml file with a given path
- Update a yaml file given a path
- Update a yaml file given a script file
- Update creates any missing entries in the path on the fly
- Create a yaml file given a deep path and value
- Create a yaml file given a script file
- Convert from json to yaml
- Convert from yaml to json
@ -111,6 +114,7 @@ will output:
```
## Update examples
Existing yaml files can be updated via the write command
### Update to stdout
Given a sample.yaml file of:
@ -128,6 +132,26 @@ b:
c: cat
```
### 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
@ -167,6 +191,40 @@ b:
- name: Howdy Partner
```
## New Examples
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
```bash
yaml n b.c cat
```
will output:
```yaml
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
```
## Converting to and from json
### Yaml2json