mirror of https://github.com/markbates/pkger.git
Added -t for specifying conditional build tags
This commit is contained in:
parent
a78c11e368
commit
bc0ae93dc6
|
@ -30,6 +30,7 @@ const outName = "pkged.go"
|
|||
type packCmd struct {
|
||||
*flag.FlagSet
|
||||
out string
|
||||
tags string
|
||||
help bool
|
||||
include slice
|
||||
subs []command
|
||||
|
@ -53,7 +54,7 @@ func (e *packCmd) Exec(args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := Package(info, fp, decls); err != nil {
|
||||
if err := Package(info, fp, decls, e.tags); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -104,6 +105,7 @@ func New() (*packCmd, error) {
|
|||
c.FlagSet = flag.NewFlagSet("pkger", flag.ExitOnError)
|
||||
c.BoolVar(&c.help, "h", false, "prints help information")
|
||||
c.StringVar(&c.out, "o", "", "output directory for pkged.go")
|
||||
c.StringVar(&c.tags, "t", "", "conditional build tag(s) for pkged.go")
|
||||
c.Var(&c.include, "include", "packages the specified file or directory")
|
||||
c.Usage = func() {
|
||||
fmt.Fprintf(os.Stderr, "Usage:\n\n")
|
||||
|
@ -123,7 +125,7 @@ func (e *packCmd) Flags() *flag.FlagSet {
|
|||
return e.FlagSet
|
||||
}
|
||||
|
||||
func Package(info here.Info, out string, decls parser.Decls) error {
|
||||
func Package(info here.Info, out string, decls parser.Decls, tags string) error {
|
||||
c, err := here.Dir(filepath.Dir(out))
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -142,6 +144,9 @@ func Package(info here.Info, out string, decls parser.Decls) error {
|
|||
}
|
||||
defer f.Close()
|
||||
|
||||
if len(tags) > 0 {
|
||||
fmt.Fprintf(f, "// +build %s\n\n", tags)
|
||||
}
|
||||
fmt.Fprintf(f, "// Code generated by pkger; DO NOT EDIT.\n\n")
|
||||
fmt.Fprintf(f, "package %s\n\n", c.Name)
|
||||
fmt.Fprintf(f, "import (\n\t\"github.com/markbates/pkger\"\n\t")
|
||||
|
|
Loading…
Reference in New Issue