File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -562,6 +562,16 @@ public function find($name)
562562 throw new \InvalidArgumentException ($ message );
563563 }
564564
565+ // filter out aliases for commands which are already on the list
566+ if (count ($ commands ) > 1 ) {
567+ $ commandList = $ this ->commands ;
568+ $ commands = array_filter ($ commands , function ($ nameOrAlias ) use ($ commandList , $ commands ) {
569+ $ commandName = $ commandList [$ nameOrAlias ]->getName ();
570+
571+ return $ commandName === $ nameOrAlias || !in_array ($ commandName , $ commands );
572+ });
573+ }
574+
565575 $ exact = in_array ($ name , $ commands , true );
566576 if (count ($ commands ) > 1 && !$ exact ) {
567577 $ suggestions = $ this ->getAbbreviationSuggestions (array_values ($ commands ));
Original file line number Diff line number Diff line change @@ -393,6 +393,19 @@ public function testFindAlternativeCommands()
393393 }
394394 }
395395
396+ public function testFindAlternativeCommandsWithAnAlias ()
397+ {
398+ $ fooCommand = new \FooCommand ();
399+ $ fooCommand ->setAliases (array ('foo2 ' ));
400+
401+ $ application = new Application ();
402+ $ application ->add ($ fooCommand );
403+
404+ $ result = $ application ->find ('foo ' );
405+
406+ $ this ->assertSame ($ fooCommand , $ result );
407+ }
408+
396409 public function testFindAlternativeNamespace ()
397410 {
398411 $ application = new Application ();
You can’t perform that action at this time.
0 commit comments