Skip to content

Group command with generateHelp emits spurious 'unknown option' for --help #558

Description

@stalep

When --help is used on a group command (a @CommandDefinition with groupCommands), aesh prints The option --help is unknown. before rendering the help output:

$ hardwood inspect --help
The option --help is unknown.
Low-level introspection commands.
Usage: hardwood inspect [-h] [COMMAND]
...

The help renders correctly (exit code 0), but the spurious error message is confusing. This only happens on nested group commands — the root command hardwood --help and leaf commands like hardwood print --help work cleanly without the error.

Expected behavior

hardwood inspect --help should render the help output without any error prefix — identical to how hardwood --help and hardwood print --help behave.

Root cause

When generateHelp = true, aesh adds a -h/--help option to the command. For leaf commands and the root command, this works correctly. But for a nested group command, the parser appears to reject --help as an unknown option before the help system processes it. The help still renders (possibly via a fallback path), but the error message leaks through to stderr.

Reproduction

@CommandDefinition(name = "root", description = "Root", generateHelp = true, groupCommands = {
    GroupCmd.class
})
public class RootCommand implements Command<CommandInvocation> { ... }

@CommandDefinition(name = "group", description = "Group", generateHelp = true, groupCommands = {
    LeafCmd.class
})
public class GroupCmd implements Command<CommandInvocation> { ... }

@CommandDefinition(name = "leaf", description = "Leaf", generateHelp = true)
public class LeafCmd implements Command<CommandInvocation> { ... }
$ app group --help      # prints "unknown option" + help (BUG)
$ app --help            # prints help only (OK)
$ app group leaf --help # prints help only (OK)

Context

Found in hardwood-hq/hardwood issue #806 after the picocli-to-aesh migration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions