mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 04:44:53 +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
|
||||
{
|
||||
public const VERSION = '2.0-rc4';
|
||||
public const VERSION = '2.0-rc5';
|
||||
|
||||
/**
|
||||
* @throws \ReflectionException
|
||||
|
||||
@ -91,7 +91,7 @@ abstract class BaseCommand extends Command
|
||||
foreach ($msg as $v) {
|
||||
logger()->error($v);
|
||||
}
|
||||
return self::FAILURE;
|
||||
return static::FAILURE;
|
||||
} catch (\Throwable $e) {
|
||||
// 不开 debug 模式就不要再显示复杂的调试栈信息了
|
||||
if ($this->getOption('debug')) {
|
||||
@ -102,10 +102,10 @@ abstract class BaseCommand extends Command
|
||||
logger()->error($v);
|
||||
}
|
||||
}
|
||||
return self::FAILURE;
|
||||
return static::FAILURE;
|
||||
}
|
||||
}
|
||||
return self::SUCCESS;
|
||||
return static::SUCCESS;
|
||||
}
|
||||
|
||||
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-fpm\tBuild php-fpm SAPI</comment>");
|
||||
$this->output->writeln("<comment>\t--build-all\tBuild all SAPI: cli, micro, fpm</comment>");
|
||||
return 1;
|
||||
return static::FAILURE;
|
||||
}
|
||||
try {
|
||||
// 构建对象
|
||||
@ -113,10 +113,10 @@ class BuildCliCommand extends BuildCommand
|
||||
$dumper = new LicenseDumper();
|
||||
$dumper->addExts($extensions)->addLibs($libraries)->addSources(['php-src'])->dump(BUILD_ROOT_PATH . '/license');
|
||||
logger()->info('License path' . $fixed . ': ' . $build_root_path . '/license/');
|
||||
return 0;
|
||||
return static::SUCCESS;
|
||||
} catch (WrongUsageException $e) {
|
||||
logger()->critical($e->getMessage());
|
||||
return 1;
|
||||
return static::FAILURE;
|
||||
} catch (\Throwable $e) {
|
||||
if ($this->getOption('debug')) {
|
||||
ExceptionHandler::getInstance()->handle($e);
|
||||
@ -124,7 +124,7 @@ class BuildCliCommand extends BuildCommand
|
||||
logger()->critical('Build failed with ' . get_class($e) . ': ' . $e->getMessage());
|
||||
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);
|
||||
logger()->info('Build libs complete, used ' . $time . ' s !');
|
||||
return 0;
|
||||
return static::SUCCESS;
|
||||
} catch (\Throwable $e) {
|
||||
if ($this->getOption('debug')) {
|
||||
ExceptionHandler::getInstance()->handle($e);
|
||||
@ -71,7 +71,7 @@ class BuildLibsCommand extends BuildCommand
|
||||
logger()->critical('Build failed with ' . get_class($e) . ': ' . $e->getMessage());
|
||||
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');
|
||||
if (!$ask) {
|
||||
$this->output->writeln('<comment>User canceled.</comment>');
|
||||
return 1;
|
||||
return static::FAILURE;
|
||||
}
|
||||
@unlink($phar_path);
|
||||
}
|
||||
@ -97,7 +97,7 @@ class DeployCommand extends BaseCommand
|
||||
$phar->setStub($phar->createDefaultStub($stub));
|
||||
} catch (\Throwable $e) {
|
||||
$this->output->writeln($e);
|
||||
return 1;
|
||||
return static::FAILURE;
|
||||
}
|
||||
$phar->addFromString('.prod', 'true');
|
||||
$phar->stopBuffering();
|
||||
@ -114,7 +114,7 @@ class DeployCommand extends BaseCommand
|
||||
}
|
||||
chmod($phar_path, 0755);
|
||||
$this->output->writeln('<info>Phar Executable: ' . $phar_path . '</info>');
|
||||
return 0;
|
||||
return static::SUCCESS;
|
||||
}
|
||||
|
||||
private function progress(int $max = 0): ProgressBar
|
||||
|
||||
@ -24,8 +24,8 @@ class DoctorCommand extends BaseCommand
|
||||
} catch (\Throwable $e) {
|
||||
$this->output->writeln('<error>' . $e->getMessage() . '</error>');
|
||||
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 ' . BUILD_ROOT_PATH . '/*');
|
||||
}
|
||||
return 0;
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
// --from-zip
|
||||
if ($path = $this->getOption('from-zip')) {
|
||||
if (!file_exists($path)) {
|
||||
logger()->critical('File ' . $path . ' not exist or not a zip archive.');
|
||||
return 1;
|
||||
return static::FAILURE;
|
||||
}
|
||||
// remove old download files first
|
||||
if (is_dir(DOWNLOAD_PATH)) {
|
||||
@ -89,7 +89,7 @@ class DownloadCommand extends BaseCommand
|
||||
if (PHP_OS_FAMILY !== 'Windows' && !$this->findCommand('unzip')) {
|
||||
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');
|
||||
return 1;
|
||||
return static::FAILURE;
|
||||
}
|
||||
// create downloads
|
||||
try {
|
||||
@ -103,10 +103,10 @@ class DownloadCommand extends BaseCommand
|
||||
}
|
||||
} catch (RuntimeException $e) {
|
||||
logger()->critical('Extract failed: ' . $e->getMessage());
|
||||
return 1;
|
||||
return static::FAILURE;
|
||||
}
|
||||
logger()->info('Extract success');
|
||||
return 0;
|
||||
return static::SUCCESS;
|
||||
}
|
||||
|
||||
// Define PHP major version
|
||||
@ -115,7 +115,7 @@ class DownloadCommand extends BaseCommand
|
||||
preg_match('/^\d+\.\d+$/', $ver, $matches);
|
||||
if (!$matches) {
|
||||
logger()->error("bad version arg: {$ver}, x.y required!");
|
||||
return 1;
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
// Use shallow-clone can reduce git resource download
|
||||
@ -175,6 +175,6 @@ class DownloadCommand extends BaseCommand
|
||||
// 打印拉取资源用时
|
||||
$time = round(microtime(true) - START_TIME, 3);
|
||||
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' . ($this->getOption('without-php') ? 'out' : '') . ' php-src');
|
||||
$this->output->writeln('Dump target dir: ' . $this->getOption('dump-dir'));
|
||||
return 0;
|
||||
return static::SUCCESS;
|
||||
}
|
||||
if ($this->getOption('by-libs') !== null) {
|
||||
$libraries = array_map('trim', array_filter(explode(',', $this->getOption('by-libs'))));
|
||||
@ -58,16 +58,16 @@ class DumpLicenseCommand extends BaseCommand
|
||||
$dumper->addLibs($libraries);
|
||||
$dumper->dump($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) {
|
||||
$sources = array_map('trim', array_filter(explode(',', $this->getOption('by-sources'))));
|
||||
$dumper->addSources($sources);
|
||||
$dumper->dump($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');
|
||||
return 1;
|
||||
return static::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,10 +26,10 @@ class ExtractCommand extends BaseCommand
|
||||
$sources = array_map('trim', array_filter(explode(',', $this->getArgument('sources'))));
|
||||
if (empty($sources)) {
|
||||
$this->output->writeln('<error>sources cannot be empty, at least contain one !</error>');
|
||||
return 1;
|
||||
return static::FAILURE;
|
||||
}
|
||||
SourceExtractor::initSource(sources: $sources);
|
||||
logger()->info('Extract done !');
|
||||
return 0;
|
||||
return static::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,6 @@ class ListExtCommand extends BaseCommand
|
||||
foreach (Config::getExts() as $ext => $meta) {
|
||||
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
|
||||
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>');
|
||||
return 1;
|
||||
return static::FAILURE;
|
||||
}
|
||||
// 2. Make sure buildroot/bin/micro.sfx exists
|
||||
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>');
|
||||
return 1;
|
||||
return static::FAILURE;
|
||||
}
|
||||
// 3. Use buildroot/bin/micro.sfx
|
||||
if ($micro_file === null) {
|
||||
@ -49,19 +49,19 @@ class MicroCombineCommand extends BaseCommand
|
||||
// 4. Make sure php or phar file exists
|
||||
if (!is_file(FileSystem::convertPath($file))) {
|
||||
$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)
|
||||
if ($ini_file !== null) {
|
||||
// Check file exist first
|
||||
if (!file_exists($ini_file)) {
|
||||
$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);
|
||||
if ($arr === false) {
|
||||
$this->output->writeln('<error>Cannot parse ini file</error>');
|
||||
return 1;
|
||||
return static::FAILURE;
|
||||
}
|
||||
$target_ini = array_merge($target_ini, $arr);
|
||||
}
|
||||
@ -71,7 +71,7 @@ class MicroCombineCommand extends BaseCommand
|
||||
$arr = parse_ini_string($item);
|
||||
if ($arr === false) {
|
||||
$this->output->writeln('<error>--with-ini-set parse failed</error>');
|
||||
return 1;
|
||||
return static::FAILURE;
|
||||
}
|
||||
$target_ini = array_merge($target_ini, $arr);
|
||||
}
|
||||
@ -90,12 +90,12 @@ class MicroCombineCommand extends BaseCommand
|
||||
$result = file_put_contents($output, $file_target);
|
||||
if ($result === false) {
|
||||
$this->output->writeln('<error>Combine failed.</error>');
|
||||
return 1;
|
||||
return static::FAILURE;
|
||||
}
|
||||
// 9. chmod +x
|
||||
chmod($output, 0755);
|
||||
$this->output->writeln('<info>Combine success! Binary file: ' . $output . '</info>');
|
||||
return 0;
|
||||
return static::SUCCESS;
|
||||
}
|
||||
|
||||
private function encodeINI(array $array): string
|
||||
|
||||
@ -52,6 +52,6 @@ class SortConfigCommand extends BaseCommand
|
||||
return 1;
|
||||
}
|
||||
$this->output->writeln('<info>sort success</info>');
|
||||
return 0;
|
||||
return static::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,7 +18,6 @@ class AllExtCommand extends BaseCommand
|
||||
public function handle(): int
|
||||
{
|
||||
$this->output->writeln(implode(',', array_keys(Config::getExts())));
|
||||
|
||||
return 0;
|
||||
return static::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,7 +37,6 @@ class ExtInfoCommand extends BaseCommand
|
||||
}
|
||||
$this->output->writeln('');
|
||||
}
|
||||
|
||||
return 0;
|
||||
return static::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,9 +25,9 @@ class PhpVerCommand extends BaseCommand
|
||||
$result = preg_match('/#define PHP_VERSION "([^"]+)"/', file_get_contents($file), $match);
|
||||
if ($result === false) {
|
||||
$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>');
|
||||
return 0;
|
||||
return static::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user