Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cobra-Cli init Error #31

Closed
aleite31 opened this issue Apr 14, 2022 · 14 comments
Closed

Cobra-Cli init Error #31

aleite31 opened this issue Apr 14, 2022 · 14 comments

Comments

@aleite31
Copy link

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

Go version : 1.18.1
VsCode : 1.66.1

@manicar2093
Copy link

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 🤔

@tahsinrahman
Copy link

tahsinrahman commented May 16, 2022

i'm having the same issue

go version 1.18.1

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

@angelorc
Copy link

same here, the issue appear if you use go work

@kcmvp
Copy link

kcmvp commented Jun 11, 2022

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

@fseesink
Copy link

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.

@tomato-ga
Copy link

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

@marckhouzam
Copy link
Collaborator

I am running into a similar problem with init.

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

Try ./cobra-cli init

@tomato-ga
Copy link

@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

@DevolvingSpud
Copy link

DevolvingSpud commented Jul 4, 2022

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.

@ezk84
Copy link

ezk84 commented Aug 22, 2022

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

@ebarti
Copy link

ebarti commented Sep 16, 2022

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

@marckhouzam
Copy link
Collaborator

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
Copy link
Collaborator

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

@marckhouzam
Copy link
Collaborator

Duplicate of #26

@marckhouzam marckhouzam marked this as a duplicate of #26 Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests