cobra icon indicating copy to clipboard operation
cobra copied to clipboard

Cannot init on new module

Open Jarvvski opened this issue 3 years ago • 17 comments

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.

Jarvvski avatar Jan 23 '22 13:01 Jarvvski

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.

Jarvvski avatar Jan 23 '22 13:01 Jarvvski

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

umarcor avatar Jan 28 '22 19:01 umarcor

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

Jarvvski avatar Jan 30 '22 00:01 Jarvvski

That'd be interesting. Note https://github.com/spf13/cobra/blob/master/CONDUCT.md#deprecation and https://endoflife.date/go as well.

umarcor avatar Feb 01 '22 01:02 umarcor

This issue is being marked as stale due to a long period of inactivity

github-actions[bot] avatar Apr 03 '22 00:04 github-actions[bot]

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

  1. thats a golang support issue and not really relevant to what cobra requires on its own
  2. 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.

johnSchnake avatar Apr 03 '22 03:04 johnSchnake

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.

chaochn47 avatar Apr 07 '22 01:04 chaochn47

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.

addie avatar May 20 '22 16:05 addie

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.

ismet55555 avatar Jun 14 '22 12:06 ismet55555

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.

zekena2 avatar Jun 20 '22 14:06 zekena2

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

rootulp avatar Jul 13 '22 19:07 rootulp

Facing the same issue. go1.19.1

ssarraju avatar Sep 23 '22 20:09 ssarraju

Facing the same issue. go1.19.1

go version go1.17.2 linux/amd64 , no such problem.

XiaoGe2030 avatar Oct 08 '22 13:10 XiaoGe2030

I solved it by these steps:

  • run command go mod tidy and go mod vendor
  • run cobra-cli init

fishingfly avatar Oct 27 '22 07:10 fishingfly

邮件已收到!

XiaoGe2030 avatar Oct 27 '22 07:10 XiaoGe2030

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. It works!

NTHunt avatar Feb 06 '23 09:02 NTHunt

在goland的Terminal中执行 cobra-cli init 应该可以成功的,原因可能是多版本下go的环境变量设置的不全面

syeplz avatar Feb 18 '23 12:02 syeplz

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.

wimvanleuven avatar Jun 17 '23 12:06 wimvanleuven

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.

gastonjarju avatar Jul 28 '23 00:07 gastonjarju