From da31cbe672332fdb6a01b062e1e46033f0d94d7a Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Sun, 27 Sep 2015 09:38:44 +1000 Subject: [PATCH] Added cli niceness --- yaml.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/yaml.go b/yaml.go index afa4f52..739c59d 100644 --- a/yaml.go +++ b/yaml.go @@ -5,10 +5,32 @@ import ( "gopkg.in/yaml.v2" "log" "io/ioutil" + "os" + "github.com/codegangsta/cli" ) func main() { - var raw_data, read_error = ioutil.ReadFile("sample.yaml") + app := cli.NewApp() + app.Name = "yaml" + app.Usage = "command line tool for reading and writing yaml" + app.Commands = []cli.Command{ + { + Name: "read", + Aliases: []string{"r"}, + Usage: "(default) reads a property from a given yaml file", + Action: read_file, + }, + } + app.Action = read_file + app.Run(os.Args) +} + +func read_file(c *cli.Context) { + if len(c.Args()) == 0 { + log.Fatalf("Must provide filename") + } + var filename = c.Args()[0] + var raw_data, read_error = ioutil.ReadFile(filename) if read_error != nil { log.Fatalf("error: %v", read_error)