Skip to content

Commit 58a09ab

Browse files
committed
add command tips for app
1 parent cdc9481 commit 58a09ab

File tree

3 files changed

+30
-49
lines changed

3 files changed

+30
-49
lines changed

src/Application.php

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,6 @@
1616
*/
1717
class Application extends AbstractApplication
1818
{
19-
/**
20-
* @var string|null
21-
*/
22-
protected $commandsNamespace;
23-
24-
/**
25-
* @var string|null
26-
*/
27-
protected $controllersNamespace;
28-
2919
/**********************************************************
3020
* register console controller/command
3121
**********************************************************/
@@ -193,9 +183,27 @@ protected function dispatch($name)
193183
return $this->runAction($name, $action, true);
194184
}
195185

186+
// command not found
196187
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+
}
199207
}
200208

201209
return 404;
@@ -274,37 +282,4 @@ public function runAction($name, $action, $believable = false, $standAlone = fal
274282

275283
return $object->run($action);
276284
}
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-
310285
}

src/BuiltIn/PharController.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,20 @@ class PharController extends Controller
2222

2323
/**
2424
* pack directory(s) to a phar file.
25+
* @usage
26+
* {command} phar=[FILE] src-dir=[DIR] [-c --format ...]
27+
*
2528
* @arguments
26-
* src-dir The source directory for pack<red>*</red>
27-
* phar The output phar file path
29+
* phar The output phar file path.<red>*</red>
30+
* src-dirs The source directory for pack, multi use ',' split.<red>*</red>
2831
*
2932
* @options
30-
* -c,--compress Want compress php file.
31-
* --file-include Append file include
33+
* -c, --compress Compress the phar file to 'gz','bz','zip'.
34+
* --format Format php source file content(will remove all annotations).
35+
* --file-include Append file include
3236
*
37+
* @example
38+
* {command} phar=my.phar src-dir=./ -c --format
3339
*/
3440
public function packCommand()
3541
{

0 commit comments

Comments
 (0)