Skip to content

Commit a9a38fb

Browse files
committed
upsome
1 parent a54704c commit a9a38fb

File tree

3 files changed

+10
-78
lines changed

3 files changed

+10
-78
lines changed

src/App.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ class App
6464
/**
6565
* @var array Parsed from `arg0 name=val var2=val2`
6666
*/
67-
private $args = [];
67+
private $args;
6868

6969
/**
7070
* @var array Parsed from `--name=val --var2=val2 -d`
7171
*/
72-
private $opts = [];
72+
private $opts;
7373

7474
/**
7575
* @var string
@@ -111,7 +111,7 @@ public function __construct(array $config = [], array $argv = null)
111111
$this->pwd = (string)getcwd();
112112

113113
// parse cli argv
114-
$argv = $argv ?? (array)$_SERVER['argv'];
114+
$argv = $argv ?? $_SERVER['argv'];
115115
if ($config) {
116116
$this->setMetas($config);
117117
}

src/Cli.php

Lines changed: 6 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,12 @@
1313
use Toolkit\Cli\Traits\WriteMessageTrait;
1414
use function date;
1515
use function defined;
16-
use function fflush;
17-
use function fgets;
1816
use function function_exists;
19-
use function fwrite;
2017
use function getenv;
2118
use function implode;
22-
use function is_array;
23-
use function is_int;
2419
use function is_numeric;
2520
use function json_encode;
2621
use function preg_replace;
27-
use function sprintf;
2822
use function strpos;
2923
use function strtoupper;
3024
use function trim;
@@ -35,7 +29,6 @@
3529
use const PHP_WINDOWS_VERSION_BUILD;
3630
use const PHP_WINDOWS_VERSION_MAJOR;
3731
use const PHP_WINDOWS_VERSION_MINOR;
38-
use const STDERR;
3932
use const STDOUT;
4033

4134
/**
@@ -45,7 +38,7 @@
4538
*/
4639
class Cli
4740
{
48-
// use ReadMessageTrait, WriteMessageTrait;
41+
use ReadMessageTrait, WriteMessageTrait;
4942

5043
public const LOG_LEVEL2TAG = [
5144
'info' => 'info',
@@ -57,78 +50,17 @@ class Cli
5750
];
5851

5952
/*******************************************************************************
60-
* read message
61-
******************************************************************************/
62-
63-
/*******************************************************************************
64-
* write message
53+
* color render
6554
******************************************************************************/
6655

6756
/**
68-
* @param string $format
69-
* @param mixed ...$args
70-
*/
71-
public static function writef(string $format, ...$args): void
72-
{
73-
self::write(sprintf($format, ...$args));
74-
}
75-
76-
/**
77-
* Write message to console
78-
*
79-
* @param string|array $messages
80-
* @param bool $nl
81-
* @param bool|int $quit
82-
*/
83-
public static function write($messages, bool $nl = true, $quit = false): void
84-
{
85-
if (is_array($messages)) {
86-
$messages = implode($nl ? PHP_EOL : '', $messages);
87-
}
88-
89-
self::stdout(Color::parseTag($messages), $nl, $quit);
90-
}
91-
92-
/**
93-
* Logs data to stdout
94-
*
95-
* @param string $message
96-
* @param bool $nl
97-
* @param bool|int $quit
98-
*/
99-
public static function stdout(string $message, bool $nl = true, $quit = false): void
100-
{
101-
fwrite(STDOUT, $message . ($nl ? PHP_EOL : ''));
102-
fflush(STDOUT);
103-
104-
if (($isTrue = true === $quit) || is_int($quit)) {
105-
$code = $isTrue ? 0 : $quit;
106-
exit($code);
107-
}
108-
}
109-
110-
/**
111-
* Logs data to stderr
112-
*
113-
* @param string $message
114-
* @param bool $nl
115-
* @param bool|int $quit
57+
* @return Style
11658
*/
117-
public static function stderr(string $message, $nl = true, $quit = -1): void
59+
public static function style(): Style
11860
{
119-
fwrite(STDERR, self::color('[ERROR] ', 'red') . $message . ($nl ? PHP_EOL : ''));
120-
fflush(STDOUT);
121-
122-
if (($isTrue = true === $quit) || is_int($quit)) {
123-
$code = $isTrue ? 0 : $quit;
124-
exit($code);
125-
}
61+
return Style::instance();
12662
}
12763

128-
/*******************************************************************************
129-
* color render
130-
******************************************************************************/
131-
13264
/**
13365
* @param string $text
13466
* @param string|int|array $style
@@ -154,7 +86,7 @@ public static function color(string $text, $style = null): string
15486
* 'coId' => 12,
15587
* ]
15688
*/
157-
public static function log(string $msg, array $data = [], string $type = 'info', array $opts = []): void
89+
public static function clog(string $msg, array $data = [], string $type = 'info', array $opts = []): void
15890
{
15991
if (isset(self::LOG_LEVEL2TAG[$type])) {
16092
$type = ColorTag::add(strtoupper($type), self::LOG_LEVEL2TAG[$type]);

src/Traits/WriteMessageTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public static function stdout($text, bool $nl = true, $quit = false): void
198198
* @param bool $nl
199199
* @param bool|int $quit
200200
*/
201-
public static function stderr($text, $nl = true, $quit = -200): void
201+
public static function stderr($text, $nl = true, $quit = -2): void
202202
{
203203
self::write($text, $nl, $quit, [
204204
'stream' => self::$errorStream,

0 commit comments

Comments
 (0)