From b195888602b9d2a8677a0fb89e1a566157080ae2 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Thu, 26 Sep 2024 12:20:17 +0400 Subject: [PATCH] modifs.mineures sans commentaires --- composer.json | 1 - src/ExitError.php | 2 +- src/{php => ext}/json/JsonException.php | 2 +- .../tools/BgLauncherApp.php | 27 ++++++++++--------- wip/app/app2.php | 2 +- wip/app/cli/Application.php | 15 ++++++----- wip/app/cli/bg_launcher.php | 1 - 7 files changed, 26 insertions(+), 24 deletions(-) rename src/{php => ext}/json/JsonException.php (95%) rename bin/bg-launcher.php => src/tools/BgLauncherApp.php (79%) mode change 100755 => 100644 diff --git a/composer.json b/composer.json index 6b029ff..b7690fd 100644 --- a/composer.json +++ b/composer.json @@ -65,7 +65,6 @@ }, "bin": [ "lib/_launch.php", - "bin/bg-launcher.php", "nur_bin/compctl.php", "nur_bin/compdep.php", "nur_bin/cachectl.php", diff --git a/src/ExitError.php b/src/ExitError.php index 263ceb2..69746fe 100644 --- a/src/ExitError.php +++ b/src/ExitError.php @@ -21,7 +21,7 @@ class ExitError extends Error { /** @var ?string */ protected $userMessage; - function haveMessage(): bool { + function haveUserMessage(): bool { return $this->userMessage !== null; } diff --git a/src/php/json/JsonException.php b/src/ext/json/JsonException.php similarity index 95% rename from src/php/json/JsonException.php rename to src/ext/json/JsonException.php index de6f0b1..8938a50 100644 --- a/src/php/json/JsonException.php +++ b/src/ext/json/JsonException.php @@ -1,5 +1,5 @@ "lancer un script en tâche de fond", "usage" => "ApplicationClass args...", + "sections" => [ + parent::VERBOSITY_SECTION, + ], + ["-i", "--infos", "name" => "action", "value" => self::ACTION_INFOS, "help" => "Afficher des informations sur la tâche", ], @@ -32,15 +32,16 @@ class BgLauncherApp extends Application { protected ?array $args = null; function main() { - $appClass = $this->args[0] ?? null; + $args = $this->args; + + $appClass = $args[0] ?? null; if ($appClass === null) { self::die("Vous devez spécifier la classe de l'application"); } - $appClass = str_replace("/", "\\", $appClass); + $appClass = $args[0] = str_replace("/", "\\", $appClass); if (!class_exists($appClass)) { self::die("$appClass: classe non trouvée"); } - $args = array_slice($this->args, 1); $useRunfile = constant("$appClass::USE_RUNFILE"); if (!$useRunfile) { @@ -50,6 +51,12 @@ class BgLauncherApp extends Application { $runfile = app2::with($appClass)->getRunfile(); switch ($this->action) { case self::ACTION_START: + $appClass::_manage_runfile(count($args), $args, $runfile); + array_splice($args, 0, 0, [ + PHP_BINARY, + NULIB_APP_app_launcher, + ]); + app2::params_putenv(); bg_launcher::_start($args, $runfile); break; case self::ACTION_STOP: @@ -61,7 +68,3 @@ class BgLauncherApp extends Application { } } } - -$params = app2::params_getenv(); -if ($params !== null) app2::init($params); -BgLauncherApp::run(); diff --git a/wip/app/app2.php b/wip/app/app2.php index cbe4984..8a49a88 100644 --- a/wip/app/app2.php +++ b/wip/app/app2.php @@ -482,7 +482,7 @@ class app2 { const EC_DISABLED = 251; const EC_LOCKED = 252; const EC_BAD_COMMAND = 253; - const EC_EXCEPTION = 254; + const EC_UNEXPECTED = 254; const EC_SIGNAL = 255; ############################################################################# diff --git a/wip/app/cli/Application.php b/wip/app/cli/Application.php index 4113412..e066d39 100644 --- a/wip/app/cli/Application.php +++ b/wip/app/cli/Application.php @@ -13,6 +13,7 @@ use nur\sery\output\std\StdMessenger; use nur\sery\ValueException; use nur\sery\wip\app\app2; use nur\sery\wip\app\RunFile; +use nur\sery\wip\web\content\v; /** * Class Application: application de base @@ -81,10 +82,9 @@ abstract class Application { /** @var bool faut-il installer le gestionnaire de signaux? */ const USE_SIGNAL_HANDLER = false; - static function _manage_runfile(RunFile $runfile): void { - global $argc, $argv; + static function _manage_runfile(int $argc, array $argv, RunFile $runfile): void { if ($argc <= 1 || $argv[1] !== "//") return; - array_splice($argv, 1, 1); $argc--; + array_splice($argv, 1, 1); $ec = 0; switch ($argv[1] ?? "infos") { case "release-lock": @@ -104,7 +104,7 @@ abstract class Application { } break; default: - fwrite(STDERR, "$argv[2]: unexpected command\n"); + fwrite(STDERR, "$argv[1]: unexpected command\n"); $ec = app2::EC_BAD_COMMAND; } exit($ec); @@ -131,7 +131,8 @@ abstract class Application { if ($useRunfile) { $runfile = app2::get()->getRunfile(); - self::_manage_runfile($runfile); + global $argc, $argv; + self::_manage_runfile($argc, $argv, $runfile); if ($useRunlock && $runfile->warnIfLocked()) exit(app2::EC_LOCKED); $runfile->wfStart(); @@ -145,11 +146,11 @@ abstract class Application { static::_configure_app($app); static::_start_app($app); } catch (ExitError $e) { - if ($e->haveMessage()) msg::error($e); + if ($e->haveUserMessage()) msg::error($e->getUserMessage()); exit($e->getCode()); } catch (Exception $e) { msg::error($e); - exit(app2::EC_EXCEPTION); + exit(app2::EC_UNEXPECTED); } } diff --git a/wip/app/cli/bg_launcher.php b/wip/app/cli/bg_launcher.php index 98b2bfa..a5c9861 100644 --- a/wip/app/cli/bg_launcher.php +++ b/wip/app/cli/bg_launcher.php @@ -6,7 +6,6 @@ use nur\sery\file\TmpfileWriter; use nur\sery\os\path; use nur\sery\os\proc\Cmd; use nur\sery\output\msg; -use nur\sery\StateException; use nur\sery\wip\app\app2; use nur\sery\wip\app\args; use nur\sery\wip\app\RunFile;