diff --git a/src/app/launcher.php b/src/app/launcher.php index 81b0b93..fb2a017 100644 --- a/src/app/launcher.php +++ b/src/app/launcher.php @@ -1,13 +1,43 @@ $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 { $app = app::get(); $vendorBindir = $app->getVendorbindir(); @@ -18,6 +48,7 @@ class launcher { $tmpfile = new TmpfileWriter(); $tmpfile->serialize($app->getParams()); + $args = self::verifix_args($args); $cmd = new Cmd([ $launch_php, "--internal-use", $tmpfile->getFile(), diff --git a/tests/app/launcherTest.php b/tests/app/launcherTest.php index a8274ac..d6d9efe 100644 --- a/tests/app/launcherTest.php +++ b/tests/app/launcherTest.php @@ -4,4 +4,17 @@ namespace nur\sery\app; use nulib\tests\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"])); + } }