Skip to content

Commit 29cbf67

Browse files
committed
update some info. format code
1 parent e415366 commit 29cbf67

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+583
-560
lines changed

src/AbstractApplication.php

Lines changed: 2 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@
1111
use Inhere\Console\Component\ErrorHandler;
1212
use Inhere\Console\Component\Style\Style;
1313
use Inhere\Console\Face\ApplicationInterface;
14-
use Inhere\Console\Face\CommandInterface;
1514
use Inhere\Console\Face\ErrorHandlerInterface;
1615
use Inhere\Console\IO\Input;
1716
use Inhere\Console\IO\InputInterface;
1817
use Inhere\Console\IO\Output;
1918
use Inhere\Console\IO\OutputInterface;
19+
use Inhere\Console\Traits\ApplicationHelpTrait;
2020
use Inhere\Console\Traits\InputOutputAwareTrait;
2121
use Inhere\Console\Traits\SimpleEventTrait;
22-
use Inhere\Console\Util\FormatUtil;
23-
use Inhere\Console\Util\Helper;
2422
use Toolkit\PhpUtil\PhpHelper;
2523

2624
/**
@@ -29,7 +27,7 @@
2927
*/
3028
abstract class AbstractApplication implements ApplicationInterface
3129
{
32-
use InputOutputAwareTrait, SimpleEventTrait;
30+
use ApplicationHelpTrait, InputOutputAwareTrait, SimpleEventTrait;
3331

3432
/** @var array */
3533
protected static $internalCommands = [
@@ -359,157 +357,6 @@ protected function validateName(string $name, bool $isGroup = false)
359357
}
360358
}
361359

362-
/***************************************************************************
363-
* some information for the application
364-
***************************************************************************/
365-
366-
/**
367-
* show the application help information
368-
* @param bool $quit
369-
* @param string $command
370-
*/
371-
public function showHelpInfo(bool $quit = true, string $command = '')
372-
{
373-
// display help for a special command
374-
if ($command) {
375-
$this->input->setCommand($command);
376-
$this->input->setSOpt('h', true);
377-
$this->input->clearArgs();
378-
$this->dispatch($command);
379-
$this->stop();
380-
}
381-
382-
$script = $this->input->getScript();
383-
$sep = $this->delimiter;
384-
385-
$this->output->helpPanel([
386-
'usage' => "$script <info>{command}</info> [--opt -v -h ...] [arg0 arg1 arg2=value2 ...]",
387-
'example' => [
388-
"$script test (run a independent command)",
389-
"$script home{$sep}index (run a command of the group)",
390-
"$script help {command} (see a command help information)",
391-
"$script home{$sep}index -h (see a command help of the group)",
392-
]
393-
], $quit);
394-
}
395-
396-
/**
397-
* show the application version information
398-
* @param bool $quit
399-
*/
400-
public function showVersionInfo($quit = true)
401-
{
402-
$os = \PHP_OS;
403-
$date = \date('Y.m.d');
404-
$logo = '';
405-
$name = $this->getConfig('name', 'Console Application');
406-
$version = $this->getConfig('version', 'Unknown');
407-
$publishAt = $this->getConfig('publishAt', 'Unknown');
408-
$updateAt = $this->getConfig('updateAt', 'Unknown');
409-
$phpVersion = \PHP_VERSION;
410-
411-
if ($logoTxt = $this->getLogoText()) {
412-
$logo = Helper::wrapTag($logoTxt, $this->getLogoStyle());
413-
}
414-
415-
$this->output->aList([
416-
"$logo\n <info>{$name}</info>, Version <comment>$version</comment>\n",
417-
'System Info' => "PHP version <info>$phpVersion</info>, on <info>$os</info> system",
418-
'Application Info' => "Update at <info>$updateAt</info>, publish at <info>$publishAt</info>(current $date)",
419-
], null, [
420-
'leftChar' => '',
421-
'sepChar' => ' : '
422-
]);
423-
424-
$quit && $this->stop();
425-
}
426-
427-
/**
428-
* show the application command list information
429-
* @param bool $quit
430-
*/
431-
public function showCommandList($quit = true)
432-
{
433-
$script = $this->getScriptName();
434-
$hasGroup = $hasCommand = false;
435-
$controllerArr = $commandArr = [];
436-
$desPlaceholder = 'No description of the command';
437-
438-
// all console controllers
439-
if ($controllers = $this->controllers) {
440-
$hasGroup = true;
441-
\ksort($controllers);
442-
}
443-
444-
// all independent commands, Independent, Single, Alone
445-
if ($commands = $this->commands) {
446-
$hasCommand = true;
447-
\ksort($commands);
448-
}
449-
450-
// add split title on both exists.
451-
if ($hasCommand && $hasGroup) {
452-
$commandArr[] = \PHP_EOL . '- <bold>Alone Commands</bold>';
453-
$controllerArr[] = \PHP_EOL . '- <bold>Group Commands</bold>';
454-
}
455-
456-
foreach ($controllers as $name => $controller) {
457-
/** @var AbstractCommand $controller */
458-
$desc = $controller::getDescription() ?: $desPlaceholder;
459-
$aliases = $this->getCommandAliases($name);
460-
$extra = $aliases ? Helper::wrapTag(' [alias: ' . \implode(',', $aliases) . ']', 'info') : '';
461-
$controllerArr[$name] = $desc . $extra;
462-
}
463-
464-
if (!$hasGroup && $this->isDebug()) {
465-
$controllerArr[] = '... Not register any group command(controller)';
466-
}
467-
468-
foreach ($commands as $name => $command) {
469-
$desc = $desPlaceholder;
470-
471-
/** @var AbstractCommand $command */
472-
if (\is_subclass_of($command, CommandInterface::class)) {
473-
$desc = $command::getDescription() ?: $desPlaceholder;
474-
} elseif ($msg = $this->getCommandMetaValue($name, 'description')) {
475-
$desc = $msg;
476-
} elseif (\is_string($command)) {
477-
$desc = 'A handler : ' . $command;
478-
} elseif (\is_object($command)) {
479-
$desc = 'A handler by ' . \get_class($command);
480-
}
481-
482-
$aliases = $this->getCommandAliases($name);
483-
$extra = $aliases ? Helper::wrapTag(' [alias: ' . \implode(',', $aliases) . ']', 'info') : '';
484-
$commandArr[$name] = $desc . $extra;
485-
}
486-
487-
if (!$hasCommand && $this->isDebug()) {
488-
$commandArr[] = '... Not register any alone command';
489-
}
490-
491-
// built in commands
492-
$internalCommands = static::$internalCommands;
493-
\ksort($internalCommands);
494-
495-
// built in options
496-
$internalOptions = FormatUtil::alignOptions(self::$internalOptions);
497-
498-
$this->output->mList([
499-
'Usage:' => "$script <info>{command}</info> [--opt -v -h ...] [arg0 arg1 arg2=value2 ...]",
500-
'Options:' => $internalOptions,
501-
'Internal Commands:' => $internalCommands,
502-
'Available Commands:' => \array_merge($controllerArr, $commandArr),
503-
], [
504-
'sepChar' => ' ',
505-
]);
506-
507-
unset($controllerArr, $commandArr, $internalCommands);
508-
$this->output->write("More command information, please use: <cyan>$script {command} -h</cyan>");
509-
510-
$quit && $this->stop();
511-
}
512-
513360
/**
514361
* @param string $name
515362
* @param string|array $aliases

src/AbstractCommand.php

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ abstract class AbstractCommand implements BaseCommandInterface
5353
protected static $annotationTags = [
5454
// tag name => multi line align
5555
'description' => false,
56-
'usage' => false,
57-
'arguments' => true,
58-
'options' => true,
59-
'example' => true,
60-
'help' => true,
56+
'usage' => false,
57+
'arguments' => true,
58+
'options' => true,
59+
'example' => true,
60+
'help' => true,
6161
];
6262

6363
/** @var Application */
@@ -96,8 +96,8 @@ public static function aliases(): array
9696

9797
/**
9898
* Command constructor.
99-
* @param Input $input
100-
* @param Output $output
99+
* @param Input $input
100+
* @param Output $output
101101
* @param InputDefinition|null $definition
102102
*/
103103
public function __construct(Input $input, Output $output, InputDefinition $definition = null)
@@ -160,12 +160,12 @@ protected function annotationVars(): array
160160
{
161161
// e.g: `more info see {name}:index`
162162
return [
163-
'name' => self::getName(),
164-
'group' => self::getName(),
165-
'workDir' => $this->input->getPwd(),
166-
'script' => $this->input->getScript(), // bin/app
167-
'binName' => $this->input->getScript(), // bin/app
168-
'command' => $this->input->getCommand(), // demo OR home:test
163+
'name' => self::getName(),
164+
'group' => self::getName(),
165+
'workDir' => $this->input->getPwd(),
166+
'script' => $this->input->getScript(), // bin/app
167+
'binName' => $this->input->getScript(), // bin/app
168+
'command' => $this->input->getCommand(), // demo OR home:test
169169
'fullCommand' => $this->input->getFullCommand(),
170170
];
171171
}
@@ -254,7 +254,7 @@ protected function beforeExecute(): bool
254254

255255
/**
256256
* do execute command
257-
* @param Input $input
257+
* @param Input $input
258258
* @param Output $output
259259
* @return int|mixed
260260
*/
@@ -366,7 +366,7 @@ public function validateInput(): bool
366366
if (\count($missingOpts) > 0) {
367367
$out->liteError(
368368
\sprintf('Not enough options parameters (missing: "%s").',
369-
\implode(', ', $missingOpts))
369+
\implode(', ', $missingOpts))
370370
);
371371

372372
return false;
@@ -405,7 +405,7 @@ protected function addAnnotationVars(array $map)
405405
}
406406

407407
/**
408-
* @param string $name
408+
* @param string $name
409409
* @param string|array $value
410410
*/
411411
protected function setAnnotationVar(string $name, $value)
@@ -482,9 +482,9 @@ protected function showHelp(): bool
482482

483483
/**
484484
* show help by parse method annotations
485-
* @param string $method
485+
* @param string $method
486486
* @param null|string $action
487-
* @param array $aliases
487+
* @param array $aliases
488488
* @return int
489489
* @throws \ReflectionException
490490
*/
@@ -549,10 +549,12 @@ protected function showHelpByMethodAnnotations(string $method, string $action =
549549
unset($help['Description:']);
550550
}
551551

552-
$help['Global Options:'] = FormatUtil::alignOptions(\array_merge(Application::getInternalOptions(), $this->commonOptions));
553-
552+
$help['Global Options:'] = FormatUtil::alignOptions(
553+
\array_merge(Application::getInternalOptions(),
554+
$this->commonOptions)
555+
);
554556
$this->output->mList($help, [
555-
'sepChar' => ' ',
557+
'sepChar' => ' ',
556558
'lastNewline' => 0,
557559
]);
558560

@@ -631,7 +633,7 @@ public static function addAnnotationTag(string $name)
631633

632634
/**
633635
* @param array $annotationTags
634-
* @param bool $replace
636+
* @param bool $replace
635637
*/
636638
public static function setAnnotationTags(array $annotationTags, $replace = false)
637639
{

src/Application.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function controller(string $name, $class = null, $option = null)
2828
/** @var Controller $class */
2929
if (!$class && \class_exists($name)) {
3030
$class = $name;
31-
$name = $class::getName();
31+
$name = $class::getName();
3232
}
3333

3434
if (!$name || !$class) {
@@ -102,7 +102,7 @@ public function command(string $name, $handler = null, $option = null)
102102
/** @var Command $name */
103103
if (!$handler && \class_exists($name)) {
104104
$handler = $name;
105-
$name = $name::getName();
105+
$name = $name::getName();
106106
}
107107

108108
if (!$name || !$handler) {
@@ -201,7 +201,7 @@ public function addGroup(string $name, $controller = null, $option = null)
201201
*/
202202
public function registerCommands(string $namespace, string $basePath): self
203203
{
204-
$length = \strlen($basePath) + 1;
204+
$length = \strlen($basePath) + 1;
205205
$iterator = Helper::directoryIterator($basePath, $this->getFileFilter());
206206

207207
foreach ($iterator as $file) {
@@ -221,7 +221,7 @@ public function registerCommands(string $namespace, string $basePath): self
221221
*/
222222
public function registerGroups(string $namespace, string $basePath): self
223223
{
224-
$length = \strlen($basePath) + 1;
224+
$length = \strlen($basePath) + 1;
225225
$iterator = Helper::directoryIterator($basePath, $this->getFileFilter());
226226

227227
foreach ($iterator as $file) {

src/BuiltIn/DevServerCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static function aliases(): array
4141
* file=STRING The entry file for server. e.g web/index.php
4242
* @example
4343
* {command} -S 127.0.0.1:8552 web/index.php
44-
* @param \Inhere\Console\IO\Input $in
44+
* @param \Inhere\Console\IO\Input $in
4545
* @param \Inhere\Console\IO\Output $out
4646
* @return int|mixed|void
4747
*/

src/BuiltIn/GenShellAutoComplete.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static function aliases(): array
2828

2929
/**
3030
* do execute
31-
* @param Input $input
31+
* @param Input $input
3232
* @param Output $output
3333
* @return int|mixed
3434
*/

src/BuiltIn/PharController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected function init()
4444
* -o, --output STRING Setting the output file name(<cyan>{defaultPkgName}.phar</cyan>)
4545
* --fast BOOL Fast build. only add modified files by <cyan>git status -s</cyan>
4646
* --refresh BOOL Whether build vendor folder files on phar file exists(<cyan>False</cyan>)
47-
* @param \Inhere\Console\IO\Input $in
47+
* @param \Inhere\Console\IO\Input $in
4848
* @param \Inhere\Console\IO\Output $out
4949
* @return int
5050
* @throws \UnexpectedValueException
@@ -155,7 +155,7 @@ public function setCompilerConfiger(\Closure $compilerConfiger)
155155
* -y, --yes BOOL Whether display goon tips message.
156156
* --overwrite BOOL Whether overwrite exists files on extract phar
157157
* @example {fullCommand} -f myapp.phar -d var/www/app
158-
* @param \Inhere\Console\IO\Input $in
158+
* @param \Inhere\Console\IO\Input $in
159159
* @param \Inhere\Console\IO\Output $out
160160
* @return int
161161
*/

src/BuiltIn/SelfUpdateCommand.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
namespace Inhere\Console\BuiltIn;
1010

11+
use Humbug\SelfUpdate\Strategy\GithubStrategy;
12+
use Humbug\SelfUpdate\Strategy\ShaStrategy;
13+
use Humbug\SelfUpdate\Updater;
14+
use Humbug\SelfUpdate\VersionParser;
1115
use Inhere\Console\Command;
1216
use Inhere\Console\IO\Input;
1317
use Inhere\Console\IO\Output;
14-
use Humbug\SelfUpdate\Updater;
15-
use Humbug\SelfUpdate\VersionParser;
16-
use Humbug\SelfUpdate\Strategy\ShaStrategy;
17-
use Humbug\SelfUpdate\Strategy\GithubStrategy;
1818

1919
/**
2020
* Class SelfUpdateCommand
@@ -40,7 +40,7 @@ class SelfUpdateCommand extends Command
4040

4141
/**
4242
* Execute the command.
43-
* @param Input $input
43+
* @param Input $input
4444
* @param Output $output
4545
*/
4646
protected function execute($input, $output)

0 commit comments

Comments
 (0)