Skip to content

Commit 9c7db43

Browse files
committed
some update, add some art font
1 parent fd81308 commit 9c7db43

File tree

11 files changed

+209
-73
lines changed

11 files changed

+209
-73
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
[![Php Version](https://img.shields.io/badge/php-%3E=7.0-brightgreen.svg?maxAge=2592000)](https://packagist.org/packages/inhere/console)
55
[![Latest Stable Version](http://img.shields.io/packagist/v/inhere/console.svg)](https://packagist.org/packages/inhere/console)
66

7-
简洁、功能全面的php命令行应用库。提供控制台参数解析, 颜色风格输出, 用户信息交互, 特殊格式信息显示。
7+
简洁、功能全面的php命令行应用库。提供控制台参数解析, 命令运行,颜色风格输出, 用户信息交互, 特殊格式信息显示。
88

99
> 无其他库依赖,可以方便的整合到任何已有项目中。
1010
1111
- 功能全面的命令行的选项参数解析(命名参数,短选项,长选项 ...)
12-
- 命令行应用, 命令行的 `controller`, `command` 解析运行
12+
- 命令行应用, 命令行的 `controller`, `command` 解析运行。(支持命令别名)
1313
- 命令行中功能强大的 `input`, `output` 管理、使用
1414
- 消息文本的多种颜色风格输出支持(`info`, `comment`, `success`, `danger`, `error` ... ...)
1515
- 丰富的特殊格式信息显示(`section`, `panel`, `padding`, `help-panel`, `table`, `title`, `list`, `multiList`, `progressBar`)

examples/app

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ $app = new \Inhere\Console\Application([
1111
'rootPath' => dirname(__DIR__),
1212
]);
1313

14+
$app->setLogoText('
15+
_ _ ___ _ _
16+
| || | / _ \| || |
17+
| || |_| | | | || |_
18+
|__ _| | | |__ _|
19+
| | | |_| | | |
20+
|_| \___/ |_|
21+
');
22+
1423
// require dirname(__DIR__) . '/boot/cli-services.php';
1524

1625
require __DIR__ . '/routes.php';

src/Application.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public function addController(string $name, string $class = null)
8282

8383
/**
8484
* @param array $controllers
85+
* @throws \InvalidArgumentException
8586
*/
8687
public function controllers(array $controllers)
8788
{
@@ -149,6 +150,7 @@ public function command(string $name, $handler = null, $option = null)
149150

150151
/**
151152
* @param array $commands
153+
* @throws \InvalidArgumentException
152154
*/
153155
public function commands(array $commands)
154156
{
@@ -254,16 +256,14 @@ protected function dispatch($name)
254256
{
255257
$sep = $this->delimiter ?: ':';
256258

257-
//// is a command name
258-
259+
// maybe is a command name
259260
$realName = $this->getRealCommandName($name);
260261

261262
if ($this->isCommand($realName)) {
262263
return $this->runCommand($realName, true);
263264
}
264265

265-
//// is a controller name
266-
266+
// maybe is a controller name
267267
$action = '';
268268

269269
// like 'home:index'
@@ -282,19 +282,10 @@ protected function dispatch($name)
282282
if (true !== self::fire(self::ON_NOT_FOUND, [$this])) {
283283
$this->output->liteError("The console command '{$name}' not exists!");
284284

285-
// find similar command names by similar_text()
286-
$similar = [];
287285
$commands = array_merge($this->getControllerNames(), $this->getCommandNames());
288286

289-
foreach ($commands as $command) {
290-
similar_text($name, $command, $percent);
291-
292-
if (45 <= (int)$percent) {
293-
$similar[] = $command;
294-
}
295-
}
296-
297-
if ($similar) {
287+
// find similar command names by similar_text()
288+
if ($similar = Helper::findSimilar($name, $commands)) {
298289
$this->write(sprintf("\nMaybe what you mean is:\n <info>%s</info>", implode(', ', $similar)));
299290
} else {
300291
$this->showCommandList(false);

src/Base/AbstractApplication.php

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@ abstract class AbstractApplication implements ApplicationInterface
2424
{
2525
use InputOutputAwareTrait, SimpleEventTrait;
2626

27-
/**
28-
* @var array
29-
* [
30-
* 0 => logo text,
31-
* 1 => color style, // 'info'
32-
* ]
33-
*/
34-
private static $logoInfo;
35-
3627
/** @var array */
3728
protected static $internalCommands = [
3829
'version' => 'Show application version information',
@@ -66,6 +57,9 @@ abstract class AbstractApplication implements ApplicationInterface
6657
// 'env' => 'pdt', // dev test pdt
6758
// 'charset' => 'UTF-8',
6859

60+
'logoText' => '',
61+
'logoStyle' => 'info',
62+
6963
// runtime stats
7064
'_stats' => [],
7165
];
@@ -366,16 +360,21 @@ public function showHelpInfo($quit = true, string $command = null)
366360
*/
367361
public function showVersionInfo($quit = true)
368362
{
363+
$os = PHP_OS;
369364
$date = date('Y.m.d');
365+
$logo = '';
370366
$name = $this->getMeta('name', 'Console Application');
371367
$version = $this->getMeta('version', 'Unknown');
372368
$publishAt = $this->getMeta('publishAt', 'Unknown');
373369
$updateAt = $this->getMeta('updateAt', 'Unknown');
374370
$phpVersion = PHP_VERSION;
375-
$os = PHP_OS;
371+
372+
if ($logoTxt = $this->getLogoText()) {
373+
$logo = Helper::wrapTag($logoTxt, $this->getLogoStyle());
374+
}
376375

377376
$this->output->aList([
378-
"\n <info>{$name}</info>, Version <comment>$version</comment>\n",
377+
"\n <info>{$name}</info>, Version <comment>$version</comment>\n$logo",
379378
'System Info' => "PHP version <info>$phpVersion</info>, on <info>$os</info> system",
380379
'Application Info' => "Update at <info>$updateAt</info>, publish at <info>$publishAt</info>(current $date)",
381380
], null, [
@@ -606,49 +605,33 @@ public function isCommand($name)
606605
/**
607606
* @return string|null
608607
*/
609-
public static function getLogoTxt()
608+
public function getLogoText()
610609
{
611-
return self::$logoInfo[0] ?? null;
610+
return $this->meta['logoText'] ?? null;
612611
}
613612

614613
/**
615614
* @param string $logoTxt
616615
*/
617-
public static function setLogoTxt(string $logoTxt)
616+
public function setLogoText(string $logoTxt)
618617
{
619-
self::$logoInfo[0] = $logoTxt;
618+
$this->meta['logoText'] = $logoTxt;
620619
}
621620

622621
/**
623622
* @return string|null
624623
*/
625-
public static function getLogoStyle()
624+
public function getLogoStyle()
626625
{
627-
return self::$logoInfo[1] ?? 'info';
626+
return $this->meta['logoStyle'] ?? 'info';
628627
}
629628

630629
/**
631630
* @param string $style
632631
*/
633-
public static function setLogoStyle(string $style)
634-
{
635-
self::$logoInfo[1] = $style;
636-
}
637-
638-
/**
639-
* @return array
640-
*/
641-
public static function getLogoInfo(): array
642-
{
643-
return self::$logoInfo;
644-
}
645-
646-
/**
647-
* @param array $logoInfo
648-
*/
649-
public static function setLogoInfo(array $logoInfo)
632+
public function setLogoStyle(string $style)
650633
{
651-
self::$logoInfo = $logoInfo;
634+
$this->meta['logoStyle'] = $style;
652635
}
653636

654637
/**
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: inhere
5+
* Date: 2017-12-20
6+
* Time: 10:08
7+
*/
8+
9+
namespace Inhere\Console\BuiltIn\ArtFonts;
10+
11+
/**
12+
* Class ArtFontsBlock
13+
* @package Inhere\Console\BuiltIn\ArtFonts
14+
*/
15+
class ArtFontsBlock
16+
{
17+
const SUCCESS = '
18+
_____
19+
/ ____|
20+
| (___ _ _ ___ ___ ___ ___ ___
21+
\___ \| | | |/ __/ __/ _ \/ __/ __|
22+
____) | |_| | (_| (_| __/\__ \__ \
23+
|_____/ \____|\___\___\___||___/___/
24+
';
25+
26+
const ERROR = "
27+
______
28+
| ____|
29+
| |__ _ __ _ __ ___ _ __
30+
| __| | '__| '__/ _ \| '__|
31+
| |____| | | | | (_) | |
32+
|______|_| |_| \___/|_|
33+
";
34+
35+
const ERROR_404 = '
36+
_ _ ___ _ _
37+
| || | / _ \| || |
38+
| || |_| | | | || |_
39+
|__ _| | | |__ _|
40+
| | | |_| | | |
41+
|_| \___/ |_|
42+
';
43+
44+
const ERROR_500 = '
45+
_____ ___ ___
46+
| ____|/ _ \ / _ \
47+
| |__ | | | | | | |
48+
|___ \| | | | | | |
49+
___) | |_| | |_| |
50+
|____/ \___/ \___/
51+
';
52+
53+
const YES = '
54+
__ __
55+
\ \ / /
56+
\ \_/ /__ ___
57+
\ / _ \/ __|
58+
| | __/\__ \
59+
|_|\___||___/
60+
';
61+
62+
const OK = '
63+
____ _
64+
/ __ \| |
65+
| | | | | __
66+
| | | | |/ /
67+
| |__| | <
68+
\____/|_|\_\
69+
';
70+
71+
const NO = '
72+
_ _
73+
| \ | |
74+
| \| | ___
75+
| . ` |/ _ \
76+
| |\ | (_) |
77+
|_| \_|\___/
78+
';
79+
}
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: 2017-12-20
6+
* Time: 11:31
7+
*/
8+
9+
namespace Inhere\Console\BuiltIn\ArtFonts;
10+
11+
/**
12+
* Class ArtFontsItalic
13+
* @package Inhere\Console\BuiltIn\ArtFonts
14+
*/
15+
class ArtFontsItalic
16+
{
17+
18+
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
_ _ ___ _ _
2-
| || | / _ \| || |
3-
| || |_| | | | || |_
4-
|__ _| | | |__ _|
5-
| | | |_| | | |
6-
|_| \___/ |_|
1+
_ _ ___ _ _
2+
| || | / _ \| || |
3+
| || |_| | | | || |_
4+
|__ _| | | |__ _|
5+
| | | |_| | | |
6+
|_| \___/ |_|
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
_____ ___ ___
2+
| ____|/ _ \ / _ \
3+
| |__ | | | | | | |
4+
|___ \| | | | | | |
5+
___) | |_| | |_| |
6+
|____/ \___/ \___/

src/Components/ArtFont.php

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

99
namespace Inhere\Console\Components;
1010

11+
use Inhere\Console\BuiltIn\ArtFonts\ArtFontsBlock;
12+
1113
/**
1214
* Class ArtFont
1315
* @package Inhere\Console\Components
@@ -26,6 +28,12 @@ class ArtFont
2628
*/
2729
private $fonts = [];
2830

31+
/**
32+
* @see ArtFontsBlock
33+
* @var array
34+
*/
35+
private $classFonts = [];
36+
2937
/**
3038
* @return self
3139
*/
@@ -99,4 +107,20 @@ public function setFonts(array $fonts)
99107
$this->addFont($name, $font);
100108
}
101109
}
110+
111+
/**
112+
* @return array
113+
*/
114+
public function getClassFonts(): array
115+
{
116+
return $this->classFonts;
117+
}
118+
119+
/**
120+
* @param array $classFonts
121+
*/
122+
public function setClassFonts(array $classFonts)
123+
{
124+
$this->classFonts = $classFonts;
125+
}
102126
}

0 commit comments

Comments
 (0)