From 4b59b004f143a974c03b236ea9ba9a4a85e6d5cf Mon Sep 17 00:00:00 2001 From: Joakim Date: Mon, 5 Jan 2026 10:27:12 +0100 Subject: [PATCH] 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 ' shows command-specific help - 'opal -h' still shows command-specific help - All existing flexible syntax continues to work --- opal-task/cmd/root.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/opal-task/cmd/root.go b/opal-task/cmd/root.go index 58a7c71..934439c 100644 --- a/opal-task/cmd/root.go +++ b/opal-task/cmd/root.go @@ -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:])