Improved runtime and script classes
This commit is contained in:
@ -22,14 +22,21 @@ class RunCommand extends Command
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$env = $this->getEnvironment();
|
||||
$args = $input->getArgument('args');
|
||||
|
||||
if ($input->getOption("list")) {
|
||||
$output->writeln($env->getDefinedScripts());
|
||||
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')) {
|
||||
$env->runScript($script, $input->getArgument('args'), $input, $output);
|
||||
$env->runScript($script, $args, $input, $output);
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,9 +38,26 @@ class Environment
|
||||
|
||||
public function runScript(string $name, array $args, InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$script = $this->config['scripts'][$name];
|
||||
$script = $this->config['scripts'][$name]??$name;
|
||||
|
||||
if (is_string($script)) {
|
||||
$this->execScript($script, $args);
|
||||
} elseif (is_array($script)) {
|
||||
foreach ($script as $row) {
|
||||
$a = str_getcsv($row, ' ', "'");
|
||||
$c = array_shift($a);
|
||||
if (str_starts_with($c, '@')) {
|
||||
$c = ($this->config['scripts'][substr($c,1)])??$c;
|
||||
$this->runScript($c, $a, $input, $output);
|
||||
} else {
|
||||
$this->execScript($c, $a);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function execScript(string $script, array $args)
|
||||
{
|
||||
// call script directly
|
||||
if (str_ends_with($script, '.php')) {
|
||||
$GLOBALS['args'] = $args;
|
||||
@ -50,11 +67,12 @@ class Environment
|
||||
fprintf(STDERR, "error: Could not find script file %s\n", $base."/".$script);
|
||||
return;
|
||||
}
|
||||
//echo "# ".$base."/".$script."\n";
|
||||
include $base . "/" . $script;
|
||||
} else {
|
||||
//echo "$ {$script}\n";
|
||||
passthru($script);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function loadEnvironment()
|
||||
|
Reference in New Issue
Block a user