Don't need to pass multiple arguments as a string

`./bin/console run -- --e prod --port 8001` now works without wrapping
multiple arbitrary arguments within a string.
This commit is contained in:
Oliver Davies 2024-03-12 23:59:26 +00:00
parent f94736183e
commit d289a01f3a
6 changed files with 18 additions and 15 deletions

View file

@ -23,10 +23,13 @@ abstract class AbstractCommand extends Command
// ./bin/console install -- --no-dev // ./bin/console install -- --no-dev
// //
// And to set the port and environment for a Sculpin project, multiple // And to set the port and environment for a Sculpin project, multiple
// arguments can be passed at once as a string: // arguments can be passed at once:
// //
// ./bin/console run -- '-e prod --port 8001' // ./bin/console run -- -e prod --port 8001
$this->addArgument('*'); $this->addArgument(
mode: InputArgument::IS_ARRAY,
name: '*',
);
$this->addOption( $this->addOption(
name: 'language', name: 'language',

View file

@ -78,7 +78,7 @@ final class BuildCommand extends AbstractCommand
case ProjectType::Drupal->value: case ProjectType::Drupal->value:
if ($isDockerCompose) { if ($isDockerCompose) {
$process = Process::create( $process = Process::create(
args: explode(separator: ' ', string: strval($args)), args: $args,
command: ['docker', 'compose', 'build'], command: ['docker', 'compose', 'build'],
workingDir: $workingDir, workingDir: $workingDir,
); );
@ -93,7 +93,7 @@ final class BuildCommand extends AbstractCommand
case ProjectType::Sculpin->value: case ProjectType::Sculpin->value:
$process = Process::create( $process = Process::create(
args: explode(separator: ' ', string: strval($args)), args: $args,
command: ['./vendor/bin/sculpin', 'generate'], command: ['./vendor/bin/sculpin', 'generate'],
workingDir: $workingDir, workingDir: $workingDir,
); );
@ -106,7 +106,7 @@ final class BuildCommand extends AbstractCommand
switch ($projectType) { switch ($projectType) {
case ProjectType::Fractal->value: case ProjectType::Fractal->value:
$process = Process::create( $process = Process::create(
args: explode(separator: ' ', string: strval($args)), args: $args,
command: ['npx', 'fractal', 'build'], command: ['npx', 'fractal', 'build'],
workingDir: $workingDir, workingDir: $workingDir,
); );

View file

@ -39,7 +39,7 @@ final class InstallCommand extends AbstractCommand
// TODO: Composer in Docker Compose? // TODO: Composer in Docker Compose?
$process = Process::create( $process = Process::create(
args: explode(separator: ' ', string: strval($args)), args: $args,
command: $this->getCommand(language: $language, workingDir: $workingDir), command: $this->getCommand(language: $language, workingDir: $workingDir),
workingDir: $workingDir, workingDir: $workingDir,
); );

View file

@ -21,12 +21,12 @@ final class PackageInstallCommand extends AbstractCommand
{ {
public function configure(): void public function configure(): void
{ {
parent::configure();
$this->addArgument( $this->addArgument(
name: 'package-name', name: 'package-name',
mode: InputArgument::REQUIRED, mode: InputArgument::REQUIRED,
); );
parent::configure();
} }
public function execute(InputInterface $input, OutputInterface $output): int public function execute(InputInterface $input, OutputInterface $output): int
@ -47,7 +47,7 @@ final class PackageInstallCommand extends AbstractCommand
switch ($language) { switch ($language) {
case ProjectLanguage::PHP->value: case ProjectLanguage::PHP->value:
$process = Process::create( $process = Process::create(
args: explode(separator: ' ', string: $args ?? ''), args: $args,
command: ['composer', 'require', $input->getArgument('package-name')], command: ['composer', 'require', $input->getArgument('package-name')],
workingDir: '.', workingDir: '.',
); );
@ -78,7 +78,7 @@ final class PackageInstallCommand extends AbstractCommand
} }
$process = Process::create( $process = Process::create(
args: explode(separator: ' ', string: $args ?? ''), args: $args,
command: $command, command: $command,
workingDir: $workingDir, workingDir: $workingDir,
); );

View file

@ -75,7 +75,7 @@ final class RunCommand extends AbstractCommand
if ($isDockerCompose) { if ($isDockerCompose) {
$process = Process::create( $process = Process::create(
args: explode(separator: ' ', string: $args ?? ''), args: $args,
command: ['docker', 'compose', 'up'], command: ['docker', 'compose', 'up'],
workingDir: $workingDir, workingDir: $workingDir,
); );
@ -86,7 +86,7 @@ final class RunCommand extends AbstractCommand
switch ($projectType) { switch ($projectType) {
case ProjectType::Fractal->value: case ProjectType::Fractal->value:
$process = Process::create( $process = Process::create(
args: explode(separator: ' ', string: $args ?? ''), args: $args,
command: ['npx', 'fractal', 'start', '--sync'], command: ['npx', 'fractal', 'start', '--sync'],
workingDir: $workingDir, workingDir: $workingDir,
); );
@ -97,7 +97,7 @@ final class RunCommand extends AbstractCommand
case ProjectType::Sculpin->value: case ProjectType::Sculpin->value:
$process = Process::create( $process = Process::create(
args: explode(separator: ' ', string: $args ?? ''), args: $args,
command: ['./vendor/bin/sculpin', 'generate', '--server', '--watch'], command: ['./vendor/bin/sculpin', 'generate', '--server', '--watch'],
workingDir: $workingDir, workingDir: $workingDir,
); );

View file

@ -38,7 +38,7 @@ final class TestCommand extends AbstractCommand
// TODO: commands in Docker Compose? // TODO: commands in Docker Compose?
$process = Process::create( $process = Process::create(
args: explode(separator: ' ', string: $args), args: $args,
command: $command, command: $command,
workingDir: $workingDir, workingDir: $workingDir,
); );