spf13 / cobra-cli

Cobra CLI tool to generate applications and commands

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cobra-Cli init Error

aleite31 opened this issue · comments

Error using "cobra-cli ini" --> Error: invalid character '{' after top-level value

Go version : 1.18.1
VsCode : 1.66.1

Don't you have a typo on your command? It's cobra-cli init

I'm using the same go version and I did not have this problem 🤔

i'm having the same issue

go version 1.18.1

update: seems it only occurs with go.work. #26

same here, the issue appear if you use go work

commented

i'm having the same issue

go version 1.18.1

update: seems it only occurs with go.work. #26

yes, my project is in a workspace. it's very easy to reproduce
1: create a workspace
2: init first normal module project
3: create a cobra module
4: run cobra-cli init --- runs into error

I am experiencing the same with Go 1.18.3 on macOS 12.4 "Monterey". And like the others, I, too, am in Go workspace.

If instead, at my Desktop or just a directory that's not a Go workspace, I simply

  1. mkdir Test
  2. cd Test
  3. go mod init cobratest
  4. cobra-cli init

then all is well.

So there definitely seems to be something with regard to the Go workspace feature for some reason.

I am running into a similar problem with init.

~/go/src/cobra cobra-cli init
cobra-cli: command not found

Installation is done
スクリーンショット 2022-06-22 20 04 29

I am running into a similar problem with init.

~/go/src/cobra cobra-cli init cobra-cli: command not found

Try ./cobra-cli init

@marckhouzam

Thx!
It didn't seem to work because I was running it in a VS code terminal,
I tried it with an SSH connection and it worked.

スクリーンショット 2022-06-22 22 45 53

Seeing the same issue here, first module worked, second is unhappy in exactly the same way as the above with the error:

Error: invalid character '{' after top-level value

I worked around it by doing the init in a directory not under the workspace, then copying everything in. Once that's in place, the other commands (add etc.) seem to work.

Running into this also, and also using a workspace. Followed @DevolvingSpud's workaround for now.

Same here, go workspaces are quite a disappointing feature to be honest, they seem to create more issues than anything.

When doing an init, the cobra-cli runs go list -json -m to get information about the current module.
When using go workspaces, that command returns all modules in the workspace, which looks something like this:

$ go list -json -m
{
	"Path": "github.com/marckhouzam/cli",
	"Main": true,
	"Dir": "/Users/kmarc/tmp/cli",
	"GoMod": "/Users/kmarc/tmp/cli/go.mod",
	"GoVersion": "1.18"
}
{
	"Path": "github.com/marckhouzam/cli2",
	"Main": true,
	"Dir": "/Users/kmarc/tmp/cli2",
	"GoMod": "/Users/kmarc/tmp/cli2/go.mod",
	"GoVersion": "1.18"
}

This a a case the cobra-cli is not handling. We need to handle workspaces properly.

Ah yes, I see this was reported in #26. Sorry for the noise.

Duplicate of #26