Skip to content

Commit 26e0928

Browse files
committed
update some for display help
1 parent fb3db61 commit 26e0928

File tree

5 files changed

+60
-11
lines changed

5 files changed

+60
-11
lines changed

src/AbstractApplication.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,16 @@ public function addAliases(string $name, $aliases): self
399399
return $this;
400400
}
401401

402+
/**
403+
* @param string $name
404+
*
405+
* @return array
406+
*/
407+
public function getAliases(string $name = ''): array
408+
{
409+
return $this->router->getAliases($name);
410+
}
411+
402412
/**
403413
* @param int $level
404414
* @param string $format

src/AbstractHandler.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,8 @@ public function validateInput(): bool
414414
$shortNames = $conf['shortcut'] ? explode('|', $conf['shortcut']) : [];
415415
if ($srt = $in->findOneShortOpts($shortNames)) {
416416
$opts[$name] = $in->sOpt($srt);
417-
} elseif ($conf['default']) {
418-
417+
} elseif ($conf['default'] !== null) {
418+
$opts[$name] = $conf['default'];
419419
} elseif ($conf['required']) {
420420
$missingOpts[] = "--{$name}" . ($srt ? "|-{$srt}" : '');
421421
}
@@ -606,8 +606,10 @@ protected function showHelpByMethodAnnotations(string $method, string $action =
606606
$ref = new ReflectionClass($this);
607607
$name = $this->input->getCommand();
608608

609-
$this->logf(Console::VERB_CRAZY, 'display help info for the method=%s, action=%s, class=%s', $method, $action,
610-
static::class);
609+
$this->log(Console::VERB_CRAZY, "display help info for the method=$method", [
610+
'class' => static::class,
611+
'action' => $action,
612+
]);
611613

612614
if (!$ref->hasMethod($method)) {
613615
$this->write("The command [<info>$name</info>] don't exist in the group: " . static::getName());
@@ -663,7 +665,7 @@ protected function showHelpByMethodAnnotations(string $method, string $action =
663665

664666
if (isset($help['Description:'])) {
665667
$description = $help['Description:'] ?: 'No description message for the command';
666-
$this->write(ucfirst($description) . PHP_EOL);
668+
$this->write(ucfirst($this->parseCommentsVars($description)) . PHP_EOL);
667669
unset($help['Description:']);
668670
}
669671

@@ -805,6 +807,20 @@ public function logf(int $level, string $format, ...$args): void
805807
Console::logf($level, $format, ...$args);
806808
}
807809

810+
/**
811+
* @param int $level
812+
* @param string $message
813+
* @param array $extra
814+
*/
815+
public function log(int $level, string $message, array $extra = []): void
816+
{
817+
if ($this->getVerbLevel() < $level) {
818+
return;
819+
}
820+
821+
Console::log($message, $extra, $level);
822+
}
823+
808824
/**
809825
* @return InputDefinition|null
810826
*/

src/BuiltIn/SelfUpdateCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
*/
2626
class SelfUpdateCommand extends Command
2727
{
28-
public const VERSION_URL = 'https://padraic.github.io/humbug/downloads/humbug.version';
28+
public const VERSION_URL = 'https://inhere.github.io/humbug/downloads/humbug.version';
2929

30-
public const PHAR_URL = 'https://padraic.github.io/humbug/downloads/humbug.phar';
30+
public const PHAR_URL = 'https://inhere.github.io/humbug/downloads/humbug.phar';
3131

32-
public const PACKAGE_NAME = 'humbug/humbug';
32+
public const PACKAGE_NAME = 'inhere/console';
3333

34-
public const FILE_NAME = 'humbug.phar';
34+
public const FILE_NAME = 'console.phar';
3535

3636
protected static $name = 'self-update';
3737

src/Controller.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,16 @@ final public function helpCommand(): int
315315
$method = $this->actionSuffix ? $action . ucfirst($this->actionSuffix) : $action;
316316
$aliases = $this->getCommandAliases($action);
317317

318+
// up: find global aliases from app
319+
if ($this->app) {
320+
$commandId = $this->input->getCommandId();
321+
$gAliases = $this->app->getAliases($commandId);
322+
323+
if ($gAliases) {
324+
$aliases = array_merge($aliases, $gAliases);
325+
}
326+
}
327+
318328
// For a specified sub-command.
319329
return $this->showHelpByMethodAnnotations($method, $action, $aliases);
320330
}

src/Traits/NameAliasTrait.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function setAlias(string $name, $alias, bool $validate = false): void
4242
}
4343

4444
/**
45-
* get real name by alias
45+
* Get real name by alias
4646
*
4747
* @param string $alias
4848
*
@@ -64,10 +64,23 @@ public function hasAlias(string $alias): bool
6464
}
6565

6666
/**
67+
* @param string $name
68+
*
6769
* @return array
6870
*/
69-
public function getAliases(): array
71+
public function getAliases(string $name = ''): array
7072
{
73+
if ($name) {
74+
$aliases = [];
75+
foreach ($this->aliases as $alias => $n) {
76+
if ($name === $n) {
77+
$aliases[] = $alias;
78+
}
79+
}
80+
81+
return $aliases;
82+
}
83+
7184
return $this->aliases;
7285
}
7386
}

0 commit comments

Comments
 (0)