modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-09-30 08:30:29 +04:00
parent 2a20032b02
commit bbec334f44
4 changed files with 38 additions and 5 deletions

View File

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

35
src/ext/yaml.php Normal file
View File

@ -0,0 +1,35 @@
<?php
namespace nur\sery\ext;
use nur\sery\cl;
use nur\sery\file;
use nur\sery\os\IOException;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Yaml as SymfonyYaml;
/**
* Class yaml: lecture de données yaml
*/
class yaml {
/**
* @throws IOException si une erreur de lecture s'est produite
*/
static final function load($input): array {
$contents = file::reader($input)->getContents();
try {
return cl::with(SymfonyYaml::parse($contents));
} catch (ParseException $e) {
$message = "parse error";
if (is_string($input)) $message .= " while loading $input";
throw new IOException($message, 0, $e);
}
}
static final function with($data, int $indent=2, int $flags=0): string {
return SymfonyYaml::dump($data, PHP_INT_MAX, $indent, $flags);
}
static final function dump($data, $output=null, int $indent=2, int $flags=0): void {
file::writer($output)->putContents(self::with($data, $indent, $flags));
}
}

View File

@ -7,7 +7,6 @@ use nur\sery\cl;
use nur\sery\ExceptionShadow;
use nur\sery\output\IMessenger;
use nur\sery\UserException;
use nur\SL;
use Throwable;
class StdMessenger implements _IMessenger {
@ -242,7 +241,7 @@ class StdMessenger implements _IMessenger {
int $indentLevel, StdOutput $out): void {
$prefixes = self::GENERIC_PREFIXES[$level][$type];
if ($prefixes[0]) $out->print();
$content = SL::with($content);
$content = cl::with($content);
if ($out->isColor()) {
$before = $prefixes[2];
$prefix = $prefixes[3];
@ -362,7 +361,7 @@ class StdMessenger implements _IMessenger {
string $type, $content,
int $indentLevel, StdOutput $out): void {
$prefixes = self::GENERIC_PREFIXES[$level][$type];
$content = SL::with($content);
$content = cl::with($content);
if ($out->isColor()) {
$prefix = $prefixes[1];
$prefix2 = null;

View File

@ -2,6 +2,7 @@
namespace nur\sery\tools;
use nur\sery\ExitError;
use nur\sery\ext\yaml;
use nur\sery\os\path;
use nur\sery\os\proc\Cmd;
use nur\sery\os\sh;
@ -9,7 +10,6 @@ use nur\sery\output\msg;
use nur\sery\app\app;
use nur\sery\app\cli\Application;
use nur\sery\app\RunFile;
use nur\yaml;
class BgLauncherApp extends Application {
const ACTION_INFOS = 0, ACTION_START = 1, ACTION_STOP = 2;