Repository navigation
Conversation
The application only accepted exact command names, although it mirrors Symfony's Application, which accepts unique abbreviations (c:c for cache:clear) and lists similar names for an unknown command. Add Application::findCommand(), ported from Symfony's find(), and use it to resolve the command given on the command line. getCommand() and hasCommand() keep their exact lookup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Approved |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
Applicationonly looked up exact command names:nefor the single commandnegfailed withThe command "ne" does not exist., and nothing suggested the right name, althoughfindNamespace()already accepts abbreviated namespaces and the class otherwise mirrors Symfony'sApplication, which does both.This adds
Application::findCommand(string $name): AbstractCommand, a port of Symfony'sApplication::find():c:c→cache:clear,li→list), with a case-insensitive fallback; aliases of a command that already matches are not counted twice;CommandNotFoundException"The command "x" is ambiguous." listing the matches with their descriptions, an unknown name keeps the existing messageThe command "x" does not exist.and appends "Did you mean this?" alternatives (Levenshtein, as in Symfony); both pass the names toCommandNotFoundException::getAlternatives();NamespaceNotFoundExceptionfromfindNamespace();doExecute()now resolves the command from the input withfindCommand().getCommand()andhasCommand()keep their exact lookup, so code calling them is unaffected. The--helphandling still goes throughgetCommand()once the name is resolved, soli --helpshows the help oflist.Related to #32 (which removes the extra error block a few lines further down in
doExecute(); the two merge cleanly) and #33 (adds afinallyto the sametryblock).Testing Instructions
New tests in
tests/ApplicationTest.php(testFindCommand*,testFindAmbiguousCommand,testFindUnknownCommand*,testTheApplicationIsExecutedWithAnAbbreviatedCommand) cover exact names, abbreviations per namespace part, the case-insensitive fallback, alias de-duplication, the command loader, ambiguity, alternatives, unknown namespaces and hidden commands. On4.x-devthey fail (the method does not exist, and runninglireports an unknown command).Manually: register
cache:clearand runbin/console c:c, or runbin/console lisstand see "Did you mean this? list".Documentation Changes Required
docs/overview.md: new "Finding commands" section under "Console Application".🤖 Generated with Claude Code