Created
February 16, 2015 15:08
-
-
Save alicebob/ac2a67e4bcd316b4a8dc to your computer and use it in GitHub Desktop.
reformat yml files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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