Skip to content

Commit b74e8b9

Browse files
committed
bug fixed: group command ailas
new: add some symbol char classes
1 parent ab619ac commit b74e8b9

File tree

8 files changed

+160
-10
lines changed

8 files changed

+160
-10
lines changed

examples/Controllers/HomeController.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Inhere\Console\Components\Style\LiteStyle;
1212
use Inhere\Console\Utils\Helper;
1313
use Inhere\Console\Utils\Interact;
14+
use Inhere\Console\Utils\ProcessUtil;
1415
use Inhere\Console\Utils\ProgressBar;
1516
use Inhere\Console\Utils\Show;
1617

@@ -54,7 +55,7 @@ protected function init()
5455

5556
protected function afterExecute()
5657
{
57-
$this->write('after command execute');
58+
// $this->write('after command execute');
5859
}
5960

6061
/**
@@ -98,6 +99,14 @@ public function defArgCommand()
9899
$this->output->dump($this->input->getArgs(), $this->input->getOpts(), $this->input->getBoolOpt('y'));
99100
}
100101

102+
/**
103+
* dump current env information
104+
*/
105+
public function dumpEnvCommand()
106+
{
107+
$this->output->aList($_SERVER, '$_SERVER data');
108+
}
109+
101110
/**
102111
* a example for highlight code
103112
* @options
@@ -138,6 +147,25 @@ public function colorCommand()
138147
return 0;
139148
}
140149

150+
/**
151+
* check color support for current env.
152+
*/
153+
public function colorCheckCommand()
154+
{
155+
// $char= '❤';
156+
// $ret = ProcessUtil::run('echo ❤');
157+
// var_dump($ret, trim($ret[1]), $char === trim($ret[1]));
158+
//
159+
// die;
160+
161+
$this->output->aList([
162+
'basic color output?' => Helper::supportColor() ? '<info>Y</info>' : 'N',
163+
'ansi char output?' => Helper::isAnsiSupport() ? 'Y' : 'N',
164+
'256 color output?' => Helper::isSupport256Color() ? 'Y' : 'N',
165+
'font symbol output?' => Helper::isSupport256Color() ? 'Y' : 'N',
166+
], 'color support check');
167+
}
168+
141169
/**
142170
* a example for use color text output by LiteStyle::class
143171
*/

examples/Controllers/ProcessController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public function runScriptCommand()
7373

7474
echo "command returned $retVal\n";
7575
}
76+
77+
ProcessUtil::run();
7678
}
7779

7880
/**

src/Application.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ protected function dispatch(string $name)
282282
if (strpos($realName, $sep) > 0) {
283283
$input = array_values(array_filter(explode($sep, $realName)));
284284
list($realName, $action) = \count($input) > 2 ? array_splice($input, 2) : $input;
285+
$realName = $this->getRealCommandName($realName);
285286
}
286287

287288
if ($this->isController($realName)) {

src/BuiltIn/PharController.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class PharController extends Controller
2828
* @options
2929
* --dir STRING Setting the directory for packing.
3030
* - default is current work-dir.(<comment>{workDir}</comment>)
31+
* --fast BOOL Fast build. only add modified files by <cyan>git status -s</cyan>
3132
* --output STRING Setting the output file name(<comment>app.phar</comment>)
3233
* --refresh BOOL Whether build vendor folder files on phar file exists(<comment>False</comment>)
3334
* @param \Inhere\Console\IO\Input $in
@@ -38,21 +39,26 @@ public function packCommand($in, $out): int
3839
{
3940
$time = microtime(1);
4041
$workDir = $in->getPwd();
41-
$dir = $in->getOpt('dir') ?: $workDir;
42-
$pharFile = $workDir . '/' . $in->getOpt('output', 'app.phar');
4342

43+
$dir = $in->getOpt('dir') ?: $workDir;
4444
$cpr = $this->configCompiler($dir);
4545

4646
$counter = null;
4747
$refresh = $in->boolOpt('refresh');
48+
$pharFile = $workDir . '/' . $in->getOpt('output', 'app.phar');
49+
50+
// use fast build
51+
if ($this->input->boolOpt('fast')) {
52+
$cpr->setModifies($cpr->findChangedByGit());
53+
$this->output->liteNote('Use fast build, will only pack changed or new files(from git status)');
54+
}
4855

4956
$out->liteInfo(
5057
"Now, will begin building phar package.\n from path: <comment>$workDir</comment>\n" .
5158
" phar file: <info>$pharFile</info>"
5259
);
5360

5461
$out->info('Pack file to Phar: ');
55-
5662
$cpr->onError(function ($error) {
5763
$this->output->warning($error);
5864
});
@@ -63,7 +69,6 @@ public function packCommand($in, $out): int
6369
});
6470
} else {
6571
$counter = Show::counterTxt('Handling ...', 'Done.');
66-
6772
$cpr->onAdd(function () use($counter) {
6873
$counter->send(1);
6974
});
@@ -72,6 +77,7 @@ public function packCommand($in, $out): int
7277
// packing ...
7378
$cpr->pack($pharFile, $refresh);
7479

80+
// end
7581
if ($counter) {
7682
$counter->send(-1);
7783
}
@@ -94,9 +100,8 @@ public function packCommand($in, $out): int
94100
*/
95101
protected function configCompiler(string $dir): PharCompiler
96102
{
97-
$cpr = new PharCompiler($dir);
98-
99103
// config
104+
$cpr = new PharCompiler($dir);
100105
$cpr
101106
// ->stripComments(false)
102107
->setShebang(true)

src/BuiltIn/SelfUpdateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class SelfUpdateCommand extends Command
4545
*/
4646
protected function execute($input, $output)
4747
{
48-
$this->version = $this->getApplication()->getVersion();
48+
$this->version = $this->getApp()->getVersion();
4949
$parser = new VersionParser;
5050

5151
/**

src/Utils/EmojiSymbol.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: inhere
5+
* Date: 2018-01-26
6+
* Time: 9:33
7+
*/
8+
9+
namespace Inhere\Console\Utils;
10+
11+
/**
12+
* Class EmojiSymbol
13+
* @package Inhere\Console\Utils
14+
*/
15+
class EmojiSymbol
16+
{
17+
const KEY = '🔑';
18+
const BOX = '📦';
19+
const GIFT = '🎁';
20+
const CLOCK = '';
21+
const FLAG = '🚩';
22+
23+
const DOC = '📄';
24+
const DIR = '📂';
25+
const BOOK = '📔';
26+
27+
const TOOL = '🔧';
28+
const GUN = '🔫';
29+
30+
const UP = '👍';
31+
const DOWN = '👎';
32+
33+
const FIRE = '🔥';
34+
const SNOW = '';
35+
const WATER = '💧';
36+
const FLASH = '';
37+
38+
const HEART = '💖';
39+
40+
const SUC = '';
41+
const FAIL = '';
42+
const WAN = '';
43+
44+
const CAR = '🚕';
45+
46+
const TREE = '🌲';
47+
const FLOWER = '🌺';
48+
49+
const PEAR = '🍐';
50+
const APPLE = '🍎';
51+
52+
const ELEPHANT = '🐘';
53+
const WHALE = '🐳';
54+
55+
const SUN = '🌞';
56+
const STAR = '';
57+
const MOON = '🌜';
58+
59+
/**
60+
* @return array
61+
*/
62+
public static function getConstants(): array
63+
{
64+
$objClass = new \ReflectionClass(__CLASS__);
65+
66+
// 此处获取类中定义的全部常量 返回的是 [key=>value,...] 的数组
67+
// key是常量名 value是常量值
68+
return $objClass->getConstants();
69+
}
70+
}

src/Utils/FontSymbol.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: inhere
5+
* Date: 2018-01-26
6+
* Time: 9:33
7+
*/
8+
9+
namespace Inhere\Console\Utils;
10+
11+
/**
12+
* Class FontSymbol
13+
* - 字体符号
14+
* @package Inhere\Console\Utils
15+
*/
16+
class FontSymbol
17+
{
18+
const OK = '';
19+
const NO = '';
20+
const PEN = '';
21+
const HEART = '';
22+
23+
const UP = '';
24+
const DOWN = '';
25+
const LEFT = '';
26+
const RIGHT = '';
27+
28+
const MALE = '';
29+
const FEMALE = '';
30+
31+
/**
32+
* @return array
33+
*/
34+
public static function getConstants(): array
35+
{
36+
$objClass = new \ReflectionClass(__CLASS__);
37+
38+
return $objClass->getConstants();
39+
}
40+
}

src/Utils/Helper.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public static function supportColor(): bool
103103
/**
104104
* @return bool
105105
*/
106-
public function isSupport256Color(): bool
106+
public static function isSupport256Color(): bool
107107
{
108108
return DIRECTORY_SEPARATOR === '/' && strpos(getenv('TERM'), '256color') !== false;
109109
}
@@ -113,7 +113,11 @@ public function isSupport256Color(): bool
113113
*/
114114
public static function isAnsiSupport(): bool
115115
{
116-
return getenv('ANSICON') === true || getenv('ConEmuANSI') === 'ON';
116+
if (DIRECTORY_SEPARATOR === '\\') {
117+
return getenv('ANSICON') === true || getenv('ConEmuANSI') === 'ON';
118+
}
119+
120+
return true;
117121
}
118122

119123
/**

0 commit comments

Comments
 (0)