modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-06-17 17:44:43 +04:00
parent 1282dc6365
commit 60c9c4a2fb
3 changed files with 29 additions and 17 deletions

View File

@ -11,6 +11,7 @@ $argv = array_merge(
); );
$app_params = unserialize(file_get_contents($paramsfile)); $app_params = unserialize(file_get_contents($paramsfile));
@unlink($paramsfile);
require $app_params["vendor"]["autoload"]; require $app_params["vendor"]["autoload"];
use nur\cli\Application; use nur\cli\Application;

View File

@ -3,6 +3,7 @@ namespace nur\sery\app;
use nur\sery\cl; use nur\sery\cl;
use nur\sery\file\TmpfileWriter; use nur\sery\file\TmpfileWriter;
use nur\sery\os\path;
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;
@ -18,24 +19,28 @@ class launcher {
* - les valeurs séquentielles sont prises telles quelles * - les valeurs séquentielles sont prises telles quelles
*/ */
static function verifix_args(array $args): array { static function verifix_args(array $args): array {
if (cl::is_list($args)) return $args; if (!cl::is_list($args)) {
$fixedArgs = []; $fixedArgs = [];
$index = 0; $index = 0;
foreach ($args as $arg => $value) { foreach ($args as $arg => $value) {
if ($arg === $index) { if ($arg === $index) {
$index++; $index++;
$fixedArgs[] = $value; $fixedArgs[] = $value;
continue; continue;
} elseif ($value === false) { } elseif ($value === false) {
continue; continue;
}
$arg = str::us2camel($arg);
$arg = str::camel2us($arg, false, "-");
$arg = str_replace("_", "-", $arg);
$fixedArgs[] = "--$arg";
if ($value !== true) $fixedArgs[] = "$value";
} }
$arg = str::us2camel($arg); $args = $fixedArgs;
$arg = str::camel2us($arg, false, "-");
$arg = str_replace("_", "-", $arg);
$fixedArgs[] = "--$arg";
if ($value !== true) $fixedArgs[] = "$value";
} }
return $fixedArgs; # corriger le chemin de l'application pour qu'il soit absolu et normalisé
$args[0] = path::abspath($args[0]);
return $args;
} }
static function launch(string $appClass, array $args): int { static function launch(string $appClass, array $args): int {
@ -46,7 +51,7 @@ class launcher {
$launch_php = __DIR__."/../../lib/_launch.php"; $launch_php = __DIR__."/../../lib/_launch.php";
} }
$tmpfile = new TmpfileWriter(); $tmpfile = new TmpfileWriter();
$tmpfile->serialize($app->getParams()); $tmpfile->keep()->serialize($app->getParams());
$args = self::verifix_args($args); $args = self::verifix_args($args);
$cmd = new Cmd([ $cmd = new Cmd([

View File

@ -39,6 +39,12 @@ class TmpfileWriter extends FileWriter {
/** @var bool */ /** @var bool */
protected $delete; protected $delete;
/** désactiver la suppression automatique du fichier temporaire */
function keep(): self {
$this->delete = false;
return $this;
}
function __destruct() { function __destruct() {
$this->close(); $this->close();
if ($this->delete) $this->delete(); if ($this->delete) $this->delete();