nur-sery/tbin/test-console.php

280 lines
7.5 KiB
PHP
Executable File

#!/usr/bin/php
<?php
require(__DIR__.'/../vendor/autoload.php');
use nulib\UserException;
use nur\sery\output\std\StdMessenger;
$params = [];
$count = count($argv) - 1;
for ($i = 1; $i <= $count; $i++) {
switch ($argv[$i]) {
case "-L": $i++; $params["output"] = $argv[$i]; break;
case "-i": $i++; $params["id"] = $argv[$i]; break;
case "-t": $params["add_date"] = true; break;
case "-n": $params["color"] = false; break;
case "+n": $params["color"] = true; break;
case "-d": $params["debug"] = true; break;
case "+d": $params["debug"] = false; break;
case "-D": $params["default_level"] = "debug"; break;
case "-m": $params["default_level"] = "minor"; break;
case "-M": $params["default_level"] = "major"; break;
case "--show-debug":
case "--sd": $params["min_level"] = "debug"; break;
case "--show-minor":
case "--verbose":
case "--sm": $params["min_level"] = "minor"; break;
case "--show-normal":
case "--sn": $params["min_level"] = "normal"; break;
case "--show-major":
case "--quiet":
case "--sM": $params["min_level"] = "major"; break;
case "--show-none":
case "--silent":
case "--sx": $params["min_level"] = "none"; break;
}
}
$msg = new StdMessenger($params);
$msg->title("title0");
$msg->title("title1");
$msg->print("print under title1");
$msg->end();
$msg->print("print under title0");
$msg->end();
$msg->desc("action avec step");
$msg->action("action avec step");
$msg->step("step");
$msg->asuccess("action success");
$msg->action("action avec step");
$msg->step("step");
$msg->afailure("action failure");
$msg->action("action avec step");
$msg->step("step");
$msg->adone("action neutral");
$msg->desc("actions sans step");
$msg->action("action sans step");
$msg->asuccess("action success");
$msg->action("action sans step");
$msg->afailure("action failure");
$msg->action("action sans step");
$msg->adone("action neutral");
$msg->desc("actions imbriquées");
$msg->action("action0");
$msg->action("action1");
$msg->action("action2");
$msg->asuccess("action2 success");
$msg->asuccess("action1 success");
$msg->asuccess("action0 success");
$msg->desc("action avec step, sans messages");
$msg->action("action avec step, sans messages, success");
$msg->step("step");
$msg->asuccess();
$msg->action("action avec step, sans messages, failure");
$msg->step("step");
$msg->afailure();
$msg->action("action avec step, sans messages, done");
$msg->step("step");
$msg->adone();
$msg->desc("action sans step, sans messages");
$msg->action("action sans step, sans messages, success");
$msg->asuccess();
$msg->action("action sans step, sans messages, failure");
$msg->afailure();
$msg->action("action sans step, sans messages, done");
$msg->adone();
$msg->desc("actions imbriquées, sans messages");
$msg->action("action0");
$msg->action("action1");
$msg->action("action2");
$msg->asuccess();
$msg->asuccess();
$msg->asuccess();
$msg->info("info");
$msg->note("note");
$msg->warn("warn");
$msg->error("error");
$msg->section("section", function ($msg) {
$msg->title("title", function ($msg) {
$msg->desc("desc");
$msg->print("print");
$msg->desc("action avec step");
$msg->action("action avec step", function ($msg) {
$msg->step("step");
$msg->asuccess("action success");
});
$msg->action("action avec step", function ($msg) {
$msg->step("step");
$msg->afailure("action failure");
});
$msg->action("action avec step", function ($msg) {
$msg->step("step");
$msg->adone("action done");
});
$msg->desc("actions sans step");
$msg->action("action sans step", function ($msg) {
$msg->asuccess("action success");
});
$msg->action("action sans step", function ($msg) {
$msg->afailure("action failure");
});
$msg->action("action sans step", function ($msg) {
$msg->adone("action done");
});
$msg->desc("actions imbriquées");
$msg->action("action0", function ($msg) {
$msg->action("action1", function ($msg) {
$msg->action("action2", function ($msg) {
$msg->asuccess("action2 success");
});
$msg->asuccess("action1 success");
});
$msg->asuccess("action0 success");
});
$msg->desc("action avec step, sans messages");
$msg->action("action avec step, sans messages, success", function ($msg) {
$msg->step("step");
$msg->asuccess();
});
$msg->action("action avec step, sans messages, failure", function ($msg) {
$msg->step("step");
$msg->afailure();
});
$msg->action("action avec step, sans messages, done", function ($msg) {
$msg->step("step");
$msg->adone();
});
$msg->desc("action sans step, sans messages");
$msg->action("action sans step, sans messages, success", function ($msg) {
$msg->asuccess();
});
$msg->action("action sans step, sans messages, failure", function ($msg) {
$msg->afailure();
});
$msg->action("action sans step, sans messages, done", function ($msg) {
$msg->adone();
});
$msg->desc("actions imbriquées, sans messages");
$msg->action("action0", function ($msg) {
$msg->action("action1", function ($msg) {
$msg->action("action2", function ($msg) {
$msg->asuccess();
});
$msg->asuccess();
});
$msg->asuccess();
});
$msg->desc("action avec step, avec code de retour");
$msg->action("action avec step, avec code de retour true", function ($msg) {
$msg->step("step");
return true;
});
$msg->action("action avec step, avec code de retour false", function ($msg) {
$msg->step("step");
return false;
});
$msg->action("action avec step, avec code de retour autre", function ($msg) {
$msg->step("step");
return "autre";
});
$msg->action("action avec step, avec code de retour null", function ($msg) {
$msg->step("step");
});
$msg->desc("action sans step, avec code de retour");
$msg->action("action sans step, avec code de retour true", function ($msg) {
return true;
});
$msg->action("action sans step, avec code de retour false", function ($msg) {
return false;
});
$msg->action("action sans step, avec code de retour autre", function ($msg) {
return "autre";
});
# ici, il n'y aura pas de message du tout
$msg->action("action sans step, avec code de retour null", function ($msg) {
});
$msg->info("info");
$msg->note("note");
$msg->warn("warn");
$msg->error("error");
});
});
$msg->section("multi-line\nsection", function ($msg) {
$msg->title("multi-line\ntitle");
$msg->title("another\ntitle");
$msg->print("multi-line\nprint");
$msg->info("multi-line\ninfo");
$msg->action("multi-line\naction");
$msg->asuccess();
$msg->action("multi-line\naction");
$msg->step("multi-line\nstep");
$msg->afailure();
$msg->action("multi-line\naction");
$msg->step("multi-line\nstep");
$msg->asuccess("multi-line\nsuccess");
$msg->action("multi-line\naction");
$msg->step("multi-line\nstep");
$msg->adone("multi-line\ndone");
$msg->end();
$msg->end();
});
$msg->section("Exceptions", function ($msg) {
$e = new Exception("message");
$u1 = new UserException("userMessage");
$u2 = new UserException("userMessage", "techMessage");
$msg->title("avec message", function ($msg) use ($e, $u1, $u2) {
$msg->info(["exception", $e]);
$msg->info(["userException1", $u1]);
$msg->info(["userException2", $u2]);
});
$msg->title("sans message", function ($msg) use ($e, $u1, $u2) {
$msg->info($e);
$msg->info($u1);
$msg->info($u2);
});
});