modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-09-26 12:20:17 +04:00
parent 4bb386167f
commit b195888602
7 changed files with 26 additions and 24 deletions

View File

@ -65,7 +65,6 @@
},
"bin": [
"lib/_launch.php",
"bin/bg-launcher.php",
"nur_bin/compctl.php",
"nur_bin/compdep.php",
"nur_bin/cachectl.php",

View File

@ -21,7 +21,7 @@ class ExitError extends Error {
/** @var ?string */
protected $userMessage;
function haveMessage(): bool {
function haveUserMessage(): bool {
return $this->userMessage !== null;
}

View File

@ -1,5 +1,5 @@
<?php
namespace nur\sery\php\json;
namespace nur\sery\ext\json;
use RuntimeException;

27
bin/bg-launcher.php → src/tools/BgLauncherApp.php Executable file → Normal file
View File

@ -1,21 +1,21 @@
#!/usr/bin/php
<?php
require $_composer_autoload_path?? __DIR__.'/../vendor/autoload.php';
namespace nur\sery\tools;
use nur\sery\output\msg;
use nur\sery\wip\app\app2;
use nur\sery\wip\app\cli\Application;
use nur\sery\wip\app\cli\bg_launcher;
use nur\yaml;
class BgLauncherApp extends Application {
const PROJDIR = __DIR__.'/../..';
const ACTION_INFOS = 0, ACTION_START = 1, ACTION_STOP = 2;
const ARGS = [
"purpose" => "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();

View File

@ -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;
#############################################################################

View File

@ -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);
}
}

View File

@ -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;