Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
try packages
Browse files Browse the repository at this point in the history
  • Loading branch information
honnix committed Dec 4, 2019
1 parent e1ca5d8 commit 1d04a9d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
3 changes: 1 addition & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
9 changes: 6 additions & 3 deletions cli/pflags/api/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 1d04a9d

Please sign in to comment.