Skip to content

Commit c1babcf

Browse files
committed
update some info
1 parent ec234d4 commit c1babcf

File tree

12 files changed

+80
-92
lines changed

12 files changed

+80
-92
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
"type": "library",
44
"description": "a php console library, provide console argument parse, console controller/command run, color style, user interactive, information show.",
55
"keywords": [
6-
"library",
6+
"cli",
7+
"phar",
8+
"color",
79
"console",
810
"console-color",
911
"command",
1012
"command-line",
11-
"cli",
1213
"console-application"
1314
],
1415
"homepage": "https://github.com/inhere/php-console",

examples/Command/DemoCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class DemoCommand extends Command
2828
protected function configure()
2929
{
3030
$this->createDefinition()
31-
->setDescription(self::getDescription())
3231
->setExample($this->parseAnnotationVars('{script} {command} john male 43 --opt1 value1'))
3332
->addArgument('name', Input::ARG_REQUIRED, 'description for the argument [name], is required')
3433
->addArgument('sex', Input::ARG_OPTIONAL, 'description for the argument [sex], is optional')

examples/Controller/HomeController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected function init()
4545
{
4646
parent::init();
4747

48-
$this->addAnnotationVar('internalFonts', implode(',', ArtFont::getInternalFonts()));
48+
$this->addCommentsVar('internalFonts', implode(',', ArtFont::getInternalFonts()));
4949
}
5050

5151
protected function disabledCommands(): array

src/AbstractCommand.php

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ abstract class AbstractCommand implements BaseCommandInterface
7373
private $processTitle = '';
7474

7575
/** @var array */
76-
private $annotationVars;
76+
private $commentsVars;
7777

7878
/**
7979
* Whether enabled
@@ -110,7 +110,7 @@ public function __construct(Input $input, Output $output, InputDefinition $defin
110110
}
111111

112112
$this->commonOptions = $this->commonOptions();
113-
$this->annotationVars = $this->annotationVars();
113+
$this->commentsVars = $this->annotationVars();
114114

115115
$this->init();
116116
}
@@ -120,7 +120,7 @@ protected function init()
120120
}
121121

122122
/**
123-
* Configure input definition for command
123+
* Configure input definition for command, like symfony console.
124124
* @return InputDefinition|null
125125
*/
126126
protected function configure()
@@ -137,12 +137,14 @@ protected function createDefinition(): InputDefinition
137137
{
138138
if (!$this->definition) {
139139
$this->definition = new InputDefinition();
140+
$this->definition->setDescription(self::getDescription());
140141
}
141142

142143
return $this->definition;
143144
}
144145

145146
/**
147+
* you can set common options for all sub-commands
146148
* @return array
147149
*/
148150
protected function commonOptions(): array
@@ -153,7 +155,19 @@ protected function commonOptions(): array
153155
}
154156

155157
/**
156-
* 为命令注解提供可解析解析变量. 可以在命令的注释中使用
158+
* Provides parsable substitution variables for command annotations. Can be used in comments in commands
159+
* 为命令注解提供可解析的替换变量. 可以在命令的注释中使用
160+
*
161+
* you can append by:
162+
*
163+
* ```php
164+
* protected function annotationVars(): array
165+
* {
166+
* return \array_merge(parent::annotationVars(), [
167+
* 'myVar' => 'value',
168+
* ]);
169+
* }
170+
* ```
157171
* @return array
158172
*/
159173
protected function annotationVars(): array
@@ -368,7 +382,6 @@ public function validateInput(): bool
368382
\sprintf('Not enough options parameters (missing: "%s").',
369383
\implode(', ', $missingOpts))
370384
);
371-
372385
return false;
373386
}
374387

@@ -385,40 +398,40 @@ public function validateInput(): bool
385398

386399
/**
387400
* @param string $name
388-
* @param string $value
401+
* @param string|array $value
389402
*/
390-
protected function addAnnotationVar(string $name, $value)
403+
protected function addCommentsVar(string $name, $value)
391404
{
392-
if (!isset($this->annotationVars[$name])) {
393-
$this->annotationVars[$name] = (string)$value;
405+
if (!isset($this->commentsVars[$name])) {
406+
$this->setCommentsVar($name, $value);
394407
}
395408
}
396409

397410
/**
398411
* @param array $map
399412
*/
400-
protected function addAnnotationVars(array $map)
413+
protected function addCommentsVars(array $map)
401414
{
402415
foreach ($map as $name => $value) {
403-
$this->addAnnotationVar($name, $value);
416+
$this->setCommentsVar($name, $value);
404417
}
405418
}
406419

407420
/**
408421
* @param string $name
409422
* @param string|array $value
410423
*/
411-
protected function setAnnotationVar(string $name, $value)
424+
protected function setCommentsVar(string $name, $value)
412425
{
413-
$this->annotationVars[$name] = \is_array($value) ? \implode(',', $value) : (string)$value;
426+
$this->commentsVars[$name] = \is_array($value) ? \implode(',', $value) : (string)$value;
414427
}
415428

416429
/**
417430
* 替换注解中的变量为对应的值
418431
* @param string $str
419432
* @return string
420433
*/
421-
protected function parseAnnotationVars(string $str): string
434+
protected function parseCommentsVars(string $str): string
422435
{
423436
// not use vars
424437
if (false === \strpos($str, '{')) {
@@ -428,7 +441,7 @@ protected function parseAnnotationVars(string $str): string
428441
static $map;
429442

430443
if ($map === null) {
431-
foreach ($this->annotationVars as $key => $value) {
444+
foreach ($this->commentsVars as $key => $value) {
432445
$key = \sprintf(self::ANNOTATION_VAR, $key);
433446
$map[$key] = $value;
434447
}
@@ -505,7 +518,7 @@ protected function showHelpByMethodAnnotations(string $method, string $action =
505518
}
506519

507520
$doc = $ref->getMethod($method)->getDocComment();
508-
$tags = PhpDoc::getTags($this->parseAnnotationVars($doc));
521+
$tags = PhpDoc::getTags($this->parseCommentsVars($doc));
509522
$isAlone = $ref->isSubclassOf(CommandInterface::class);
510523
$help = [];
511524

@@ -523,7 +536,7 @@ protected function showHelpByMethodAnnotations(string $method, string $action =
523536
}
524537

525538
if ($tag === 'usage') {
526-
$help['Usage:'] = $this->annotationVars['fullCommand'] . ' [--options ...] [arguments ...]';
539+
$help['Usage:'] = $this->commentsVars['fullCommand'] . ' [--options ...] [arguments ...]';
527540
}
528541

529542
continue;
@@ -667,9 +680,9 @@ public function getCommonOptions(): array
667680
/**
668681
* @return array
669682
*/
670-
public function getAnnotationVars(): array
683+
public function getCommentsVars(): array
671684
{
672-
return $this->annotationVars;
685+
return $this->commentsVars;
673686
}
674687

675688
/**

src/BuiltIn/GenShellAutoComplete.php

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/BuiltIn/PharController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected function init()
3131
{
3232
parent::init();
3333

34-
$this->addAnnotationVar('defaultPkgName', \basename($this->input->getPwd()));
34+
$this->addCommentsVar('defaultPkgName', \basename($this->input->getPwd()));
3535
}
3636

3737
/**
@@ -50,6 +50,7 @@ protected function init()
5050
* @throws \UnexpectedValueException
5151
* @throws \RuntimeException
5252
* @throws \BadMethodCallException
53+
* @throws \Exception
5354
*/
5455
public function packCommand($in, $out): int
5556
{

src/BuiltIn/SelfUpdateCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,12 @@ protected function configure()
291291
$this
292292
->createDefinition()
293293
// ->setName('self-update')
294-
->setDescription(self::$description)
294+
// ->setDescription(self::$description)
295295
->addOption(
296296
'dev',
297297
'd',
298298
Input::OPT_BOOLEAN,
299-
'Update to most recent <fg=cyan>development build</fg=cyan> of package.'
299+
'Update to most recent <cyan>development build</cyan> of package.'
300300
)
301301
->addOption(
302302
'non-dev',

src/Component/Formatter/Formatter.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
namespace Inhere\Console\Component\Formatter;
1010

11+
use Inhere\Console\Util\Helper;
12+
use Toolkit\PhpUtil\PhpHelper;
13+
1114
/**
1215
* Class Formatter - message formatter
1316
* @package Inhere\Console\Component\Formatter
@@ -35,15 +38,7 @@ public static function create(array $config = [])
3538
*/
3639
public function __construct(array $config = [])
3740
{
38-
foreach ($config as $name => $value) {
39-
$setter = 'set' . \ucfirst($name);
40-
41-
if (\method_exists($this, $setter)) {
42-
$this->$setter($value);
43-
} elseif (\property_exists($this, $name)) {
44-
$this->$name = $value;
45-
}
46-
}
41+
PhpHelper::initObject($this, $config);
4742

4843
$this->config = $config;
4944
}

src/IO/Input/InputArgument.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,24 @@
1515
*/
1616
class InputArgument extends InputItem
1717
{
18+
/**
19+
* @var int
20+
*/
21+
private $index = 0;
1822

19-
}
23+
/**
24+
* @return int
25+
*/
26+
public function getIndex(): int
27+
{
28+
return $this->index;
29+
}
30+
31+
/**
32+
* @param int $index
33+
*/
34+
public function setIndex(int $index): void
35+
{
36+
$this->index = $index;
37+
}
38+
}

src/IO/Input/InputItem.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ class InputItem
2222
*/
2323
public $name;
2424

25-
/**
26-
* alias name
27-
* @var string
28-
*/
29-
public $alias;
30-
3125
/**
3226
* @var string
3327
*/

0 commit comments

Comments
 (0)