Merge pull request #80 from taiyangc/master

Fix pkger generating the wrong package name for pkger.go
This commit is contained in:
Mark Bates 2020-03-11 14:37:04 -04:00 committed by GitHub
commit a78c11e368
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 11 deletions

View File

@ -124,6 +124,11 @@ func (e *packCmd) Flags() *flag.FlagSet {
} }
func Package(info here.Info, out string, decls parser.Decls) error { func Package(info here.Info, out string, decls parser.Decls) error {
c, err := here.Dir(filepath.Dir(out))
if err != nil {
return err
}
os.RemoveAll(out) os.RemoveAll(out)
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {
@ -137,18 +142,8 @@ func Package(info here.Info, out string, decls parser.Decls) error {
} }
defer f.Close() defer f.Close()
c, err := here.Dir(filepath.Dir(out))
if err != nil {
return err
}
name := c.Name
if info.Module.Main {
name = "main"
}
fmt.Fprintf(f, "// Code generated by pkger; DO NOT EDIT.\n\n") fmt.Fprintf(f, "// Code generated by pkger; DO NOT EDIT.\n\n")
fmt.Fprintf(f, "package %s\n\n", name) fmt.Fprintf(f, "package %s\n\n", c.Name)
fmt.Fprintf(f, "import (\n\t\"github.com/markbates/pkger\"\n\t") 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, "\"github.com/markbates/pkger/pkging/mem\"\n)\n\n")
fmt.Fprintf(f, "var _ = pkger.Apply(mem.UnmarshalEmbed([]byte(`") fmt.Fprintf(f, "var _ = pkger.Apply(mem.UnmarshalEmbed([]byte(`")