Codebase list golang-github-gobuffalo-packr / 4884052
added some debug functionality Mark Bates 6 years ago
4 changed file(s) with 27 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
3636 Name: name,
3737 }
3838
39 DebugLog("packing file %s\n", f.Name)
40
3941 bb, err := ioutil.ReadFile(path)
4042 if err != nil {
4143 return errors.WithStack(err)
5254 }
5355 f.Contents = strings.Replace(string(bb), "\"", "\\\"", -1)
5456
57 DebugLog("packed file %s\n", f.Name)
5558 b.Files = append(b.Files, f)
5659 return nil
5760 })
1010 "github.com/pkg/errors"
1111 "golang.org/x/sync/errgroup"
1212 )
13
14 var DebugLog func(string, ...interface{})
15
16 func init() {
17 DebugLog = func(string, ...interface{}) {}
18 }
1319
1420 var invalidFilePattern = regexp.MustCompile(`(_test|-packr).go$`)
1521
113119 Files: []file{},
114120 compress: b.Compress,
115121 }
122 DebugLog("building box %s\n", bx.Name)
116123 p := filepath.Join(pk.Dir, bx.Name)
117124 if err := bx.Walk(p); err != nil {
118125 return errors.WithStack(err)
120127 if len(bx.Files) > 0 {
121128 pk.Boxes = append(pk.Boxes, *bx)
122129 }
130 DebugLog("built box %s with %q\n", bx.Name, bx.Files)
123131 }
124132
125133 if len(pk.Boxes) > 0 {
33 Name string
44 Contents string
55 }
6
7 func (f file) String() string {
8 return f.Name
9 }
11
22 import (
33 "context"
4 "fmt"
45 "os"
56
67 "github.com/gobuffalo/packr/builder"
1314 var rootCmd = &cobra.Command{
1415 Use: "packr",
1516 Short: "compiles static files into Go files",
17 PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
18 for _, a := range args {
19 if a == "-v" {
20 builder.DebugLog = func(s string, a ...interface{}) {
21 os.Stdout.WriteString(fmt.Sprintf(s, a...))
22 }
23 break
24 }
25 }
26 return nil
27 },
1628 RunE: func(cmd *cobra.Command, args []string) error {
1729 b := builder.New(context.Background(), input)
1830 b.Compress = compress