cobra
cobra copied to clipboard
Cannot init on new module
I'm not sure what I'm doing wrong here.
I've installed cobra via: go install github.com/spf13/cobra/cobra
Now, when I run a cobra init
, anywhere I get just
Error: exit status 1
I don't even see where logs are going, or how I can try and debug this. Really, this error code isn't giving me much at all to go off.
It seems like it's due to using an out dated version of go, but I don't see a specific version required in the readme?
The version installable via apt
is pretty bad. golang-go
is on 1.13
I think, which is what I had installed.
Using linuxbrew, I could get 1.17
, so after swapping those around cobra init --viper
etc works great.
but I don't see a specific version required in the readme?
You can check the versions tested in CI:
- https://github.com/spf13/cobra/actions/runs/1664856023
- https://github.com/spf13/cobra/blob/master/.github/workflows/test.yml#L34-L38
but I don't see a specific version required in the readme?
You can check the versions tested in CI:
* https://github.com/spf13/cobra/actions/runs/1664856023 * https://github.com/spf13/cobra/blob/master/.github/workflows/test.yml#L34-L38
That's definitely a reference, but I wouldn't consider that clear
Can I open a PR to add it to the readme? Just something there would be good. Even like 14+
etc
That'd be interesting. Note https://github.com/spf13/cobra/blob/master/CONDUCT.md#deprecation and https://endoflife.date/go as well.
This issue is being marked as stale due to a long period of inactivity
Hi @Jarvvski , thanks for the ticket. What would you recommend adding to the README? I wouldn't be against it if it was something that added value, but my concern is that it wouldn't; maybe I'm imagining the issue differently than you though.
The way I interpret this thread is that the only thing we could add to the README would be something like ensure you are using a supported version of go when running 'go install...'
. But
- thats a golang support issue and not really relevant to what cobra requires on its own
- its a bit implicit that versions aren't supported forever so why bother saying 'when using go, ensure its a relatively recent version if you want support'
Do you think you have a different way to express the issue/requirement in a way that adds more value than that? To be fair, I wouldn't have automatically known to try and upgrade Go so it is slightly difficult to debug on the surface. But I think thats the point: that it's an edge case that most people don't run into since it's an implicit assumption that the rest of your toolchain must be in a 'healthy state'. There are probably other problems (libraries, os requirements, etc) that could also interfere with the behavior of go install...
but we wouldn't put them in the readme unless it was a common problem or something specific to cobra.
Happy to talk about it though.
I faced the same issue after first successful run of cobra-cli init
and delete root.go
and License
files.
$ go version
go version go1.17.5 darwin/amd64
$ cobra-cli init
Using config file: /Users/chaochn/.cobra.yaml
Error: exit status 1
cobra-cli
definitely needs to do print some error logs for debugging purpose instead of swallowing it.
Update:
Removed github.com/spf13/cobra v1.4.0 // indirect
in go.mod
fixes the issue.
I am hoping if there is a convenient cobra-cli revert
subcommand.
cobra-cli init
must be run inside of a directory with an existing go.mod
. Try running go mod init <MODNAME>
first and then cobra-cli init
.
I ran into the same issue as the beginning of this post showed. Same error with cobra-cli init
. I am using Linux Ubuntu 20.04.4 x86_64.
After updating from golang version 1.13
to 1.18.3
, it worked.
I had go version 1.18.3 and ran into the same error but my problem was I didn't run go mod init. the error should state that though whether the problem is outdated go version or missing go.mod file. I know that it mostly it's a user problem who didn't read the documentation very well (like me) but still a meaningful error is always good.
I'm also observing this error.
go version: go version go1.18.3 darwin/amd64
$ cobra-cli init
Using config file: /Users/rootulp/.cobra.yaml
Error: exit status 1
Facing the same issue. go1.19.1
Facing the same issue. go1.19.1
go version go1.17.2 linux/amd64 , no such problem.
I solved it by these steps:
- run command
go mod tidy
andgo mod vendor
- run
cobra-cli init
邮件已收到!
cobra-cli init
must be run inside of a directory with an existinggo.mod
. Try runninggo mod init <MODNAME>
first and thencobra-cli init
. It works!
在goland的Terminal中执行 cobra-cli init
应该可以成功的,原因可能是多版本下go的环境变量设置的不全面
I had the same issue, but due to a go.mod file in the root of my $GOPATH. Deleting $GOPATH/go.mod fixed the problem.
I am using the new Mac M2 and after doing "go mod init github.com/spf13/<appName>", I still get the command not found error when I run "cobra-cli init." Any suggestions? I have followed all the above discussions, but still no resolve.