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

packr2 not parsing flags correctly #141

Closed
andypwarren opened this issue Jan 15, 2019 · 7 comments
Closed

packr2 not parsing flags correctly #141

andypwarren opened this issue Jan 15, 2019 · 7 comments

Comments

@andypwarren
Copy link

andypwarren commented Jan 15, 2019

Hi. I have my application entry point (main.go) in a subdirectory e.g. cmd/main.go and the repo is using go modules. When I run packr2 build -v cmd/main.go it complies the binary fine but it cant find the boxes I setup in the main.go DEBU[2019-01-15T09:49:14Z] found 0 boxes

@andypwarren andypwarren changed the title packr2 not finding box's in subdirectory packr2 not finding boxes in subdirectory Jan 15, 2019
@andypwarren
Copy link
Author

I have tried cd'ing into the cmd directory and running packr2 but it complains it can't find the go.mod file as I have set GO111MODULE=on

@markbates
Copy link
Member

Can you provide a working example and the output of of the commands with -v?

Packr2 follows import paths to find boxes, if you’re not importing a package it won’t find you boxes. If you want the old style, folder walking, then use the skip imports flag.

@andypwarren
Copy link
Author

andypwarren commented Jan 15, 2019

Thanks for the hint about imports. I have got this working now but for others stumbling across this.
I have the following directory structure (a common structure for Cobra CLI projects, although simplified for the purpose of this example)

- cmd/
-- main.go
- templates/
-- hello.txt
- go.mod
- go.sum

Here's the basic main.go file to demonstrate the issue

package main

import (
	"fmt"
	"log"

	"github.com/gobuffalo/packr/v2"
)

func main() {
	box := packr.New("templates", "../templates")
	s, err := box.FindString("hello.txt")
	if err != nil {
		log.Fatalf("error finding string: %v", err)
	}
	fmt.Println(s)
}

I set go module support:
export GO111MODULE=on
in the module root directory I run packr2 with ignore imports
packr2 --ignore-imports -v
Then build it normally with go
go build cmd/main.go
then clean up the generated files
packr2 clean

@andypwarren
Copy link
Author

Although I couldn't get ignore imports to work with the packr2 build command
packr2 --ignore-imports build -v cmd/main.go
I get the following error
flag provided but not defined: -ignore-imports

@dom3k
Copy link

dom3k commented Jan 17, 2019

I have the same. Flag --ignore-imports is not recognize.

@tomhughesnice
Copy link

I found
packr2 --ignore-imports build cmd/main.go would always fail with the error
flag provided but not defined: -ignore-imports

Breaking up the command worked though.

packr2 --ignore-imports build
go build  cmd/main.go

@markbates
Copy link
Member

markbates commented Jan 18, 2019 via email

@markbates markbates changed the title packr2 not finding boxes in subdirectory packr2 not parsing flags correctly Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants