cobra-cli icon indicating copy to clipboard operation
cobra-cli copied to clipboard

Cobra-Cli init Error

Open aleite31 opened this issue 2 years ago • 9 comments

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

Go version : 1.18.1 VsCode : 1.66.1

aleite31 avatar Apr 14 '22 13:04 aleite31

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 🤔

manicar2093 avatar May 02 '22 19:05 manicar2093

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

tahsinrahman avatar May 16 '22 01:05 tahsinrahman

same here, the issue appear if you use go work

angelorc avatar May 27 '22 22:05 angelorc

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

kcmvp avatar Jun 11 '22 09:06 kcmvp

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.

fseesink avatar Jun 18 '22 02:06 fseesink

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

tomato-ga avatar Jun 22 '22 11:06 tomato-ga

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 avatar Jun 22 '22 13:06 marckhouzam

@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

tomato-ga avatar Jun 22 '22 13:06 tomato-ga

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.

DevolvingSpud avatar Jul 04 '22 16:07 DevolvingSpud

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

ezk84 avatar Aug 22 '22 18:08 ezk84

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

ebarti avatar Sep 16 '22 19:09 ebarti

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.

marckhouzam avatar Sep 19 '22 01:09 marckhouzam

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

marckhouzam avatar Sep 19 '22 01:09 marckhouzam

Duplicate of #26

marckhouzam avatar Sep 19 '22 01:09 marckhouzam