Skip to content

Commit 909cec8

Browse files
committed
Adjust help information display. update chanagelog
1 parent ad06900 commit 909cec8

File tree

10 files changed

+161
-62
lines changed

10 files changed

+161
-62
lines changed

CHANGELOG.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
11
# CHANGELOG
22

3+
## v2.4.0
4+
5+
> publish at: 2018.07.03
6+
7+
8+
9+
## v2.3.3
10+
11+
> publish at: 2018.03.15
12+
13+
**update**
14+
15+
- prompt password input use sh instead bash
16+
- command help display modify
17+
- modify error display
18+
- Update README.md
19+
- add more param type declare
20+
21+
**new**
22+
23+
- add running sub-command support
24+
- add disable command support in controller
25+
- add a built in command for run php dev server
26+
27+
**bug fixed**
28+
29+
- token_get_all not exist for Highlighter
30+
- fix some errors for phar build
31+
332
## v2.3.2
433

534
> publish at: 2018.01.26

src/Application.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ protected function dispatch(string $name)
291291
$action = '';
292292

293293
// like 'home:index'
294-
if (strpos($realName, $sep) > 0) {
295-
$input = array_values(array_filter(explode($sep, $realName)));
296-
list($realName, $action) = \count($input) > 2 ? array_splice($input, 2) : $input;
294+
if (\strpos($realName, $sep) > 0) {
295+
$input = \array_values(\array_filter(\explode($sep, $realName)));
296+
list($realName, $action) = \count($input) > 2 ? \array_splice($input, 2) : $input;
297297
$realName = $this->getRealCommandName($realName);
298298
}
299299

@@ -305,17 +305,17 @@ protected function dispatch(string $name)
305305
if (true !== $this->fire(self::ON_NOT_FOUND, [$this])) {
306306
$this->output->liteError("The command '{$name}' is not exists in the console application!");
307307

308-
$commands = array_merge($this->getControllerNames(), $this->getCommandNames());
308+
$commands = \array_merge($this->getControllerNames(), $this->getCommandNames());
309309

310310
// find similar command names by similar_text()
311311
if ($similar = Helper::findSimilar($name, $commands)) {
312-
$this->write(sprintf("\nMaybe what you mean is:\n <info>%s</info>", implode(', ', $similar)));
312+
$this->write(\sprintf("\nMaybe what you mean is:\n <info>%s</info>", implode(', ', $similar)));
313313
} else {
314314
$this->showCommandList(false);
315315
}
316316
}
317317

318-
return 404;
318+
return 2;
319319
}
320320

321321
/**

src/Base/AbstractApplication.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ public function showHelpInfo($quit = true, string $command = null)
418418
$sep = $this->delimiter;
419419

420420
$this->output->helpPanel([
421-
'usage' => "$script <info>{command}</info> [arg0 arg1=value1 arg2=value2 ...] [--opt -v -h ...]",
421+
'usage' => "$script <info>{command}</info> [--opt -v -h ...] [arg0 arg1 arg2=value2 ...]",
422422
'example' => [
423423
"$script test (run a independent command)",
424424
"$script home{$sep}index (run a command of the group)",
@@ -471,27 +471,29 @@ public function showCommandList($quit = true)
471471
$desPlaceholder = 'No description of the command';
472472

473473
// all console controllers
474-
$controllerArr[] = PHP_EOL . '- <bold>Group Commands</bold>';
475-
$controllers = $this->controllers;
476-
ksort($controllers);
474+
if ($controllers = $this->controllers) {
475+
\ksort($controllers);
476+
$controllerArr[] = PHP_EOL . '- <bold>Group Commands</bold>';
477+
}
477478

478479
foreach ($controllers as $name => $controller) {
479480
$hasGroup = true;
480481
/** @var AbstractCommand $controller */
481482
$desc = $controller::getDescription() ?: $desPlaceholder;
482483
$aliases = $this->getCommandAliases($name);
483-
$extra = $aliases ? Helper::wrapTag(' [alias: ' . implode(',', $aliases) . ']', 'info') : '';
484+
$extra = $aliases ? Helper::wrapTag(' [alias: ' . \implode(',', $aliases) . ']', 'info') : '';
484485
$controllerArr[$name] = $desc . $extra;
485486
}
486487

487-
if (!$hasGroup) {
488+
if (!$hasGroup && $this->isDebug()) {
488489
$controllerArr[] = '... Not register any group command(controller)';
489490
}
490491

491492
// all independent commands, Independent, Single, Alone
492-
$commands = $this->commands;
493-
$commandArr[] = PHP_EOL . '- <bold>Alone Commands</bold>';
494-
ksort($commands);
493+
if ($commands = $this->commands) {
494+
$commandArr[] = PHP_EOL . '- <bold>Alone Commands</bold>';
495+
\ksort($commands);
496+
}
495497

496498
foreach ($commands as $name => $command) {
497499
$desc = $desPlaceholder;
@@ -513,13 +515,13 @@ public function showCommandList($quit = true)
513515
$commandArr[$name] = $desc . $extra;
514516
}
515517

516-
if (!$hasCommand) {
518+
if (!$hasCommand && $this->isDebug()) {
517519
$commandArr[] = '... Not register any alone command';
518520
}
519521

520522
// built in commands
521523
$internalCommands = static::$internalCommands;
522-
ksort($internalCommands);
524+
\ksort($internalCommands);
523525

524526
// built in options
525527
$internalOptions = FormatUtil::alignmentOptions(self::$internalOptions);

src/Base/AbstractCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ protected function showHelpByMethodAnnotations(string $method, string $action =
488488
}
489489

490490
if ($tag === 'usage') {
491-
$help['Usage:'] = $this->annotationVars['fullCommand'] . ' [arguments ...] [options ...]';
491+
$help['Usage:'] = $this->annotationVars['fullCommand'] . ' [--options ...] [arguments ...]';
492492
}
493493

494494
continue;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: inhere
5+
* Date: 2018/7/4
6+
* Time: 上午10:25
7+
*/
8+
9+
namespace Inhere\Console\BuiltIn;
10+
11+
/**
12+
* Class GenShellAutoComplete
13+
* @package Inhere\Console\BuiltIn
14+
*/
15+
class GenShellAutoComplete
16+
{
17+
18+
}

src/Controller.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ final public function showCommandList()
238238
$this->beforeShowCommandList();
239239

240240
$ref = new \ReflectionClass($this);
241-
$sName = lcfirst(self::getName() ?: $ref->getShortName());
241+
$sName = \lcfirst(self::getName() ?: $ref->getShortName());
242242

243243
if (!($classDes = self::getDescription())) {
244244
$classDes = Annotation::description($ref->getDocComment()) ?: 'No description for the console controller';
@@ -274,7 +274,7 @@ final public function showCommandList()
274274
}
275275

276276
// sort commands
277-
ksort($commands);
277+
\ksort($commands);
278278

279279
// move 'help' to last.
280280
if ($helpCmd = $commands['help'] ?? null) {
@@ -286,19 +286,19 @@ final public function showCommandList()
286286

287287
if ($this->executionAlone) {
288288
$name = $sName . ' ';
289-
$usage = "$script <info>{command}</info> [arguments ...] [options ...]";
289+
$usage = "$script <info>{command}</info> [--options ...] [arguments ...]";
290290
} else {
291291
$name = $sName . $this->delimiter;
292-
$usage = "$script {$name}<info>{command}</info> [arguments ...] [options ...]";
292+
$usage = "$script {$name}<info>{command}</info> [--options ...] [arguments ...]";
293293
}
294294

295295
$this->output->startBuffer();
296296
$this->output->write(ucfirst($classDes) . PHP_EOL);
297297
$this->output->mList([
298298
'Usage:' => $usage,
299299
//'Group Name:' => "<info>$sName</info>",
300-
'Options:' => FormatUtil::alignmentOptions(array_merge(Application::getInternalOptions(), static::$globalOptions)),
301-
'Commands:' => $commands,
300+
'Global Options:' => FormatUtil::alignmentOptions(array_merge(Application::getInternalOptions(), static::$globalOptions)),
301+
'Available Commands:' => $commands,
302302
], [
303303
'sepChar' => ' ',
304304
]);

src/IO/Input/ArrayInput.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ public function __construct(array $argv = null, $parsing = true)
2727
parent::__construct([], false);
2828

2929
$this->tokens = $argv;
30-
$this->script = array_shift($argv);
31-
$this->fullScript = implode(' ', $argv);
30+
$this->script = \array_shift($argv);
31+
$this->fullScript = \implode(' ', $argv);
3232

3333
if ($parsing && $argv) {
3434
list($this->args, $this->sOpts, $this->lOpts) = InputParser::fromArray($argv);
3535

3636
// collect command. it is first argument.
37-
$this->command = isset($this->args[0]) ? array_shift($this->args) : null;
37+
$this->command = isset($this->args[0]) ? \array_shift($this->args) : null;
3838
}
3939
}
4040

src/IO/InputDefinition.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,19 @@ class InputDefinition
2222
'default' => null,
2323
];
2424

25+
/** @var string|array */
2526
private $example;
27+
2628
/** @var string */
2729
private $description;
2830

29-
/**
30-
* @var array[]
31-
*/
31+
/** @var array[] */
3232
private $arguments;
3333
private $requiredCount = 0;
3434
private $hasOptional = false;
3535
private $hasAnArrayArgument = false;
3636

37-
/**
38-
* @var array[]
39-
*/
37+
/** @var array[] */
4038
private $options;
4139

4240
/** @var array */

0 commit comments

Comments
 (0)