add -o flag

This commit is contained in:
Mark Bates 2019-11-10 18:43:12 -05:00
parent 2a3000b896
commit 9da9f00821
1 changed files with 6 additions and 2 deletions

View File

@ -4,10 +4,12 @@ import (
"flag"
"fmt"
"os"
"path/filepath"
"sort"
"strings"
"github.com/markbates/pkger"
"github.com/markbates/pkger/here"
"github.com/markbates/pkger/parser"
"github.com/markbates/pkger/pkging/pkgutil"
)
@ -16,6 +18,7 @@ const outName = "pkged.go"
type packCmd struct {
*flag.FlagSet
out string
help bool
subs []command
}
@ -30,7 +33,7 @@ func (e *packCmd) Exec(args []string) error {
return err
}
fp := info.FilePath(outName)
fp := filepath.Join(info.Dir, e.out, outName)
os.RemoveAll(fp)
decls, err := parser.Parse(info)
@ -88,6 +91,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.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage:\n\n")
Usage(os.Stderr, c.FlagSet)()
@ -115,7 +119,7 @@ func Package(out string, decls parser.Decls) error {
}
defer f.Close()
c, err := pkger.Current()
c, err := here.Dir(filepath.Dir(out))
if err != nil {
return err
}