Skip to content

Commit 571d69b

Browse files
committed
fix: #2 cli app run error
1 parent cd1b24c commit 571d69b

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

src/App.php

+11-10
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class App
9999
/**
100100
* Class constructor.
101101
*
102-
* @param array $config
102+
* @param array $config
103103
* @param array|null $argv
104104
*/
105105
public function __construct(array $config = [], array $argv = null)
@@ -186,7 +186,7 @@ protected function doHandle(): int
186186
}
187187

188188
if (!isset($this->commands[$command])) {
189-
$this->displayHelp("The command '{$command}' is not exists!");
189+
$this->displayHelp("The command '$command' is not exists!");
190190
return 0;
191191
}
192192

@@ -201,15 +201,15 @@ protected function doHandle(): int
201201
$status = $this->handleException($e);
202202
}
203203

204-
return $status;
204+
return (int)$status;
205205
}
206206

207207
/**
208208
* @param int $code
209209
*/
210210
public function stop(int $code = 0): void
211211
{
212-
exit((int)$code);
212+
exit($code);
213213
}
214214

215215
/**
@@ -369,16 +369,17 @@ public function commands(array $commands): void
369369
public function displayHelp(string $err = ''): void
370370
{
371371
if ($err) {
372-
Color::println("<red>ERROR</red>: $err\n");
372+
Cli::println("<red>ERROR</red>: $err\n");
373373
}
374374

375375
// help
376-
$desc = ucfirst($this->metas['desc']);
376+
$desc = ucfirst($this->metas['desc']);
377377
if ($ver = $this->metas['version']) {
378378
$desc .= "(<red>v$ver</red>)";
379379
}
380380

381-
$usage = "<cyan>{$this->script} COMMAND -h</cyan>";
381+
$script = $this->script;
382+
$usage = "<cyan>$script COMMAND -h</cyan>";
382383

383384
$help = "$desc\n\n<comment>Usage:</comment> $usage\n<comment>Commands:</comment>\n";
384385
$data = $this->messages;
@@ -390,9 +391,9 @@ public function displayHelp(string $err = ''): void
390391
$help .= " <green>$command</green> $desc\n";
391392
}
392393

393-
$help .= "\nFor command usage please run: <cyan>{$this->script} COMMAND -h</cyan>";
394+
$help .= "\nFor command usage please run: <cyan>$script COMMAND -h</cyan>";
394395

395-
Color::println($help);
396+
Cli::println($help);
396397
}
397398

398399
/**
@@ -435,7 +436,7 @@ public function displayCommandHelp(string $name): void
435436
]);
436437
}
437438

438-
Color::println($help);
439+
Cli::println($help);
439440
}
440441

441442
/**

src/Cli.php

-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ public static function isAnsiSupport(): bool
194194
*/
195195
public static function isInteractive($fileDescriptor): bool
196196
{
197-
/** @noinspection PhpComposerExtensionStubsInspection */
198197
return function_exists('posix_isatty') && @posix_isatty($fileDescriptor);
199198
}
200199

src/Color.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
/**
2424
* Class Color
2525
*
26+
* Usage:
27+
*
28+
* ```php
29+
* echo Color::red('hello');
30+
* echo Color::info('hello');
31+
* ```
32+
*
2633
* @package Toolkit\Cli
2734
* // basic
2835
* @method string red(string $text)
@@ -367,9 +374,9 @@ public static function render(string $text, $style = null): string
367374
*
368375
* @param string $text
369376
*
370-
* @return mixed|string
377+
* @return string
371378
*/
372-
public static function parseTag(string $text)
379+
public static function parseTag(string $text): string
373380
{
374381
return ColorTag::parse($text);
375382
}

0 commit comments

Comments
 (0)