Skip to content

--help resolves the wrong command and bypasses a registered help command #36

Description

@HafizMMoaz

Console::run() handles -h/--help by instantiating the built in Help command directly and letting it read argument 0 as the command name (src/Console.php:289-292, src/Commands/Help.php:28-35). Three problems follow.

1. --help fails on any command that takes arguments. Argument 0 is used as the command name even when it is a value:

php app deploy prod --help
# Command not found: "prod"   (exit 1)

2. A registered custom help command is ignored. new Help($this) skips the command registry, so $console->addCommand(new MyHelp($console)) is honoured by php app help deploy but not by php app deploy --help.

3. -h is globally reserved. A command that documents -h for its own use can never receive it:

protected array $options = ['-h, --host' => 'The host to bind.'];
// php app serve -h 0.0.0.0  ->  Command not found: "0.0.0.0"

Verified on PHP 8.4.19 against main (2c0159f).

Suggested fix: resolve help through getCommand('help') so overrides work, and only treat argument 0 as a target when it actually names a registered command, otherwise fall back to the current command name. Point 3 needs a decision: either let a command opt out of the global -h, or reserve only the long --help.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions