use jrosset\CliProgram\Validation\Validators\InvalidValueException;
use jrosset\CliProgram\Validation\Validators\IValidator;
use ReflectionFunction;
use Stringable;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Input\InputArgument;
@ -24,16 +26,59 @@ trait TCommandWithValidation {
* @var array<string,IValidator> The validators of each {@see InputOption}
*/
private array $optionsValidator = [];
/**
* @var Closure|null The <i>real</i> code ({@see Command::$code} is used to perform input validation before execution) to execute when running this command.
* <br><br>If set, it overrides the code defined in the execute() method.
*/
private ?Closure $realCode = null;
/**
* @inheritDoc
*
* @throws Throwable If an argument or option is not valid
*/
protected function interact (InputInterface $input, OutputInterface $output): void {
parent::interact($input, $output);
$this->validate($input, $output);
protected function initialize (InputInterface $input, OutputInterface $output): void {
parent::setCode(
function (InputInterface $input, OutputInterface $output): int {