Codebase list golang-github-gobuffalo-packr / e1c38da
added verbose flag Mark Bates 6 years ago
2 changed file(s) with 20 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
115115
116116 When it comes time to build, or install, your Go binary, simply use `packr build` or `packr install` just as you would `go build` or `go install`. All flags for the `go` tool are supported and everything works the way you expect, the only difference is your static assets are now bundled in the generated binary. If you want more control over how this happens, looking at the following section on building binaries (the hard way).
117117
118 ### Building a Binary (the hard way)
118 ## Building a Binary (the hard way)
119119
120120 Before you build your Go binary, run the `packr` command first. It will look for all the boxes in your code and then generate `.go` files that pack the static files into bytes that can be bundled into the Go binary.
121121
122122 ```
123123 $ packr
124 --> packing foo/foo-packr.go
125 --> packing example-packr.go
126124 ```
127125
128126 Then run your `go build command` like normal.
135133
136134 ```
137135 $ packr clean
138 ----> cleaning up example-packr.go
139 ----> cleaning up foo/foo-packr.go
140136 ```
141137
142138 Why do you want to do this? Packr first looks to the information stored in these generated files, if the information isn't there it looks to disk. This makes it easy to work with in development.
139
140 ---
141
142 ## Debugging
143
144 The `packr` command passes all arguments down to the underlying `go` command, this includes the `-v` flag to print out `go build` information. Packr looks for the `-v` flag, and will turn on its own verbose logging. This is very useful for trying to understand what the `packr` command is doing when it is run.
1010
1111 var input string
1212 var compress bool
13 var verbose bool
1314
1415 var rootCmd = &cobra.Command{
1516 Use: "packr",
1617 Short: "compiles static files into Go files",
1718 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...))
19 if !verbose {
20 for _, a := range args {
21 if a == "-v" {
22 verbose = true
23 break
2224 }
23 break
25 }
26 }
27
28 if verbose {
29 builder.DebugLog = func(s string, a ...interface{}) {
30 os.Stdout.WriteString(fmt.Sprintf(s, a...))
2431 }
2532 }
2633 return nil
3643 pwd, _ := os.Getwd()
3744 rootCmd.Flags().StringVarP(&input, "input", "i", pwd, "path to scan for packr Boxes")
3845 rootCmd.Flags().BoolVarP(&compress, "compress", "z", false, "compress box contents")
46 rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "print verbose logging information")
3947 }
4048
4149 // Execute the commands