35 lines
1.2 KiB
PHP
35 lines
1.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Spark\Commands;
|
||
|
|
|
||
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||
|
|
use Spark\Commands\Command;
|
||
|
|
use Symfony\Component\Console\Input\InputArgument;
|
||
|
|
use Symfony\Component\Console\Input\InputInterface;
|
||
|
|
use Symfony\Component\Console\Input\InputOption;
|
||
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
||
|
|
|
||
|
|
#[AsCommand(name:'run', description:'Run a script')]
|
||
|
|
class RunCommand extends Command
|
||
|
|
{
|
||
|
|
protected function configure()
|
||
|
|
{
|
||
|
|
$this->addOption("list", null, InputOption::VALUE_NONE, "List the available scripts");
|
||
|
|
$this->addArgument("script", InputArgument::OPTIONAL, "The script too run (see --list)");
|
||
|
|
$this->addArgument("args", InputArgument::OPTIONAL|InputArgument::IS_ARRAY, "Arguments to the script");
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||
|
|
{
|
||
|
|
$env = $this->getEnvironment();
|
||
|
|
|
||
|
|
if ($input->getOption("list")) {
|
||
|
|
$output->writeln($env->getDefinedScripts());
|
||
|
|
return Command::SUCCESS;
|
||
|
|
} elseif ($script = $input->getArgument('script')) {
|
||
|
|
$env->runScript($script, $input->getArgument('args'), $input, $output);
|
||
|
|
}
|
||
|
|
|
||
|
|
return Command::SUCCESS;
|
||
|
|
}
|
||
|
|
}
|