|
|
|
@ -2,8 +2,11 @@
|
|
|
|
|
|
|
|
|
|
namespace jrosset\Tests\Commands;
|
|
|
|
|
|
|
|
|
|
use DateTimeImmutable;
|
|
|
|
|
use DateTimeInterface;
|
|
|
|
|
use jrosset\CliProgram\Monolog\ConsoleOutputWithMonolog;
|
|
|
|
|
use jrosset\CliProgram\Validation\CommandWithValidation;
|
|
|
|
|
use jrosset\CliProgram\Validation\Validators\DateValidator;
|
|
|
|
|
use jrosset\CliProgram\Validation\Validators\EnumValidator;
|
|
|
|
|
use jrosset\CliProgram\Validation\Validators\IntegerValidator;
|
|
|
|
|
use jrosset\Tests\Lang;
|
|
|
|
@ -32,7 +35,16 @@ class Hello extends CommandWithValidation {
|
|
|
|
|
parent::configure();
|
|
|
|
|
|
|
|
|
|
$this->addArgument(
|
|
|
|
|
'day',
|
|
|
|
|
InputArgument::OPTIONAL,
|
|
|
|
|
'The day',
|
|
|
|
|
new DateTimeImmutable(),
|
|
|
|
|
new DateValidator()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->addOption(
|
|
|
|
|
'lang',
|
|
|
|
|
'l',
|
|
|
|
|
InputArgument::OPTIONAL,
|
|
|
|
|
'The lang',
|
|
|
|
|
Lang::English,
|
|
|
|
@ -54,11 +66,17 @@ class Hello extends CommandWithValidation {
|
|
|
|
|
protected function execute (InputInterface $input, OutputInterface $output): int {
|
|
|
|
|
$output->writeln('Command : ' . __CLASS__, OutputInterface::VERBOSITY_DEBUG);
|
|
|
|
|
|
|
|
|
|
/** @var Lang $lang */
|
|
|
|
|
$lang = $input->getArgument('lang');
|
|
|
|
|
$text = $input->getOption('lang')->value;
|
|
|
|
|
$repeat = $input->getOption('repeat');
|
|
|
|
|
|
|
|
|
|
/** @var DateTimeInterface $day */
|
|
|
|
|
$day = $input->getArgument('day');
|
|
|
|
|
if ((new DateTimeImmutable())->diff($day)->days === 0) {
|
|
|
|
|
$text .= ' today';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for ($curr = 0; $curr < $repeat; $curr++) {
|
|
|
|
|
$output->writeln($lang->value);
|
|
|
|
|
$output->writeln($text);
|
|
|
|
|
}
|
|
|
|
|
$output->writeln('FIN', ConsoleOutputWithMonolog::OPTION_SKIP_MONOLOG);
|
|
|
|
|
return Command::SUCCESS;
|
|
|
|
|