|
16 | 16 | */ |
17 | 17 | class Application extends AbstractApplication |
18 | 18 | { |
19 | | - /** |
20 | | - * @var string|null |
21 | | - */ |
22 | | - protected $commandsNamespace; |
23 | | - |
24 | | - /** |
25 | | - * @var string|null |
26 | | - */ |
27 | | - protected $controllersNamespace; |
28 | | - |
29 | 19 | /********************************************************** |
30 | 20 | * register console controller/command |
31 | 21 | **********************************************************/ |
@@ -193,9 +183,27 @@ protected function dispatch($name) |
193 | 183 | return $this->runAction($name, $action, true); |
194 | 184 | } |
195 | 185 |
|
| 186 | + // command not found |
196 | 187 | if (true !== self::fire(self::ON_NOT_FOUND, [$this])) { |
197 | | - $this->output->error("Console controller or command [$name] not exists!"); |
198 | | - $this->showCommandList(false); |
| 188 | + $this->output->liteError("The console command '{$name}' not exists!"); |
| 189 | + |
| 190 | + // find similar command names by similar_text() |
| 191 | + $similar = []; |
| 192 | + $commands = array_merge($this->getControllerNames(), $this->getCommandNames()); |
| 193 | + |
| 194 | + foreach ($commands as $command) { |
| 195 | + similar_text($name, $command, $percent); |
| 196 | + |
| 197 | + if (45 <= (int)$percent) { |
| 198 | + $similar[] = $command; |
| 199 | + } |
| 200 | + } |
| 201 | + |
| 202 | + if ($similar) { |
| 203 | + $this->write(sprintf('Maybe what you mean is: <info>%s</info>', implode(', ', $similar))); |
| 204 | + } else { |
| 205 | + $this->showCommandList(false); |
| 206 | + } |
199 | 207 | } |
200 | 208 |
|
201 | 209 | return 404; |
@@ -274,37 +282,4 @@ public function runAction($name, $action, $believable = false, $standAlone = fal |
274 | 282 |
|
275 | 283 | return $object->run($action); |
276 | 284 | } |
277 | | - |
278 | | - /** |
279 | | - * @return null|string |
280 | | - */ |
281 | | - public function getCommandsNamespace() |
282 | | - { |
283 | | - return $this->commandsNamespace; |
284 | | - } |
285 | | - |
286 | | - /** |
287 | | - * @param null|string $commandsNamespace |
288 | | - */ |
289 | | - public function setCommandsNamespace($commandsNamespace) |
290 | | - { |
291 | | - $this->commandsNamespace = $commandsNamespace; |
292 | | - } |
293 | | - |
294 | | - /** |
295 | | - * @return null|string |
296 | | - */ |
297 | | - public function getControllersNamespace() |
298 | | - { |
299 | | - return $this->controllersNamespace; |
300 | | - } |
301 | | - |
302 | | - /** |
303 | | - * @param null|string $controllersNamespace |
304 | | - */ |
305 | | - public function setControllersNamespace($controllersNamespace) |
306 | | - { |
307 | | - $this->controllersNamespace = $controllersNamespace; |
308 | | - } |
309 | | - |
310 | 285 | } |
0 commit comments