Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #53 from markbates/handle-main
Browse files Browse the repository at this point in the history
handle main packages
  • Loading branch information
markbates authored Dec 11, 2019
2 parents b0a67f7 + 945a3a2 commit 5497054
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 20 deletions.
8 changes: 7 additions & 1 deletion cmd/pkger/cmds/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,13 @@ func Package(info here.Info, out string, decls parser.Decls) error {
if err != nil {
return err
}
fmt.Fprintf(f, "package %s\n\n", c.Name)

name := c.Name
if info.Module.Main {
name = "main"
}

fmt.Fprintf(f, "package %s\n\n", name)
fmt.Fprintf(f, "import (\n\t\"github.com/markbates/pkger\"\n\t")
fmt.Fprintf(f, "\"github.com/markbates/pkger/pkging/mem\"\n)\n\n")
fmt.Fprintf(f, "var _ = pkger.Apply(mem.UnmarshalEmbed([]byte(`")
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
Expand Down
18 changes: 0 additions & 18 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ func Test_Parser_Ref(t *testing.T) {
fmt.Println(f.Path)
}
r.Len(files, 25)

for _, f := range files {
if f.Path.Pkg == ref.Module.Path {
r.True(strings.HasPrefix(f.Abs, ref.Dir), "%q %q", f.Abs, ref.Dir)
} else {
r.False(strings.HasPrefix(f.Abs, ref.Dir), "%q %q", f.Abs, ref.Dir)
}
}
}

func Test_Parser_Ref_Include(t *testing.T) {
Expand All @@ -75,19 +67,9 @@ func Test_Parser_Ref_Include(t *testing.T) {

files, err := res.Files()
r.NoError(err)
// t.FailNow()

l := len(files)
r.Equal(26, l)
// r.Len(files, 27)

for _, f := range files {
if f.Path.Pkg == ref.Module.Path {
r.True(strings.HasPrefix(f.Abs, ref.Dir), "%q %q", f.Abs, ref.Dir)
} else {
r.False(strings.HasPrefix(f.Abs, ref.Dir), "%q %q", f.Abs, ref.Dir)
}
}
}

func Test_Parser_Example_HTTP(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion pkging/pkgtest/ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func NewRef() (*Ref, error) {
if err != nil {
return nil, err
}

root := filepath.Join(
her.Module.Dir,
"pkging",
Expand Down

0 comments on commit 5497054

Please sign in to comment.