Go modules will be released soon, and the cobra generator should be updated to respect them. Currently, it always generates into GOPATH, but when run in a repository that has a go.mod file, it should instead generate into the current directory.
is there any workaround for this?
I believe my problem is related.
When I run cobra init or cobra add my_special_command using Go 1.11.1 in a Go project folder outside of GOPATH, having go.mod, it outputs:
Using config file: /home/user/.cobra.yaml
Error: Rel: can't make /home/user/path/to/non-gopath/my_project relative to
I just moved the project into the GOPATH in order to use cobra init/add and then moved it back into my project folder which worked fine.
Hope at some point it will support go modules though.
From bash or similar shells you can use:
$ GOPATH=$HOME/workspace cobra add my_new_command
my_new_command created at /home/me/workspace/src/.../my_project/cmd/my_new_commnd_roll.go
This should be resolved by #817 .
Most helpful comment
I believe my problem is related.
When I run
cobra initorcobra add my_special_commandusing Go 1.11.1 in a Go project folder outside ofGOPATH, havinggo.mod, it outputs: