diff --git a/dispatcher.go b/dispatcher.go index 4756132..4857567 100644 --- a/dispatcher.go +++ b/dispatcher.go @@ -212,13 +212,21 @@ func (d *Dispatcher) Execute(args []string) error { } // Check for help flags anywhere in the arguments, but stop at -- + // When "help" is registered as a command, don't treat bare "help" as a + // help keyword when it appears as the first argument — let the registered + // command handle it instead. hasHelp := false - for _, arg := range args { + helpIsCommand := d.HasCommand("help") + for i, arg := range args { if arg == "--" { // Stop processing flags after -- break } - if arg == "-h" || arg == "--help" || arg == "help" { + if arg == "-h" || arg == "--help" { + hasHelp = true + break + } + if arg == "help" && !(i == 0 && helpIsCommand) { hasHelp = true break } @@ -767,6 +775,16 @@ func (d *Dispatcher) showNamespaceHelp(namespacePath string) error { return nil } +// ShowCommandHelp displays help for the command at the given path. +// Returns an error if the command is not found. +func (d *Dispatcher) ShowCommandHelp(path string) error { + entry := d.GetCommandEntry(path) + if entry == nil { + return fmt.Errorf("unknown command: %s", path) + } + return d.showCommandHelp(entry) +} + // GetCommand returns the command for a given path, or nil if not found func (d *Dispatcher) GetCommand(path string) Command { normalizedPath := normalizeCommandPath(path)