Fix help flags to show root help instead of list help
Previously, 'opal -h', 'opal --help', and 'opal help' would show the list command help instead of the root command help. This was because the argument preprocessing logic would rewrite these as 'opal list -h' before Cobra could handle them. Now we detect help flags/command before preprocessing and let Cobra handle them naturally. This ensures: - 'opal -h' and 'opal --help' show root help - 'opal help' shows root help - 'opal help <command>' shows command-specific help - 'opal <command> -h' still shows command-specific help - All existing flexible syntax continues to work
This commit is contained in:
@@ -48,6 +48,16 @@ It supports filtering, tags, priorities, projects, and recurring tasks.`,
|
||||
}
|
||||
|
||||
func Execute() error {
|
||||
// Check for help flags/command BEFORE preprocessing
|
||||
// This allows Cobra to handle help naturally for the root command
|
||||
if len(os.Args) > 1 {
|
||||
firstArg := os.Args[1]
|
||||
if firstArg == "-h" || firstArg == "--help" || firstArg == "help" {
|
||||
// Let Cobra handle help - skip preprocessing
|
||||
return rootCmd.Execute()
|
||||
}
|
||||
}
|
||||
|
||||
// Preprocess arguments BEFORE Cobra routing
|
||||
if len(os.Args) > 1 {
|
||||
parsed := preprocessArgs(os.Args[1:])
|
||||
|
||||
Reference in New Issue
Block a user