mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 04:44:53 +08:00
Unified option to parameter conversion
This commit is contained in:
parent
aae6c2c98b
commit
c551efb75c
@ -79,20 +79,7 @@ class CraftCommand extends BaseCommand
|
|||||||
$craft['download-options']['ignore-cache-sources'] .= ',php-src';
|
$craft['download-options']['ignore-cache-sources'] .= ',php-src';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$download_options = $craft['download-options'];
|
$this->optionsToArguments($craft['download-options'], $args);
|
||||||
foreach ($download_options as $option => $val) {
|
|
||||||
if (is_bool($val) && $val || is_null($val)) {
|
|
||||||
$args[] = "--{$option}";
|
|
||||||
} elseif (is_string($val)) {
|
|
||||||
$args[] = "--{$option}={$val}";
|
|
||||||
} elseif (is_array($val)) {
|
|
||||||
foreach ($val as $v) {
|
|
||||||
if (is_string($v)) {
|
|
||||||
$args[] = "--{$option}={$v}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$retcode = $this->runCommand('download', ...$args);
|
$retcode = $this->runCommand('download', ...$args);
|
||||||
if ($retcode !== 0) {
|
if ($retcode !== 0) {
|
||||||
$this->output->writeln('<error>craft download failed</error>');
|
$this->output->writeln('<error>craft download failed</error>');
|
||||||
@ -104,6 +91,7 @@ class CraftCommand extends BaseCommand
|
|||||||
// craft build
|
// craft build
|
||||||
if ($craft['craft-options']['build']) {
|
if ($craft['craft-options']['build']) {
|
||||||
$args = [$extensions, "--with-libs={$libs}", ...array_map(fn ($x) => "--build-{$x}", $craft['sapi'])];
|
$args = [$extensions, "--with-libs={$libs}", ...array_map(fn ($x) => "--build-{$x}", $craft['sapi'])];
|
||||||
|
$this->optionsToArguments($craft['build-options'], $args);
|
||||||
$retcode = $this->runCommand('build', ...$args);
|
$retcode = $this->runCommand('build', ...$args);
|
||||||
if ($retcode !== 0) {
|
if ($retcode !== 0) {
|
||||||
$this->output->writeln('<error>craft build failed</error>');
|
$this->output->writeln('<error>craft build failed</error>');
|
||||||
@ -164,4 +152,27 @@ class CraftCommand extends BaseCommand
|
|||||||
$process->run([$this, 'processLogCallback']);
|
$process->run([$this, 'processLogCallback']);
|
||||||
return $process->getExitCode();
|
return $process->getExitCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function optionsToArguments(array $options, array &$args): void
|
||||||
|
{
|
||||||
|
foreach ($options as $option => $val) {
|
||||||
|
if ((is_bool($val) && $val) || $val === null) {
|
||||||
|
$args[] = "--{$option}";
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (is_string($val)) {
|
||||||
|
$args[] = "--{$option}={$val}";
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (is_array($val)) {
|
||||||
|
foreach ($val as $v) {
|
||||||
|
if (is_string($v)) {
|
||||||
|
$args[] = "--{$option}={$v}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user