• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

cmd/yaml-patch/H19-Jul-2017-13297

LICENSEH A D19-Jul-201711.1 KiB202169

MakefileH A D19-Jul-2017362 1812

README.mdH A D19-Jul-20171.2 KiB8763

container.goH A D19-Jul-20172.9 KiB168118

node.goH A D19-Jul-20171.6 KiB8456

operation.goH A D19-Jul-20174.1 KiB182132

patch.goH A D19-Jul-20171.2 KiB6146

patch_test.goH A D19-Jul-20178.8 KiB607586

pathfinder.goH A D19-Jul-20172.3 KiB11084

pathfinder_test.goH A D19-Jul-20172.5 KiB7566

placeholder_wrapper.goH A D19-Jul-20171.5 KiB5236

placeholder_wrapper_test.goH A D19-Jul-20173 KiB9481

yaml_patch_suite_test.goH A D19-Jul-2017200 1410

README.md

1# yaml-patch
2
3`yaml-patch` is a version of Evan Phoenix's
4[json-patch](https://github.com/evanphx/json-patch), which is an implementation
5of [JavaScript Object Notation (JSON) Patch](https://tools.ietf.org/html/rfc6902),
6but for YAML.
7
8
9## Installing
10
11`go get github.com/krishicks/yaml-patch`
12
13If you want to use the CLI:
14
15`go get github.com/krishicks/yaml-patch/cmd/yaml-patch`
16
17## API
18
19Given the following RFC6902-ish YAML document, `ops`:
20
21```
22---
23- op: add
24  path: /baz/waldo
25  value: fred
26```
27
28And the following YAML that is to be modified, `src`:
29
30```
31---
32foo: bar
33baz:
34  quux: grault
35```
36
37Decode the ops file into a patch:
38
39```
40patch, err := yamlpatch.DecodePatch(ops)
41// handle err
42```
43
44Then apply that patch to the document:
45
46```
47dst, err := patch.Apply(src)
48// handle err
49
50// do something with dst
51```
52
53### Example
54
55```
56doc := []byte(`---
57foo: bar
58baz:
59  quux: grault
60`)
61
62ops := []byte(`---
63- op: add
64  path: /baz/waldo
65  value: fred
66`)
67
68patch, err := yamlpatch.DecodePatch(ops)
69if err != nil {
70  log.Fatalf("decoding patch failed: %s", err)
71}
72
73bs, err := patch.Apply(doc)
74if err != nil {
75  log.Fatalf("applying patch failed: %s", err)
76}
77
78fmt.Println(string(bs))
79```
80
81```
82baz:
83  quux: grault
84  waldo: fred
85foo: bar
86```
87