Allow initialization of cobra project from within a go workspace/monorepo. resolves spf13/cobra-cli#26 #98
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 -m
but 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 -m
command reverts back to returning the single object cobra-cli expects.An alternative solution would be to parse the output of the
go list -json -m
command with ajson.Decoder
rather thanjson.Unmarshal
and 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.Decoder
may 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.