Allow initialization of cobra project from within a go workspace/monorepo. resolves spf13/cobra-cli#26#98
Open
tclancy13 wants to merge 1 commit intospf13:mainfrom
Open
Conversation
|
I think this is a great solutution. 🚢 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves spf13/cobra-cli#26
Running
cobra-cli init...in a module that is part of a go workspace fails because of a JSON parsing error. The error is the result of expecting a single object from the commandgo list -json -mbut receiving multiple objects - one for each of the modules in the workspace.By setting the environment variable GOWORK=off before running cobra-cli, the
go list -json -mcommand reverts back to returning the single object cobra-cli expects.An alternative solution would be to parse the output of the
go list -json -mcommand with ajson.Decoderrather thanjson.Unmarshaland match the module directory to the correct object decoded. The environment variable solution implemented here seemed cleaner to implement - however should cobra-cli require further interaction with workspaces going forward, usingjson.Decodermay be a more appropriate approach, at which point this environment variable must be removed.No new tests were created for this fix as none of the existing tests pass as is.