nur-sery/lib/launch.php

60 lines
1.6 KiB
PHP
Raw Normal View History

2024-06-13 07:28:11 +04:00
#!/usr/bin/php
<?php
require $_composer_autoload_path?? __DIR__.'/../vendor/autoload.php';
use nur\cli\Application;
use nur\sery\wip\app\app;
2024-06-13 07:32:06 +04:00
use nur\sery\app\launcher;
2024-06-13 07:28:11 +04:00
use nur\yaml;
Application::run(new class extends Application {
const ACTION_INFOS = 0, ACTION_START = 1, ACTION_STOP = 2;
const ARGS = [
"merge" => parent::ARGS,
"purpose" => "lancer une tâche de fond",
"usage" => "ApplicationClass args...",
["-s", "--start", "name" => "action", "value" => self::ACTION_START,
"help" => "démarrer la tâche, c'est la valeur par défaut"
],
["-k", "--stop", "name" => "action", "value" => self::ACTION_STOP,
"help" => "arrêter la tâche"
],
["-i", "--infos", "name" => "action", "value" => self::ACTION_INFOS,
"help" => "afficher des informations sur la tâche"
],
];
protected $action = self::ACTION_START;
protected $args;
function main() {
$appClass = $this->args[0] ?? null;
if ($appClass === null) {
self::die("Vous devez spécifier la classe de l'application");
}
$args = array_slice($this->args, 1);
$useRunfile = constant("$appClass::USE_RUNFILE");
if (!$useRunfile) {
self::die("Cette application ne supporte pas l'usage de runfile");
}
$app = app::with($appClass);
$runfile = $app->getRunfile();
switch ($this->action) {
case self::ACTION_START:
launcher::_start($args, $runfile);
break;
case self::ACTION_STOP:
launcher::_stop($runfile);
break;
case self::ACTION_INFOS:
yaml::dump($runfile->read());
break;
}
}
});