cobra-cli
cobra-cli copied to clipboard
Cobra-Cli init Error
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. https://github.com/spf13/cobra-cli/issues/26
same here, the issue appear if you use go work
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
- mkdir Test
- cd Test
- go mod init cobratest
- 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
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.

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