nur-sery/nur_src/mapper/item/TextMapper_command.php

52 lines
1.4 KiB
PHP

<?php
namespace nur\mapper\item;
use nur\mapper\base\mappers_command;
use nur\mapper\base\Tparams_command;
/**
* Class TextMapper_command: classe de support pour construire une instance de
* mapper pour une application recevant des commandes utilisateurs
*/
class TextMapper_command {
use Tparams_command;
const NAME = "text";
const DEF = [self::NAME, "txt",
"help" => "faire des opérations sur des chaines",
"action" => [self::class, "create_command"],
"cmd_args" => [
"usage" => self::NAME,
["--mo", "--marked-only", "args" => "value", "type" => "bool",
"action" => [self::class, "set_marked_only"],
"help" => "indiquer si les opérations ne doivent être effectuées que sur les éléments marqués",
],
["-o", "--param", "args" => "value",
"action" => [self::class, "add_params"],
"help" => "spécifier une option générique",
],
["args" => [["value", null]],
"action" => [self::class, "add_actions"],
],
],
];
/** @var TextMapper */
protected static $command;
static function create_command() {
self::$command = mappers_command::add(new TextMapper());
}
static function set_marked_only(?bool $marked_only) {
self::get()->setMarkedOnly($marked_only);
}
static function add_actions(array $actions) {
$command = self::get();
foreach ($actions as $action) {
$command->addAction($action);
}
}
}