45 lines
1.6 KiB
PHP
45 lines
1.6 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();
|
|
$args = $input->getArgument('args');
|
|
|
|
if ($input->getOption("list") || empty($input->getArgument("script"))) {
|
|
$scripts = $env->getDefinedScripts();
|
|
if (count($scripts) > 0) {
|
|
$output->writeln("<options=bold>Defined scripts:</>");
|
|
$output->writeln("- ".join("\n- ",$scripts));
|
|
} else {
|
|
$output->writeln("No scripts defined.");
|
|
}
|
|
return Command::SUCCESS;
|
|
} elseif ($script = $input->getArgument('script')) {
|
|
$runner = $env->getScriptRunner();
|
|
//$env->runScript($script, $args, $input, $output);
|
|
$runner->evaluateDefinedScript($script); // args?
|
|
}
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|