Hi, I tried using the following: cobra init gitHub.com/pookah-net/test, from go/src, as specified in the README, to create a new Golang project using Cobra, and it kept telling me Error: required flag(s) "pkg-name" not set and giving me the help text.
I finally (!) figured out that cobra init --pkg-name gitHub.com/pookah-net/test was needed, instead. Is it supposed to be that way?
(Oh, it didn't create the src/github.com/pookah-net/test folder. Instead, it created src/cmd/root.go, and src/main.go and src/LICENSE files and folders!)
Thanks
Ian
Hi @pookah-net! This is being addressed in #878 nad #888. #891 is also related.
To achieve the behaviour you expect, you need to use either:
cobra init ${GOPATH}/src/gitHub.com/pookah-net/test --pkg-name=gitHub.com/pookah-net/test
or
mkdir gitHub.com/pookah-net/test
cd gitHub.com/pookah-net/test
cobra init --pkg-name=gitHub.com/pookah-net/test
@jharshman, would cobra init work in the second case, provided that it is being executed from ${GOPATH}/src/gitHub.com/pookah-net/test?
Ah, I see! I must have used the wrong search terms, because I didn't see those others.
Thanks!
@umarcor, yes but would still require --pkg-name
@pookah-net documentation on the cobra generator is being updated. In the meantime you can refer to the issues that @umarcor linked as well as https://github.com/spf13/cobra/pull/817
@umarcor, yes but would still require
--pkg-name
So, GOPATH is completely deprecated? I.e, even if cobra init is executed from a 'valid' and empty location (i.e. ${GOPATH}/src/gitHub.com/pookah-net/test), it will not infer pkg-name automatically? I'm not suggesting it is wrong, I just want to be sure about it.
@umarcor correct, the generator no longer cares about the GOPATH.
@jharshman, thanks!
@pookah-net, can you please close this issue? I believe that it is solved already.
Thanks!
you'd think a cli generator should not have issues with it's own cli :)
Most helpful comment
Hi @pookah-net! This is being addressed in #878 nad #888. #891 is also related.
To achieve the behaviour you expect, you need to use either:
cobra init ${GOPATH}/src/gitHub.com/pookah-net/test --pkg-name=gitHub.com/pookah-net/testor
@jharshman, would
cobra initwork in the second case, provided that it is being executed from${GOPATH}/src/gitHub.com/pookah-net/test?