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

Allow initialization of cobra project from within a go workspace/monorepo. resolves spf13/cobra-cli#26 #98

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tclancy13
Copy link

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 command go 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 a json.Decoder rather than json.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, using json.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.

@CLAassistant
Copy link

CLAassistant commented Sep 20, 2023

CLA assistant check
All committers have signed the CLA.

@mikerybka
Copy link

I think this is a great solutution. 🚢

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

Successfully merging this pull request may close these issues.

Go 1.18 workspace support in cobra-cli init
3 participants