Skip to content

Instantly share code, notes, and snippets.

@alicebob
Created February 16, 2015 15:08
Show Gist options
  • Save alicebob/ac2a67e4bcd316b4a8dc to your computer and use it in GitHub Desktop.
Save alicebob/ac2a67e4bcd316b4a8dc to your computer and use it in GitHub Desktop.
reformat yml files
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)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment