From 4143058f5a4e8b92731b16fb9165eae407e5a2b6 Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Sat, 14 May 2016 14:46:59 -0400 Subject: Switching argument parsing to codegangsta/cli Signed-off-by: Dave Henderson --- main.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index 007de5c0..38f1c5f3 100644 --- a/main.go +++ b/main.go @@ -1,27 +1,18 @@ package main import ( - "flag" - "fmt" "io" "io/ioutil" "log" "os" - "github.com/hairyhenderson/gomplate/aws" - "github.com/hairyhenderson/gomplate/version" "strings" "text/template" -) -func init() { - ver := flag.Bool("v", false, "Print version and exit") - flag.Parse() - if *ver { - fmt.Println(version.Version) - os.Exit(0) - } -} + "github.com/codegangsta/cli" + "github.com/hairyhenderson/gomplate/aws" + "github.com/hairyhenderson/gomplate/version" +) func (g *Gomplate) createTemplate() *template.Template { return template.New("template").Funcs(g.funcMap).Option("missingkey=error") @@ -75,7 +66,18 @@ func NewGomplate() *Gomplate { } } -func main() { +func runTemplate(c *cli.Context) error { g := NewGomplate() g.RunTemplate(os.Stdin, os.Stdout) + return nil +} + +func main() { + app := cli.NewApp() + app.Name = "gomplate" + app.Usage = "Process text files with Go templates" + app.Version = version.Version + app.Action = runTemplate + + app.Run(os.Args) } -- cgit v1.2.3