diff --git a/main.go b/main.go index 9dd1b82..fcf7883 100644 --- a/main.go +++ b/main.go @@ -48,11 +48,11 @@ func main() { outdir := flag.String("o", ".", "Output directory") flag.Parse() files := flag.Args() - // if len(files) == 0 { - // Error.Printf("No files specified") - // flag.Usage() - // return - // } + if len(files) == 0 { + Error.Printf("No files specified") + flag.Usage() + return + } ltemplate, err := template.New("class").Funcs(fns).Parse(templatestr) if err != nil { @@ -70,13 +70,7 @@ func main() { Error.Printf("Error parsing file: %v", err) return } - - outfile, err := class.GetOutFile(*outdir) - if err != nil { - Error.Printf("Error creating output file: %v", err) - return - } - ltemplate.Execute(outfile, class) + class.Write(*outdir, ltemplate) }(file) } wg.Wait() diff --git a/types.go b/types.go index 65d7838..a932e12 100644 --- a/types.go +++ b/types.go @@ -5,6 +5,7 @@ import ( "os" "path/filepath" "strings" + "text/template" ) type ( @@ -57,3 +58,15 @@ func (c *Class) GetOutFile(root string) (*os.File, error) { } return f, nil } + +func (c *Class) Write(root string, tmpl *template.Template) error { + outfile, err := c.GetOutFile(root) + if err != nil { + return fmt.Errorf("error creating output file %v: %v", c.ClassName, err) + } + err = tmpl.Execute(outfile, c) + if err != nil { + return fmt.Errorf("error writing output file %v: %v", c.ClassName, err) + } + return nil +}