You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PR #660 fixed parent commands silently exiting 0 on unknown subcommands by adding RunE with a manual len(args) > 0 check. The fix works correctly, but can be cleaned up.
Suggested improvements
1. Use cobra.NoArgs instead of manual args check
The current RunE reimplements what cobra.NoArgs already provides (same error format). Each parent command can be simplified to:
Cobra validates Args before calling RunE, so the manual check is unnecessary.
2. Improve test isolation in cloneRootCmd
cloneRootCmd calls AddCommand on global command variables, which reassigns their .parent pointer to the clone without removing them from rootCmd.commands. This works today but is fragile. Options:
Use rootCmd directly (it already has SilenceUsage/SilenceErrors)
Add a t.Cleanup that re-parents commands back to rootCmd
Activity
amh1k commentedon Aug 3, 2026
Would like to take this up