mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 21:04:52 +08:00
replace symfony console return values
This commit is contained in:
parent
7a1433a994
commit
a1e4125ded
@ -15,7 +15,7 @@ use Symfony\Component\Console\Command\ListCommand;
|
|||||||
*/
|
*/
|
||||||
class ConsoleApplication extends Application
|
class ConsoleApplication extends Application
|
||||||
{
|
{
|
||||||
public const VERSION = '2.0-rc4';
|
public const VERSION = '2.0-rc5';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws \ReflectionException
|
* @throws \ReflectionException
|
||||||
|
|||||||
@ -91,7 +91,7 @@ abstract class BaseCommand extends Command
|
|||||||
foreach ($msg as $v) {
|
foreach ($msg as $v) {
|
||||||
logger()->error($v);
|
logger()->error($v);
|
||||||
}
|
}
|
||||||
return self::FAILURE;
|
return static::FAILURE;
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
// 不开 debug 模式就不要再显示复杂的调试栈信息了
|
// 不开 debug 模式就不要再显示复杂的调试栈信息了
|
||||||
if ($this->getOption('debug')) {
|
if ($this->getOption('debug')) {
|
||||||
@ -102,10 +102,10 @@ abstract class BaseCommand extends Command
|
|||||||
logger()->error($v);
|
logger()->error($v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return self::FAILURE;
|
return static::FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return self::SUCCESS;
|
return static::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getOption(string $name): mixed
|
protected function getOption(string $name): mixed
|
||||||
|
|||||||
@ -51,7 +51,7 @@ class BuildCliCommand extends BuildCommand
|
|||||||
$this->output->writeln("<comment>\t--build-micro\tBuild phpmicro SAPI</comment>");
|
$this->output->writeln("<comment>\t--build-micro\tBuild phpmicro SAPI</comment>");
|
||||||
$this->output->writeln("<comment>\t--build-fpm\tBuild php-fpm SAPI</comment>");
|
$this->output->writeln("<comment>\t--build-fpm\tBuild php-fpm SAPI</comment>");
|
||||||
$this->output->writeln("<comment>\t--build-all\tBuild all SAPI: cli, micro, fpm</comment>");
|
$this->output->writeln("<comment>\t--build-all\tBuild all SAPI: cli, micro, fpm</comment>");
|
||||||
return 1;
|
return static::FAILURE;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// 构建对象
|
// 构建对象
|
||||||
@ -113,10 +113,10 @@ class BuildCliCommand extends BuildCommand
|
|||||||
$dumper = new LicenseDumper();
|
$dumper = new LicenseDumper();
|
||||||
$dumper->addExts($extensions)->addLibs($libraries)->addSources(['php-src'])->dump(BUILD_ROOT_PATH . '/license');
|
$dumper->addExts($extensions)->addLibs($libraries)->addSources(['php-src'])->dump(BUILD_ROOT_PATH . '/license');
|
||||||
logger()->info('License path' . $fixed . ': ' . $build_root_path . '/license/');
|
logger()->info('License path' . $fixed . ': ' . $build_root_path . '/license/');
|
||||||
return 0;
|
return static::SUCCESS;
|
||||||
} catch (WrongUsageException $e) {
|
} catch (WrongUsageException $e) {
|
||||||
logger()->critical($e->getMessage());
|
logger()->critical($e->getMessage());
|
||||||
return 1;
|
return static::FAILURE;
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
if ($this->getOption('debug')) {
|
if ($this->getOption('debug')) {
|
||||||
ExceptionHandler::getInstance()->handle($e);
|
ExceptionHandler::getInstance()->handle($e);
|
||||||
@ -124,7 +124,7 @@ class BuildCliCommand extends BuildCommand
|
|||||||
logger()->critical('Build failed with ' . get_class($e) . ': ' . $e->getMessage());
|
logger()->critical('Build failed with ' . get_class($e) . ': ' . $e->getMessage());
|
||||||
logger()->critical('Please check with --debug option to see more details.');
|
logger()->critical('Please check with --debug option to see more details.');
|
||||||
}
|
}
|
||||||
return 1;
|
return static::FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,7 +63,7 @@ class BuildLibsCommand extends BuildCommand
|
|||||||
|
|
||||||
$time = round(microtime(true) - START_TIME, 3);
|
$time = round(microtime(true) - START_TIME, 3);
|
||||||
logger()->info('Build libs complete, used ' . $time . ' s !');
|
logger()->info('Build libs complete, used ' . $time . ' s !');
|
||||||
return 0;
|
return static::SUCCESS;
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
if ($this->getOption('debug')) {
|
if ($this->getOption('debug')) {
|
||||||
ExceptionHandler::getInstance()->handle($e);
|
ExceptionHandler::getInstance()->handle($e);
|
||||||
@ -71,7 +71,7 @@ class BuildLibsCommand extends BuildCommand
|
|||||||
logger()->critical('Build failed with ' . get_class($e) . ': ' . $e->getMessage());
|
logger()->critical('Build failed with ' . get_class($e) . ': ' . $e->getMessage());
|
||||||
logger()->critical('Please check with --debug option to see more details.');
|
logger()->critical('Please check with --debug option to see more details.');
|
||||||
}
|
}
|
||||||
return 1;
|
return static::FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,7 +60,7 @@ class DeployCommand extends BaseCommand
|
|||||||
$ask = $this->getOption('overwrite') ? true : $prompt->requireBool('<comment>The file "' . $phar_path . '" already exists, do you want to overwrite it?</comment>' . PHP_EOL . 'If you want to, just Enter');
|
$ask = $this->getOption('overwrite') ? true : $prompt->requireBool('<comment>The file "' . $phar_path . '" already exists, do you want to overwrite it?</comment>' . PHP_EOL . 'If you want to, just Enter');
|
||||||
if (!$ask) {
|
if (!$ask) {
|
||||||
$this->output->writeln('<comment>User canceled.</comment>');
|
$this->output->writeln('<comment>User canceled.</comment>');
|
||||||
return 1;
|
return static::FAILURE;
|
||||||
}
|
}
|
||||||
@unlink($phar_path);
|
@unlink($phar_path);
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@ class DeployCommand extends BaseCommand
|
|||||||
$phar->setStub($phar->createDefaultStub($stub));
|
$phar->setStub($phar->createDefaultStub($stub));
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
$this->output->writeln($e);
|
$this->output->writeln($e);
|
||||||
return 1;
|
return static::FAILURE;
|
||||||
}
|
}
|
||||||
$phar->addFromString('.prod', 'true');
|
$phar->addFromString('.prod', 'true');
|
||||||
$phar->stopBuffering();
|
$phar->stopBuffering();
|
||||||
@ -114,7 +114,7 @@ class DeployCommand extends BaseCommand
|
|||||||
}
|
}
|
||||||
chmod($phar_path, 0755);
|
chmod($phar_path, 0755);
|
||||||
$this->output->writeln('<info>Phar Executable: ' . $phar_path . '</info>');
|
$this->output->writeln('<info>Phar Executable: ' . $phar_path . '</info>');
|
||||||
return 0;
|
return static::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function progress(int $max = 0): ProgressBar
|
private function progress(int $max = 0): ProgressBar
|
||||||
|
|||||||
@ -24,8 +24,8 @@ class DoctorCommand extends BaseCommand
|
|||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
$this->output->writeln('<error>' . $e->getMessage() . '</error>');
|
$this->output->writeln('<error>' . $e->getMessage() . '</error>');
|
||||||
pcntl_signal(SIGINT, SIG_IGN);
|
pcntl_signal(SIGINT, SIG_IGN);
|
||||||
return 1;
|
return static::FAILURE;
|
||||||
}
|
}
|
||||||
return 0;
|
return static::SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -68,14 +68,14 @@ class DownloadCommand extends BaseCommand
|
|||||||
f_passthru('rm -rf ' . DOWNLOAD_PATH . '/*');
|
f_passthru('rm -rf ' . DOWNLOAD_PATH . '/*');
|
||||||
f_passthru('rm -rf ' . BUILD_ROOT_PATH . '/*');
|
f_passthru('rm -rf ' . BUILD_ROOT_PATH . '/*');
|
||||||
}
|
}
|
||||||
return 0;
|
return static::FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --from-zip
|
// --from-zip
|
||||||
if ($path = $this->getOption('from-zip')) {
|
if ($path = $this->getOption('from-zip')) {
|
||||||
if (!file_exists($path)) {
|
if (!file_exists($path)) {
|
||||||
logger()->critical('File ' . $path . ' not exist or not a zip archive.');
|
logger()->critical('File ' . $path . ' not exist or not a zip archive.');
|
||||||
return 1;
|
return static::FAILURE;
|
||||||
}
|
}
|
||||||
// remove old download files first
|
// remove old download files first
|
||||||
if (is_dir(DOWNLOAD_PATH)) {
|
if (is_dir(DOWNLOAD_PATH)) {
|
||||||
@ -89,7 +89,7 @@ class DownloadCommand extends BaseCommand
|
|||||||
if (PHP_OS_FAMILY !== 'Windows' && !$this->findCommand('unzip')) {
|
if (PHP_OS_FAMILY !== 'Windows' && !$this->findCommand('unzip')) {
|
||||||
logger()->critical('Missing unzip command, you need to install it first !');
|
logger()->critical('Missing unzip command, you need to install it first !');
|
||||||
logger()->critical('You can use "bin/spc doctor" command to check and install required tools');
|
logger()->critical('You can use "bin/spc doctor" command to check and install required tools');
|
||||||
return 1;
|
return static::FAILURE;
|
||||||
}
|
}
|
||||||
// create downloads
|
// create downloads
|
||||||
try {
|
try {
|
||||||
@ -103,10 +103,10 @@ class DownloadCommand extends BaseCommand
|
|||||||
}
|
}
|
||||||
} catch (RuntimeException $e) {
|
} catch (RuntimeException $e) {
|
||||||
logger()->critical('Extract failed: ' . $e->getMessage());
|
logger()->critical('Extract failed: ' . $e->getMessage());
|
||||||
return 1;
|
return static::FAILURE;
|
||||||
}
|
}
|
||||||
logger()->info('Extract success');
|
logger()->info('Extract success');
|
||||||
return 0;
|
return static::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define PHP major version
|
// Define PHP major version
|
||||||
@ -115,7 +115,7 @@ class DownloadCommand extends BaseCommand
|
|||||||
preg_match('/^\d+\.\d+$/', $ver, $matches);
|
preg_match('/^\d+\.\d+$/', $ver, $matches);
|
||||||
if (!$matches) {
|
if (!$matches) {
|
||||||
logger()->error("bad version arg: {$ver}, x.y required!");
|
logger()->error("bad version arg: {$ver}, x.y required!");
|
||||||
return 1;
|
return static::FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use shallow-clone can reduce git resource download
|
// Use shallow-clone can reduce git resource download
|
||||||
@ -175,6 +175,6 @@ class DownloadCommand extends BaseCommand
|
|||||||
// 打印拉取资源用时
|
// 打印拉取资源用时
|
||||||
$time = round(microtime(true) - START_TIME, 3);
|
$time = round(microtime(true) - START_TIME, 3);
|
||||||
logger()->info('Download complete, used ' . $time . ' s !');
|
logger()->info('Download complete, used ' . $time . ' s !');
|
||||||
return 0;
|
return static::SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,7 +50,7 @@ class DumpLicenseCommand extends BaseCommand
|
|||||||
$this->output->writeln('Dump license with libraries: ' . implode(', ', $libraries));
|
$this->output->writeln('Dump license with libraries: ' . implode(', ', $libraries));
|
||||||
$this->output->writeln('Dump license with' . ($this->getOption('without-php') ? 'out' : '') . ' php-src');
|
$this->output->writeln('Dump license with' . ($this->getOption('without-php') ? 'out' : '') . ' php-src');
|
||||||
$this->output->writeln('Dump target dir: ' . $this->getOption('dump-dir'));
|
$this->output->writeln('Dump target dir: ' . $this->getOption('dump-dir'));
|
||||||
return 0;
|
return static::SUCCESS;
|
||||||
}
|
}
|
||||||
if ($this->getOption('by-libs') !== null) {
|
if ($this->getOption('by-libs') !== null) {
|
||||||
$libraries = array_map('trim', array_filter(explode(',', $this->getOption('by-libs'))));
|
$libraries = array_map('trim', array_filter(explode(',', $this->getOption('by-libs'))));
|
||||||
@ -58,16 +58,16 @@ class DumpLicenseCommand extends BaseCommand
|
|||||||
$dumper->addLibs($libraries);
|
$dumper->addLibs($libraries);
|
||||||
$dumper->dump($this->getOption('dump-dir'));
|
$dumper->dump($this->getOption('dump-dir'));
|
||||||
$this->output->writeln('Dump target dir: ' . $this->getOption('dump-dir'));
|
$this->output->writeln('Dump target dir: ' . $this->getOption('dump-dir'));
|
||||||
return 0;
|
return static::SUCCESS;
|
||||||
}
|
}
|
||||||
if ($this->getOption('by-sources') !== null) {
|
if ($this->getOption('by-sources') !== null) {
|
||||||
$sources = array_map('trim', array_filter(explode(',', $this->getOption('by-sources'))));
|
$sources = array_map('trim', array_filter(explode(',', $this->getOption('by-sources'))));
|
||||||
$dumper->addSources($sources);
|
$dumper->addSources($sources);
|
||||||
$dumper->dump($this->getOption('dump-dir'));
|
$dumper->dump($this->getOption('dump-dir'));
|
||||||
$this->output->writeln('Dump target dir: ' . $this->getOption('dump-dir'));
|
$this->output->writeln('Dump target dir: ' . $this->getOption('dump-dir'));
|
||||||
return 0;
|
return static::SUCCESS;
|
||||||
}
|
}
|
||||||
$this->output->writeln('You must use one of "--by-extensions=", "--by-libs=", "--by-sources=" to dump');
|
$this->output->writeln('You must use one of "--by-extensions=", "--by-libs=", "--by-sources=" to dump');
|
||||||
return 1;
|
return static::FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,10 +26,10 @@ class ExtractCommand extends BaseCommand
|
|||||||
$sources = array_map('trim', array_filter(explode(',', $this->getArgument('sources'))));
|
$sources = array_map('trim', array_filter(explode(',', $this->getArgument('sources'))));
|
||||||
if (empty($sources)) {
|
if (empty($sources)) {
|
||||||
$this->output->writeln('<error>sources cannot be empty, at least contain one !</error>');
|
$this->output->writeln('<error>sources cannot be empty, at least contain one !</error>');
|
||||||
return 1;
|
return static::FAILURE;
|
||||||
}
|
}
|
||||||
SourceExtractor::initSource(sources: $sources);
|
SourceExtractor::initSource(sources: $sources);
|
||||||
logger()->info('Extract done !');
|
logger()->info('Extract done !');
|
||||||
return 0;
|
return static::SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,6 @@ class ListExtCommand extends BaseCommand
|
|||||||
foreach (Config::getExts() as $ext => $meta) {
|
foreach (Config::getExts() as $ext => $meta) {
|
||||||
echo $ext . PHP_EOL;
|
echo $ext . PHP_EOL;
|
||||||
}
|
}
|
||||||
return 0;
|
return static::SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,12 +35,12 @@ class MicroCombineCommand extends BaseCommand
|
|||||||
// 1. Make sure specified micro.sfx file exists
|
// 1. Make sure specified micro.sfx file exists
|
||||||
if ($micro_file !== null && !file_exists($micro_file)) {
|
if ($micro_file !== null && !file_exists($micro_file)) {
|
||||||
$this->output->writeln('<error>The micro.sfx file you specified is incorrect or does not exist!</error>');
|
$this->output->writeln('<error>The micro.sfx file you specified is incorrect or does not exist!</error>');
|
||||||
return 1;
|
return static::FAILURE;
|
||||||
}
|
}
|
||||||
// 2. Make sure buildroot/bin/micro.sfx exists
|
// 2. Make sure buildroot/bin/micro.sfx exists
|
||||||
if ($micro_file === null && !file_exists($internal)) {
|
if ($micro_file === null && !file_exists($internal)) {
|
||||||
$this->output->writeln('<error>You haven\'t compiled micro.sfx yet, please use "build" command and "--build-micro" to compile phpmicro first!</error>');
|
$this->output->writeln('<error>You haven\'t compiled micro.sfx yet, please use "build" command and "--build-micro" to compile phpmicro first!</error>');
|
||||||
return 1;
|
return static::FAILURE;
|
||||||
}
|
}
|
||||||
// 3. Use buildroot/bin/micro.sfx
|
// 3. Use buildroot/bin/micro.sfx
|
||||||
if ($micro_file === null) {
|
if ($micro_file === null) {
|
||||||
@ -49,19 +49,19 @@ class MicroCombineCommand extends BaseCommand
|
|||||||
// 4. Make sure php or phar file exists
|
// 4. Make sure php or phar file exists
|
||||||
if (!is_file(FileSystem::convertPath($file))) {
|
if (!is_file(FileSystem::convertPath($file))) {
|
||||||
$this->output->writeln('<error>The file to combine does not exist!</error>');
|
$this->output->writeln('<error>The file to combine does not exist!</error>');
|
||||||
return 1;
|
return static::FAILURE;
|
||||||
}
|
}
|
||||||
// 5. Confirm ini files (ini-set has higher priority)
|
// 5. Confirm ini files (ini-set has higher priority)
|
||||||
if ($ini_file !== null) {
|
if ($ini_file !== null) {
|
||||||
// Check file exist first
|
// Check file exist first
|
||||||
if (!file_exists($ini_file)) {
|
if (!file_exists($ini_file)) {
|
||||||
$this->output->writeln('<error>The ini file to combine does not exist! (' . $ini_file . ')</error>');
|
$this->output->writeln('<error>The ini file to combine does not exist! (' . $ini_file . ')</error>');
|
||||||
return 1;
|
return static::FAILURE;
|
||||||
}
|
}
|
||||||
$arr = parse_ini_file($ini_file);
|
$arr = parse_ini_file($ini_file);
|
||||||
if ($arr === false) {
|
if ($arr === false) {
|
||||||
$this->output->writeln('<error>Cannot parse ini file</error>');
|
$this->output->writeln('<error>Cannot parse ini file</error>');
|
||||||
return 1;
|
return static::FAILURE;
|
||||||
}
|
}
|
||||||
$target_ini = array_merge($target_ini, $arr);
|
$target_ini = array_merge($target_ini, $arr);
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ class MicroCombineCommand extends BaseCommand
|
|||||||
$arr = parse_ini_string($item);
|
$arr = parse_ini_string($item);
|
||||||
if ($arr === false) {
|
if ($arr === false) {
|
||||||
$this->output->writeln('<error>--with-ini-set parse failed</error>');
|
$this->output->writeln('<error>--with-ini-set parse failed</error>');
|
||||||
return 1;
|
return static::FAILURE;
|
||||||
}
|
}
|
||||||
$target_ini = array_merge($target_ini, $arr);
|
$target_ini = array_merge($target_ini, $arr);
|
||||||
}
|
}
|
||||||
@ -90,12 +90,12 @@ class MicroCombineCommand extends BaseCommand
|
|||||||
$result = file_put_contents($output, $file_target);
|
$result = file_put_contents($output, $file_target);
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
$this->output->writeln('<error>Combine failed.</error>');
|
$this->output->writeln('<error>Combine failed.</error>');
|
||||||
return 1;
|
return static::FAILURE;
|
||||||
}
|
}
|
||||||
// 9. chmod +x
|
// 9. chmod +x
|
||||||
chmod($output, 0755);
|
chmod($output, 0755);
|
||||||
$this->output->writeln('<info>Combine success! Binary file: ' . $output . '</info>');
|
$this->output->writeln('<info>Combine success! Binary file: ' . $output . '</info>');
|
||||||
return 0;
|
return static::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function encodeINI(array $array): string
|
private function encodeINI(array $array): string
|
||||||
|
|||||||
@ -52,6 +52,6 @@ class SortConfigCommand extends BaseCommand
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
$this->output->writeln('<info>sort success</info>');
|
$this->output->writeln('<info>sort success</info>');
|
||||||
return 0;
|
return static::SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,6 @@ class AllExtCommand extends BaseCommand
|
|||||||
public function handle(): int
|
public function handle(): int
|
||||||
{
|
{
|
||||||
$this->output->writeln(implode(',', array_keys(Config::getExts())));
|
$this->output->writeln(implode(',', array_keys(Config::getExts())));
|
||||||
|
return static::SUCCESS;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,7 +37,6 @@ class ExtInfoCommand extends BaseCommand
|
|||||||
}
|
}
|
||||||
$this->output->writeln('');
|
$this->output->writeln('');
|
||||||
}
|
}
|
||||||
|
return static::SUCCESS;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,9 +25,9 @@ class PhpVerCommand extends BaseCommand
|
|||||||
$result = preg_match('/#define PHP_VERSION "([^"]+)"/', file_get_contents($file), $match);
|
$result = preg_match('/#define PHP_VERSION "([^"]+)"/', file_get_contents($file), $match);
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
$this->output->writeln('<error>PHP source not found, maybe you need to extract first ?</error>');
|
$this->output->writeln('<error>PHP source not found, maybe you need to extract first ?</error>');
|
||||||
return 1;
|
return static::FAILURE;
|
||||||
}
|
}
|
||||||
$this->output->writeln('<info>' . $match[1] . '</info>');
|
$this->output->writeln('<info>' . $match[1] . '</info>');
|
||||||
return 0;
|
return static::SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user