-
Notifications
You must be signed in to change notification settings - Fork 120
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
Go 1.18 workspace support in cobra-cli init #26
Comments
This issue is being marked as stale due to a long period of inactivity |
same here |
Same problem |
This issue is being marked as stale due to a long period of inactivity |
Same problem |
same problem, I have given up on not using go.work |
Same problem |
If your workspace looks something like: #workspace
module1/
module2/
cli
go.work you can do something like mkdir /tmp/cli && cd /tmp/cli
go mod init cli
cobra-cli init
cp /tmp/cli/ /path/to/workspace/cli
cd /path/to/workspace
go work use cli and it will get you the boilerplate you want. |
Solution and temporary fix: |
This issue is being marked as stale due to a long period of inactivity |
@bokunodev , nice workaround. |
This issue is being marked as stale due to a long period of inactivity |
+1 |
Still an issue. Workspaces isn't going anywhere and most new projects will likely use it, so I would recommend prioritizing this issue. |
+1 |
still an issue |
Line 106 in 1d43487
|
When attempting to use
cobra-cli init
in a project that uses Go 1.18's new workspace mode, I hit what looks like a JSON unmarshaling error (Error: invalid character '{' after top-level value
) and initializing fails.My apologies in advance if I'm misunderstanding any aspect of workspaces, modules, or cobra-cli here - I'm fairly new to Go, but expecting this might be a new edge case in 1.18 due to workspaces.
Steps to reproduce
I believe this is because
go list -json -m
returns a stream of JSON objects with relevant modules, whereas this bit of code expects to consume a single JSON object.I spiked out a test in investigating this behavior, which exposes the same behavior as above. But I’m guessing that approach only works for Go 1.18+, and cobra-cli probably wants to support earlier versions. As far as a fix (if we agree it's worth addressing), I was thinking that the
parseModInfo
operations could potentially allow using the current directory (from the output ofgo list -json -e
) to decide which of the JSON objects to use. Thoughts?Workaround
Removing all projects from the workspace except the one I want to
cobra-cli init
does let things work, and that's good enough to unblock me.Additional potential gotcha
In experimenting with removing workspace items, there's another case that has surprising (to me) behavior: if we try running
cobra-cli init
on a module that's not yet included in the workspace.The above appears to succeed, but the contents of
project2/main.go
are now:I'm honestly not sure what behavior I'd expect here, since the module isn't in the workspace. But the import path
project1/tmp/cli-playground/project2/cmd
looks pretty wrong to me (note bothproject1
andproject2
in that path, despite them being peers). I can totally understand this scenario being unsupported / undefined behavior,But I thought it could be useful to include it in this report, both because I think the existing behavior is kind of surprising (I might personally prefer an error), and more importantly because I imagine that the choice of which module to pick from the list in
go list -json -m
could potentially create better behavior here.The text was updated successfully, but these errors were encountered: