Skip to content
This repository has been archived by the owner on Jun 25, 2022. It is now read-only.

Commit

Permalink
added verbose flag
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed Apr 9, 2018
1 parent 4884052 commit e1c38da
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,12 @@ func main() {

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).

### Building a Binary (the hard way)
## Building a Binary (the hard way)

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.

```
$ packr
--> packing foo/foo-packr.go
--> packing example-packr.go
```

Then run your `go build command` like normal.
Expand All @@ -136,8 +134,12 @@ When you're done it is recommended that you run the `packr clean` command. This

```
$ packr clean
----> cleaning up example-packr.go
----> cleaning up foo/foo-packr.go
```

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.

---

## Debugging

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.
18 changes: 13 additions & 5 deletions packr/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,24 @@ import (

var input string
var compress bool
var verbose bool

var rootCmd = &cobra.Command{
Use: "packr",
Short: "compiles static files into Go files",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
for _, a := range args {
if a == "-v" {
builder.DebugLog = func(s string, a ...interface{}) {
os.Stdout.WriteString(fmt.Sprintf(s, a...))
if !verbose {
for _, a := range args {
if a == "-v" {
verbose = true
break
}
break
}
}

if verbose {
builder.DebugLog = func(s string, a ...interface{}) {
os.Stdout.WriteString(fmt.Sprintf(s, a...))
}
}
return nil
Expand All @@ -37,6 +44,7 @@ func init() {
pwd, _ := os.Getwd()
rootCmd.Flags().StringVarP(&input, "input", "i", pwd, "path to scan for packr Boxes")
rootCmd.Flags().BoolVarP(&compress, "compress", "z", false, "compress box contents")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "print verbose logging information")
}

// Execute the commands
Expand Down

0 comments on commit e1c38da

Please sign in to comment.