pivotal-cf/yaml-patch

Name: yaml-patch

Owner: Pivotal Cloud Foundry

Description: null

Created: 2017-11-08 19:39:52.0

Updated: 2018-05-14 07:32:28.0

Pushed: 2017-11-15 19:13:28.0

Homepage: null

Size: 49

Language: Go

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

yaml-patch

yaml-patch is a version of Evan Phoenix's json-patch, which is an implementation of JavaScript Object Notation (JSON) Patch, but for YAML.

Installing

go get github.com/krishicks/yaml-patch

If you want to use the CLI:

go get github.com/krishicks/yaml-patch/cmd/yaml-patch

API

Given the following RFC6902-ish YAML document, ops:


: add
th: /baz/waldo
lue: fred

And the following YAML that is to be modified, src:


 bar

ux: grault

Decode the ops file into a patch:

h, err := yamlpatch.DecodePatch(ops)
andle err

Then apply that patch to the document:

 err := patch.Apply(src)
andle err

o something with dst
Example
:= []byte(`---
 bar

ux: grault


:= []byte(`---
: add
th: /baz/waldo
lue: fred


h, err := yamlpatch.DecodePatch(ops)
rr != nil {
g.Fatalf("decoding patch failed: %s", err)


err := patch.Apply(doc)
rr != nil {
g.Fatalf("applying patch failed: %s", err)


Println(string(bs))


ux: grault
ldo: fred
 bar

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.