diff --git a/.goreleaser.yml b/.goreleaser.yml index 36add3d..dc49d22 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,10 +1,9 @@ before: hooks: - - dep ensure -vendor-only + - go mod download builds: - env: - CGO_ENABLED=0 - - GO111MODULE=off main: ./cli/pflags/main.go binary: pflags goos: diff --git a/cli/pflags/api/generator.go b/cli/pflags/api/generator.go index 2588c8d..09643b3 100644 --- a/cli/pflags/api/generator.go +++ b/cli/pflags/api/generator.go @@ -3,14 +3,13 @@ package api import ( "context" "fmt" - "go/token" "go/types" "path/filepath" "strings" "github.com/lyft/flytestdlib/logger" - "go/importer" + "golang.org/x/tools/go/packages" "github.com/ernesto-jimenez/gogen/gogenutil" ) @@ -301,10 +300,14 @@ func NewGenerator(pkg, targetTypeName, defaultVariableName string) (*PFlagProvid pkg = gogenutil.StripGopath(pkg) } - targetPackage, err := importer.ForCompiler(token.NewFileSet(), "source", nil).Import(pkg) + config := &packages.Config{ + Mode: packages.NeedTypes | packages.NeedTypesInfo, + } + loadedPkgs, err := packages.Load(config, pkg) if err != nil { return nil, err } + targetPackage := loadedPkgs[0].Types obj := targetPackage.Scope().Lookup(targetTypeName) if obj == nil { diff --git a/go.mod b/go.mod index 05744ff..3050fc8 100644 --- a/go.mod +++ b/go.mod @@ -46,7 +46,7 @@ require ( golang.org/x/net v0.0.0-20191021144547-ec77196f6094 // indirect golang.org/x/sys v0.0.0-20191020212454-3e7259c5e7c2 // indirect golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 - golang.org/x/tools v0.0.0-20191018212557-ed542cd5b28a + golang.org/x/tools v0.0.0-20191204011308-9611592c72f6 google.golang.org/api v0.11.1-0.20191020000718-bf72a15fd9e9 // indirect google.golang.org/appengine v1.6.5 // indirect google.golang.org/grpc v1.24.0 // indirect diff --git a/go.sum b/go.sum index 4167732..4df02b5 100644 --- a/go.sum +++ b/go.sum @@ -295,6 +295,8 @@ golang.org/x/tools v0.0.0-20190927191325-030b2cf1153e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191010171213-8abd42400456/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191018212557-ed542cd5b28a h1:UuQ+70Pi/ZdWHuP4v457pkXeOynTdgd/4enxeIO/98k= golang.org/x/tools v0.0.0-20191018212557-ed542cd5b28a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191204011308-9611592c72f6 h1:BP62y4oUl8+/CvHuvVqHIPmVRixgDl6y6a+tR7pXXIA= +golang.org/x/tools v0.0.0-20191204011308-9611592c72f6/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=