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

Use PreRunE for sub-commands #165

Merged
merged 1 commit into from
Feb 28, 2024
Merged

Conversation

bschimke95
Copy link
Contributor

By default, PersistentPreRun hooks are not chained. If a child command overwrites this, the parent hook is not executed.

This caused the global permissions check to be overwritten in the sub-commands and caused misleading error messages when running commands without root permission.

There is a flag to introduce the chaining behavior but this unnecessarily complicates the commands. Since we have shallow command, using PreRun hooks is just fine.

Btw, we are not the only ones that got confused by this feature: spf13/cobra#252

@bschimke95 bschimke95 requested a review from a team as a code owner February 28, 2024 09:48
By default, PersistentPreRun hooks are not chained. If a child command
overwrites this, the parent hook is not executed.

This caused the global permissions check to be overwritten in the
sub-commands and caused misleading error messages when running commands
without root permission.
@bschimke95 bschimke95 force-pushed the bschimke95/fix-root-permission-check branch from 45899bc to 8e9195d Compare February 28, 2024 11:56
Copy link
Contributor

@kwmonroe kwmonroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice find @bschimke95!

@bschimke95 bschimke95 merged commit b7bd5ee into main Feb 28, 2024
15 checks passed
@bschimke95 bschimke95 deleted the bschimke95/fix-root-permission-check branch February 28, 2024 14:40
eaudetcobello pushed a commit that referenced this pull request Feb 28, 2024
By default, PersistentPreRun hooks are not chained. If a child command
overwrites this, the parent hook is not executed.

This caused the global permissions check to be overwritten in the
sub-commands and caused misleading error messages when running commands
without root permission.
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.

3 participants