Skip to content

Instantly share code, notes, and snippets.

@alicebob
Created February 16, 2015 15:08

Revisions

  1. Harmen created this gist Feb 16, 2015.
    31 changes: 31 additions & 0 deletions yml.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    package main

    import (
    "io/ioutil"
    "os"

    "gopkg.in/yaml.v2"
    )

    func main() {
    for _, f := range os.Args[1:] {
    b, err := ioutil.ReadFile(f)
    if err != nil {
    panic(err)
    }

    var o interface{}
    if err := yaml.Unmarshal(b, &o); err != nil {
    panic(err)
    }

    nb, err := yaml.Marshal(o)
    if err != nil {
    panic(err)
    }

    if err := ioutil.WriteFile(f, nb, os.ModePerm); err != nil {
    panic(err)
    }
    }
    }