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

Command passed to SetHelpFunc doesn't have a context #2240

Closed
Frassle opened this issue Feb 20, 2025 · 1 comment · Fixed by #2241
Closed

Command passed to SetHelpFunc doesn't have a context #2240

Frassle opened this issue Feb 20, 2025 · 1 comment · Fixed by #2241

Comments

@Frassle
Copy link
Contributor

Frassle commented Feb 20, 2025

When using SetHelpFunc the function gets given a Command object and you'd think you could use Context() to get the right context off the command, but it doesn't actually get set.

We hit this in pulumi: pulumi/pulumi#18659

I can work around via just a context.Background call instead, but feels like this should just work as the parent "help" command does have a context.

@Frassle
Copy link
Contributor Author

Frassle commented Feb 20, 2025

Will see if I can raise a PR to fix this.

Frassle added a commit to Frassle/cobra that referenced this issue Feb 20, 2025
Frassle added a commit to Frassle/cobra that referenced this issue Feb 20, 2025
github-merge-queue bot pushed a commit to pulumi/pulumi that referenced this issue Feb 20, 2025
Fixes #18659

Comment in code pretty much covers it, but repeating here:

You'd think you could use cmd.Context() in the help function but cobra
doesn't set context on the cmd even though the parent help command has
it. I've raised spf13/cobra#2240 to see about
fixing it.
Frassle added a commit to Frassle/cobra that referenced this issue Feb 20, 2025
Frassle added a commit to Frassle/cobra that referenced this issue Feb 20, 2025
marckhouzam pushed a commit that referenced this issue Feb 21, 2025
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 a pull request may close this issue.

1 participant