diff --git a/composer.json b/composer.json index 5e41ee2..b7f88ac 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,7 @@ "symfony/finder": "^6.0", "symfony/process": "^6.0", "psr/log": "^3.0", - "symfony/var-dumper": "^6.0" + "symfony/var-dumper": "^6.0", + "symfony/yaml": "^6.0" } } diff --git a/runtime/SparkPlug.php b/runtime/SparkPlug.php index 1f0fb83..4da3222 100644 --- a/runtime/SparkPlug.php +++ b/runtime/SparkPlug.php @@ -11,11 +11,13 @@ abstract class SparkPlug return SparkApplication::$instance->getPluginManager()->getPlugin($name); } - function get_resource(string $name) { + function getResource(string $name) + { return SparkApplication::$instance->getResourceManager()->getNamedResource($name); } - function read_config($file=null) { + function readConfig($file=null) + { if (!$file) return; $abs = get_environment()->getConfigDirectory() . "/" . $file; if (!file_exists($abs)) { @@ -29,5 +31,6 @@ abstract class SparkPlug { return SparkApplication::$instance->getEnvironment()->getProjectDirectory(); } + } \ No newline at end of file diff --git a/src/Commands/RunCommand.php b/src/Commands/RunCommand.php index f9de0b7..ff9d82c 100644 --- a/src/Commands/RunCommand.php +++ b/src/Commands/RunCommand.php @@ -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("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; } -} \ No newline at end of file +} diff --git a/src/Environment/Environment.php b/src/Environment/Environment.php index 0c1ad48..9b19424 100644 --- a/src/Environment/Environment.php +++ b/src/Environment/Environment.php @@ -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()