modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-06-16 13:31:11 +04:00
parent 7f378c6b8f
commit 57a8ce0ca8
2 changed files with 44 additions and 0 deletions

View File

@ -1,13 +1,43 @@
<?php <?php
namespace nur\sery\app; namespace nur\sery\app;
use nur\sery\cl;
use nur\sery\file\TmpfileWriter; use nur\sery\file\TmpfileWriter;
use nur\sery\os\proc\Cmd; use nur\sery\os\proc\Cmd;
use nur\sery\output\msg; use nur\sery\output\msg;
use nur\sery\StateException; use nur\sery\StateException;
use nur\sery\str;
use nur\sery\wip\app\app; use nur\sery\wip\app\app;
class launcher { class launcher {
/**
* transformer une liste d'argument de la forme
* - ["myArg" => $value] devient ["--my-arg", "$value"]
* - ["myOpt" => true] devient ["--my-opt"]
* - ["myOpt" => false] est momis
* - les valeurs séquentielles sont prises telles quelles
*/
static function verifix_args(array $args): array {
if (cl::is_list($args)) return $args;
$fixedArgs = [];
$index = 0;
foreach ($args as $arg => $value) {
if ($arg === $index) {
$index++;
$fixedArgs[] = $value;
continue;
} elseif ($value === false) {
continue;
}
$arg = str::us2camel($arg);
$arg = str::camel2us($arg, false, "-");
$arg = str_replace("_", "-", $arg);
$fixedArgs[] = "--$arg";
if ($value !== true) $fixedArgs[] = "$value";
}
return $fixedArgs;
}
static function launch(string $appClass, array $args): int { static function launch(string $appClass, array $args): int {
$app = app::get(); $app = app::get();
$vendorBindir = $app->getVendorbindir(); $vendorBindir = $app->getVendorbindir();
@ -18,6 +48,7 @@ class launcher {
$tmpfile = new TmpfileWriter(); $tmpfile = new TmpfileWriter();
$tmpfile->serialize($app->getParams()); $tmpfile->serialize($app->getParams());
$args = self::verifix_args($args);
$cmd = new Cmd([ $cmd = new Cmd([
$launch_php, $launch_php,
"--internal-use", $tmpfile->getFile(), "--internal-use", $tmpfile->getFile(),

View File

@ -4,4 +4,17 @@ namespace nur\sery\app;
use nulib\tests\TestCase; use nulib\tests\TestCase;
class launcherTest extends TestCase { class launcherTest extends TestCase {
function testVerifix_args() {
self::assertSame([], launcher::verifix_args([]));
self::assertSame(["a"], launcher::verifix_args(["a"]));
self::assertSame(["a", "--b"], launcher::verifix_args(["a", "--b"]));
self::assertSame([], launcher::verifix_args(["a" => false]));
self::assertSame(["--a"], launcher::verifix_args(["a" => true]));
self::assertSame(["--a", "value"], launcher::verifix_args(["a" => "value"]));
self::assertSame(["--a", "52"], launcher::verifix_args(["a" => 52]));
self::assertSame(["--aa-bb", "value"], launcher::verifix_args(["aaBb" => "value"]));
self::assertSame(["--aa-bb", "value"], launcher::verifix_args(["aa-Bb" => "value"]));
self::assertSame(["--aa-bb", "value"], launcher::verifix_args(["aa_Bb" => "value"]));
self::assertSame(["---aa-bb", "value"], launcher::verifix_args(["_aa_Bb" => "value"]));
}
} }