48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
namespace nulib\app\args;
|
|
|
|
use nulib\app\args\Aodef;
|
|
use nulib\app\args\Aolist;
|
|
use nulib\php\types\vbool;
|
|
|
|
/**
|
|
* Class Aosection: un regroupement d'arguments pour améliorer la mise en forme
|
|
* de l'affichage de l'aide
|
|
*/
|
|
class Aosection extends Aolist {
|
|
function __construct(array $defs, bool $setup=false) {
|
|
parent::__construct($defs, $setup);
|
|
}
|
|
|
|
public bool $show = true;
|
|
public ?string $prefix = null;
|
|
public ?string $title = null;
|
|
public ?string $description = null;
|
|
public ?string $suffix = null;
|
|
|
|
protected function parseParams(?array $params): void {
|
|
$this->show = vbool::with($params["show"] ?? true);
|
|
$this->prefix ??= $params["prefix"] ?? null;
|
|
$this->title ??= $params["title"] ?? null;
|
|
$this->description ??= $params["description"] ?? null;
|
|
$this->suffix ??= $params["suffix"] ?? null;
|
|
}
|
|
|
|
function printHelp(?array $what=null): void {
|
|
$showSection = $what["show"] ?? $this->show;
|
|
if (!$showSection) return;
|
|
|
|
$prefix = $what["prefix"] ?? null;
|
|
if ($prefix !== null) echo $prefix;
|
|
|
|
if ($this->prefix) echo "{$this->prefix}\n";
|
|
if ($this->title) echo "{$this->title}\n";
|
|
if ($this->description) echo "\n{$this->description}\n";
|
|
/** @var Aodef|Aolist $aobject */
|
|
foreach ($this->all(["aolist" => true]) as $aobject) {
|
|
$aobject->printHelp();
|
|
}
|
|
if ($this->suffix) echo "{$this->suffix}\n";
|
|
}
|
|
}
|