nulib-base/php/tbin/test-application.php

79 lines
2.3 KiB
PHP
Executable File

#!/usr/bin/php
<?php
require __DIR__."/../vendor/autoload.php";
use nulib\app\app;
use nulib\app\cli\Application;
use nulib\output\msg;
Application::run(new class extends Application {
const ARGS = [
"purpose" => "tester la gestion des arguments",
"usage" => "-A|-a|-b",
"merge" => parent::ARGS,
"sections" => [
[
"title" => "Section X",
"show" => false,
["group",
["-X:", "--setx", "args" => "int", "name" => "x",
"help" => "spécifier x",
],
["--setx10", "name" => "x", "value" => 10],
["--setx20", "name" => "x", "value" => 20],
],
["-x", "--incx", "name" => "x"],
["-y", "--decx", "name" => "x", "inverse" => true],
],
],
["group",
["-A:", "--seta", "args" => "int", "name" => "a",
"help" => "spécifier a",
],
["--seta10", "name" => "a", "value" => 10],
["--seta20", "name" => "a", "value" => 20],
],
["-a", "--inca", "name" => "a",
"help" => "incrémenter a",
],
["-b", "--deca", "name" => "a", "inverse" => true,
"help" => "décrémenter a",
],
["-D::", "--override",
"help" => "++remplace celui de la section principale",
],
["-1:first", "--one", "help" => "un argument"],
["-2:first,second", "--two", "help" => "deux arguments"],
["-3", "args" => ""],
//["args" => [["value", "value"]], "name" => "args"],
//["args" => ["value", ["value"]], "name" => "args"],
//["args" => ["value", "value"], "name" => "args"],
];
private ?int $a = null;
private ?int $x = null;
private ?string $override = null;
private ?string $one = null;
private ?array $two = null;
function main() {
$profile = app::get_profile($productionMode);
$profile = self::get_profile($profile);
$productionMode = $productionMode? "production": "development";
msg::info("profile=$profile ($productionMode)");
$debug = app::is_debug()? "DEBUG": "non";
msg::info("debug=$debug");
msg::info([
"variables:",
"\na=", var_export($this->a, true),
"\nx=", var_export($this->x, true),
"\noverride=", var_export($this->override, true),
"\none=", var_export($this->one, true),
"\ntwo=", var_export($this->two, true),
"\nargs=", var_export($this->args, true),
]);
}
});