codegen: add ability to insert comments and blank lines into the generated code
Some checks failed
CI / build-docker (push) Successful in 4s
CI / build-docker-bootstrap (push) Has been skipped
CI / release-test (push) Failing after 12s

This commit is contained in:
2026-02-15 14:54:22 -08:00
parent 8ab21edae9
commit d6426bba14
3 changed files with 197 additions and 24 deletions

View File

@@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"go/ast"
"go/printer"
"go/token"
"os"
@@ -37,11 +36,9 @@ var generate_model = &cobra.Command{
return ErrNoSuchTable
}
fset := token.NewFileSet()
if Must(cmd.Flags().GetBool("test")) {
file2 := modelgenerate.GenerateModelTestAST(table, modname)
PanicIf(printer.Fprint(os.Stdout, fset, file2))
PanicIf(modelgenerate.FprintWithComments(os.Stdout, file2))
} else {
decls := []ast.Decl{
&ast.GenDecl{
@@ -81,7 +78,7 @@ var generate_model = &cobra.Command{
Decls: decls,
}
PanicIf(printer.Fprint(os.Stdout, fset, file))
PanicIf(modelgenerate.FprintWithComments(os.Stdout, file))
}
return nil