diff --git a/apply.go b/apply.go index e90b1d8..c7e9160 100644 --- a/apply.go +++ b/apply.go @@ -1,16 +1,20 @@ package pkger import ( + "log" + "os" "sync" "github.com/markbates/pkger/pkging" + "github.com/markbates/pkger/pkging/pkgutil" ) var current pkging.Pkger var gil = &sync.RWMutex{} func Apply(pkg pkging.Pkger, err error) error { - if err != nil { + if err := pkgutil.Dump(os.Stdout, pkg); err != nil { + log.Fatal(err) return err } gil.Lock() diff --git a/pkging/pkgutil/dump.go b/pkging/pkgutil/dump.go new file mode 100644 index 0000000..fa214bd --- /dev/null +++ b/pkging/pkgutil/dump.go @@ -0,0 +1,46 @@ +package pkgutil + +import ( + "encoding/json" + "io" + "os" + + "github.com/markbates/pkger/here" + "github.com/markbates/pkger/pkging" +) + +func Dump(w io.Writer, pkg pkging.Pkger) error { + d := struct { + Info here.Info + Paths map[string]os.FileInfo + }{ + Paths: map[string]os.FileInfo{}, + } + + info, err := pkg.Current() + if err != nil { + return err + } + d.Info = info + + err = pkg.Walk("/", func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + + d.Paths[path] = info + return nil + }) + if err != nil { + return err + } + + enc := json.NewEncoder(w) + enc.SetIndent("", " ") + + if err := enc.Encode(d); err != nil { + return err + } + + return nil +}