Add github.com/krishicks/yaml-patch to vendor

This commit is contained in:
Jingfang Liu
2018-08-30 13:45:25 -07:00
parent a81b2e32e0
commit 95cf508b2b
19 changed files with 1882 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
package main
// Thanks, Concourse!
import (
"fmt"
"os"
"path/filepath"
)
// FileFlag is a flag for passing a path to a file on disk. The file is
// expected to be a file, not a directory, that actually exists.
type FileFlag string
// UnmarshalFlag implements go-flag's Unmarshaler interface
func (f *FileFlag) UnmarshalFlag(value string) error {
stat, err := os.Stat(value)
if err != nil {
return err
}
if stat.IsDir() {
return fmt.Errorf("path '%s' is a directory, not a file", value)
}
abs, err := filepath.Abs(value)
if err != nil {
return err
}
*f = FileFlag(abs)
return nil
}
// Path is the path to the file
func (f FileFlag) Path() string {
return string(f)
}

View File

@@ -0,0 +1,57 @@
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
flags "github.com/jessevdk/go-flags"
yamlpatch "github.com/krishicks/yaml-patch"
)
type opts struct {
OpsFiles []FileFlag `long:"ops-file" short:"o" value-name:"PATH" description:"Path to file with one or more operations"`
}
func main() {
var o opts
_, err := flags.Parse(&o)
if err != nil {
log.Fatalf("error: %s\n", err)
}
placeholderWrapper := yamlpatch.NewPlaceholderWrapper("{{", "}}")
var patches []yamlpatch.Patch
for _, opsFile := range o.OpsFiles {
var bs []byte
bs, err = ioutil.ReadFile(opsFile.Path())
if err != nil {
log.Fatalf("error reading opsfile: %s", err)
}
var patch yamlpatch.Patch
patch, err = yamlpatch.DecodePatch(placeholderWrapper.Wrap(bs))
if err != nil {
log.Fatalf("error decoding opsfile: %s", err)
}
patches = append(patches, patch)
}
doc, err := ioutil.ReadAll(os.Stdin)
if err != nil {
log.Fatalf("error reading from stdin: %s", err)
}
mdoc := placeholderWrapper.Wrap(doc)
for _, patch := range patches {
mdoc, err = patch.Apply(mdoc)
if err != nil {
log.Fatalf("error applying patch: %s", err)
}
}
fmt.Printf("%s", placeholderWrapper.Unwrap(mdoc))
}

View File

@@ -0,0 +1,18 @@
package main_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
"testing"
)
var _ = AfterSuite(func() {
gexec.CleanupBuildArtifacts()
})
func TestMain(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Main Suite")
}

View File

@@ -0,0 +1,14 @@
package main_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
)
var _ = Describe("yaml-patch", func() {
It("builds", func() {
_, err := gexec.Build("github.com/krishicks/yaml-patch/cmd/yaml-patch")
Expect(err).NotTo(HaveOccurred())
})
})