Files
avorion-docgen/main.go
2024-09-12 00:24:47 +02:00

76 lines
1.5 KiB
Go

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)
}
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"},
{Name: "b", Type: "string", Comment: "test"},
},
Returns: []Return{
{Type: "int", Comment: "test"},
{Type: "string", Comment: "test"},
},
Comment: "test",
},
},
}
ltemplate, err := template.New("class").Parse(templatestr)
if err != nil {
Error.Printf("Error parsing template: %v", err)
return
}
log.Printf("%#v", ltemplate)
ltemplate.Execute(os.Stdout, test)
for _, file := range files {
fmt.Println(file)
}
}