Cobra: Generator should support Go modules

Created on 30 Jul 2018  路  5Comments  路  Source: spf13/cobra

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.

Most helpful comment

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

All 5 comments

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 .

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alapidas picture alapidas  路  3Comments

eine picture eine  路  5Comments

umbynos picture umbynos  路  5Comments

diwakergupta picture diwakergupta  路  5Comments

garthk picture garthk  路  3Comments