package main import ( "flag" "fmt" "io" "log" "os" "text/template" _ "embed" ) //go:embed class.tmpl var templatestr string var Error *log.Logger var Warning *log.Logger func init() { log.SetFlags(log.Lmicroseconds | log.Lshortfile) logger := io.MultiWriter(os.Stdout) log.SetOutput(logger) Error = log.New(io.MultiWriter(os.Stderr, os.Stdout), fmt.Sprintf("%sERROR:%s ", "\033[0;101m", "\033[0m"), log.Lmicroseconds|log.Lshortfile) Warning = log.New(io.MultiWriter(os.Stdout), fmt.Sprintf("%sWarning:%s ", "\033[0;93m", "\033[0m"), log.Lmicroseconds|log.Lshortfile) } var fns = template.FuncMap{ "plus1": func(x int) int { return x + 1 }, } func main() { flag.Parse() files := flag.Args() // if len(files) == 0 { // Error.Printf("No files specified") // flag.Usage() // return // } test := Class{ ClassName: "Test", Fields: []Field{ {Name: "a", Type: "int", Comment: "test"}, {Name: "b", Type: "string", Comment: "test"}, }, Methods: []Method{ { Name: "test", Params: []Param{ {Name: "a", Type: "int", Comment: "test param 1"}, {Name: "b", Type: "string", Comment: "test param 2"}, }, Returns: []Return{ {Type: "int", Comment: "test return int"}, {Type: "string", Comment: "test return string"}, }, Comment: "test method", }, { Name: "test2", Params: []Param{ {Name: "a", Type: "int", Comment: "test param 1"}, {Name: "b", Type: "string", Comment: "test param 2"}, }, Returns: []Return{ {Type: "int", Comment: "test return int"}, {Type: "string", Comment: "test return string"}, }, Comment: "test method", }, }, } ltemplate, err := template.New("class").Funcs(fns).Parse(templatestr) if err != nil { Error.Printf("Error parsing template: %v", err) return } outfile, err := test.GetOutFile() if err != nil { Error.Printf("Error creating output file: %v", err) return } ltemplate.Execute(outfile, test) for _, file := range files { fmt.Println(file) } }