@@ -529,6 +529,10 @@ public function getNamespaces()
529
529
{
530
530
$ namespaces = [];
531
531
foreach ($ this ->all () as $ command ) {
532
+ if ($ command ->isHidden ()) {
533
+ continue ;
534
+ }
535
+
532
536
$ namespaces = array_merge ($ namespaces , $ this ->extractAllNamespaces ($ command ->getName ()));
533
537
534
538
foreach ($ command ->getAliases () as $ alias ) {
@@ -612,6 +616,12 @@ public function find($name)
612
616
$ commands = preg_grep ('{^ ' .$ expr .'}i ' , $ allCommands );
613
617
}
614
618
619
+ // hidden commands can only be matched exactly and shall not appear otherwise
620
+ $ hiddenCommands = $ this ->removeHiddenCommands ($ commands );
621
+ if (isset ($ hiddenCommands [$ name ])) {
622
+ return $ hiddenCommands [$ name ];
623
+ }
624
+
615
625
// if no commands matched or we just matched namespaces
616
626
if (empty ($ commands ) || \count (preg_grep ('{^ ' .$ expr .'$}i ' , $ commands )) < 1 ) {
617
627
if (false !== $ pos = strrpos ($ name , ': ' )) {
@@ -622,6 +632,8 @@ public function find($name)
622
632
$ message = sprintf ('Command "%s" is not defined. ' , $ name );
623
633
624
634
if ($ alternatives = $ this ->findAlternatives ($ name , $ allCommands )) {
635
+ $ this ->removeHiddenCommands ($ alternatives );
636
+
625
637
if (1 == \count ($ alternatives )) {
626
638
$ message .= "\n\nDid you mean this? \n " ;
627
639
} else {
@@ -1155,6 +1167,38 @@ private function findAlternatives($name, $collection)
1155
1167
return array_keys ($ alternatives );
1156
1168
}
1157
1169
1170
+ /**
1171
+ * Removes hidden commands commands from a given array of command names and
1172
+ * returns them as Command instances.
1173
+ *
1174
+ * @param string[] $commandNames The command names to filter
1175
+ *
1176
+ * @return Command[] An associative array of removed commands with
1177
+ * command names and command aliases being the keys
1178
+ *
1179
+ * @internal
1180
+ */
1181
+ private function removeHiddenCommands (array &$ commandNames )
1182
+ {
1183
+ $ hiddenCommands = [];
1184
+ foreach ($ commandNames as $ key => $ commandName ) {
1185
+ $ command = $ this ->has ($ commandName ) ? $ this ->commands [$ commandName ] : $ this ->commandLoader ->get ($ commandName );
1186
+
1187
+ if (!$ command ->isHidden ()) {
1188
+ continue ;
1189
+ }
1190
+
1191
+ $ hiddenCommands [$ commandName ] = $ command ;
1192
+ foreach ($ command ->getAliases () as $ alias ) {
1193
+ $ hiddenCommands [$ alias ] = $ command ;
1194
+ }
1195
+
1196
+ unset($ commandNames [$ key ]);
1197
+ }
1198
+
1199
+ return $ hiddenCommands ;
1200
+ }
1201
+
1158
1202
/**
1159
1203
* Sets the default Command name.
1160
1204
*
0 commit comments