nur-sery/tbin/test-console.php

290 lines
7.2 KiB
PHP
Raw Normal View History

2023-12-26 23:27:51 +04:00
#!/usr/bin/php
<?php
require(__DIR__.'/../vendor/autoload.php');
2023-12-28 13:29:39 +04:00
use nulib\UserException;
2023-12-27 11:38:43 +04:00
use nur\sery\output\std\StdMessenger;
2023-12-26 23:27:51 +04:00
$params = [];
$count = count($argv) - 1;
for ($i = 1; $i <= $count; $i++) {
switch ($argv[$i]) {
case "-n":
$params["color"] = false;
break;
case "+n":
$params["color"] = true;
break;
case "-d":
$params["debug"] = true;
break;
case "+d":
$params["debug"] = false;
break;
2023-12-27 01:39:08 +04:00
case "-L":
$i++;
$params["output"] = $argv[$i];
break;
2023-12-26 23:27:51 +04:00
case "-D":
$params["default_level"] = "debug";
$params["debug"] = true;
break;
case "-N":
$params["default_level"] = "normal";
break;
case "-M":
$params["default_level"] = "major";
break;
2023-12-28 11:54:15 +04:00
case "-i":
$i++;
$params["id"] = $argv[$i];
break;
case "-t":
$params["add_date"] = true;
break;
2023-12-26 23:27:51 +04:00
}
}
2023-12-28 14:16:39 +04:00
$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);
});
});