Skip to content

Commit

Permalink
vmconfiger: minor cleanups
Browse files Browse the repository at this point in the history
Use helper function instead of generating the same code every time. Move
header from a bunch of printfs to single template.
  • Loading branch information
jcrussell committed Mar 29, 2017
1 parent 94ed076 commit 84a57a1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 126 deletions.
106 changes: 24 additions & 82 deletions src/minimega/vmconfiger_cli.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 8 additions & 14 deletions src/vmconfiger/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ func (g *Generator) Format() []byte {
func (g *Generator) Run() error {
fs := token.NewFileSet()

t := template.Must(template.New("funcs").Parse(funcsTemplate))
t := template.Must(template.New("header").Parse(headerTemplate))
template.Must(t.New("funcs").Parse(funcsTemplate))
template.Must(t.New("clear").Parse(clearTemplate))
// template name must match the type it intends to generate
template.Must(t.New("int64").Parse(numTemplate))
Expand Down Expand Up @@ -107,19 +108,12 @@ func (g *Generator) Run() error {
}

// Print the header and package clause.
g.Printf("// Code generated by \"vmconfiger %s\"; DO NOT EDIT\n\n", strings.Join(os.Args[1:], " "))
g.Printf("package %s\n", g.pkg.Name)
g.Printf(`import (
"fmt"
"minicli"
log "minilog"
"bytes"
"os"
"path/filepath"
"strconv"
)`)
g.Printf("\n")
g.Printf("var vmconfigerCLIHandlers = []minicli.Handler{\n")
g.Execute("header", struct {
Args, Package string
}{
Args: strings.Join(os.Args[1:], " "),
Package: g.pkg.Name,
})

g.fields = map[string][]Field{}

Expand Down
65 changes: 35 additions & 30 deletions src/vmconfiger/templates.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 84a57a1

Please sign in to comment.