Merge pull request #25 from markbates/out-flag

add -o flag
This commit is contained in:
Mark Bates 2019-11-10 15:49:12 -08:00 committed by GitHub
commit 834898d6b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import (
"strings" "strings"
"github.com/markbates/pkger" "github.com/markbates/pkger"
"github.com/markbates/pkger/here"
"github.com/markbates/pkger/parser" "github.com/markbates/pkger/parser"
"github.com/markbates/pkger/pkging/pkgutil" "github.com/markbates/pkger/pkging/pkgutil"
) )
@ -17,6 +18,7 @@ const outName = "pkged.go"
type packCmd struct { type packCmd struct {
*flag.FlagSet *flag.FlagSet
out string
help bool help bool
subs []command subs []command
} }
@ -31,7 +33,7 @@ func (e *packCmd) Exec(args []string) error {
return err return err
} }
fp := filepath.Join(info.Dir, outName) fp := filepath.Join(info.Dir, e.out, outName)
os.RemoveAll(fp) os.RemoveAll(fp)
decls, err := parser.Parse(info) decls, err := parser.Parse(info)
@ -89,6 +91,7 @@ func New() (*packCmd, error) {
c.FlagSet = flag.NewFlagSet("pkger", flag.ExitOnError) c.FlagSet = flag.NewFlagSet("pkger", flag.ExitOnError)
c.BoolVar(&c.help, "h", false, "prints help information") c.BoolVar(&c.help, "h", false, "prints help information")
c.StringVar(&c.out, "o", "", "output directory for pkged.go")
c.Usage = func() { c.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage:\n\n") fmt.Fprintf(os.Stderr, "Usage:\n\n")
Usage(os.Stderr, c.FlagSet)() Usage(os.Stderr, c.FlagSet)()
@ -116,7 +119,7 @@ func Package(out string, decls parser.Decls) error {
} }
defer f.Close() defer f.Close()
c, err := pkger.Current() c, err := here.Dir(filepath.Dir(out))
if err != nil { if err != nil {
return err return err
} }