Skip to content

Commit

Permalink
Refactors build methods onto Context object
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmoran committed Sep 14, 2019
1 parent b7fbf22 commit cf71c4d
Show file tree
Hide file tree
Showing 6 changed files with 625 additions and 599 deletions.
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ Flags:
defer output.Close()

buffer := bytes.NewBuffer([]byte{})
tree := rendering.Build(iface).AST()
context := rendering.NewContext()
tree := context.Build(iface).AST()

err = format.Node(buffer, token.NewFileSet(), tree)
if err != nil {
Expand All @@ -97,7 +98,7 @@ Flags:
stderr.Fatalf("could not determine output absolute path: %s", err)
}

result, err := imports.Process(outputPath, buffer.Bytes(), nil)
result, err := imports.Process(outputPath, buffer.Bytes(), &imports.Options{FormatOnly: false})
if err != nil {
stderr.Fatalf("could not process imports: %s\n\n%s", err, buffer.String())
}
Expand Down
13 changes: 12 additions & 1 deletion parsing/argument.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
package parsing

import "go/types"
import (
"go/types"
)

type Argument struct {
Name string
Type types.Type
Variadic bool
Package string
}

func NewArgument(v *types.Var, variadic bool) Argument {
var pkg string
if t, ok := v.Type().(*types.Named); ok {
if t.Obj().Pkg() != nil {
pkg = t.Obj().Pkg().Path()
}
}

return Argument{
Name: v.Name(),
Type: v.Type(),
Variadic: variadic,
Package: pkg,
}
}
Loading

0 comments on commit cf71c4d

Please sign in to comment.