Skip to content

Commit b1ff470

Browse files
author
Mike Farah
committed
Updated readme
1 parent 82f1230 commit b1ff470

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ go get github.com/mikefarah/yaml
1414
- Deep read a yaml file with a given path
1515
- Update a yaml file given a path
1616
- Update a yaml file given a script file
17+
- Update creates any missing entries in the path on the fly
18+
- Create a yaml file given a deep path and value
19+
- Create a yaml file given a script file
1720
- Convert from json to yaml
1821
- Convert from yaml to json
1922

@@ -111,6 +114,7 @@ will output:
111114
```
112115

113116
## Update examples
117+
Existing yaml files can be updated via the write command
114118

115119
### Update to stdout
116120
Given a sample.yaml file of:
@@ -128,6 +132,26 @@ b:
128132
c: cat
129133
```
130134
135+
### Adding new fields
136+
Any missing fields in the path will be created on the fly.
137+
138+
Given a sample.yaml file of:
139+
```yaml
140+
b:
141+
c: 2
142+
```
143+
then
144+
```bash
145+
yaml w sample.yaml b.d[0] "new thing"
146+
```
147+
will output:
148+
```yaml
149+
b:
150+
c: cat
151+
d:
152+
- new thing
153+
```
154+
131155
### Updating yaml in-place
132156
Given a sample.yaml file of:
133157
```yaml
@@ -167,6 +191,40 @@ b:
167191
- name: Howdy Partner
168192
```
169193
194+
## New Examples
195+
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.
196+
197+
### Creating a simple yaml file
198+
```bash
199+
yaml n b.c cat
200+
```
201+
will output:
202+
```yaml
203+
b:
204+
c: cat
205+
```
206+
207+
### Creating using a create script
208+
Create scripts follow the same format as the update scripts.
209+
210+
Given a script create_instructions.yaml of:
211+
```yaml
212+
b.c: 3
213+
b.e[0].name: Howdy Partner
214+
```
215+
then
216+
217+
```bash
218+
yaml n -s create_instructions.yaml
219+
```
220+
will output:
221+
```yaml
222+
b:
223+
c: 3
224+
e:
225+
- name: Howdy Partner
226+
```
227+
170228
## Converting to and from json
171229
172230
### Yaml2json

0 commit comments

Comments
 (0)