You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.8 KiB
PHP
66 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace jrosset\Tests\Commands;
|
|
|
|
use jrosset\CliProgram\Monolog\ConsoleOutputWithMonolog;
|
|
use jrosset\CliProgram\Validation\CommandWithValidation;
|
|
use jrosset\CliProgram\Validation\Validators\EnumValidator;
|
|
use jrosset\CliProgram\Validation\Validators\IntegerValidator;
|
|
use jrosset\Tests\Lang;
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
class Hello extends CommandWithValidation {
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
protected static $defaultDescription = 'Say hello';
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function __construct () {
|
|
parent::__construct('hello', 'bonjour');
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
protected function configure () {
|
|
parent::configure();
|
|
|
|
$this->addArgument(
|
|
'lang',
|
|
InputArgument::OPTIONAL,
|
|
'The lang',
|
|
Lang::English,
|
|
new EnumValidator(Lang::class)
|
|
);
|
|
$this->addOption(
|
|
'repeat',
|
|
'r',
|
|
InputArgument::OPTIONAL,
|
|
'The number of repeat',
|
|
1,
|
|
new IntegerValidator(1, null)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
protected function execute (InputInterface $input, OutputInterface $output): int {
|
|
$output->writeln('Command : ' . __CLASS__, OutputInterface::VERBOSITY_DEBUG);
|
|
|
|
/** @var Lang $lang */
|
|
$lang = $input->getArgument('lang');
|
|
$repeat = $input->getOption('repeat');
|
|
for ($curr = 0; $curr < $repeat; $curr++) {
|
|
$output->writeln($lang->value);
|
|
}
|
|
$output->writeln('FIN', ConsoleOutputWithMonolog::OPTION_SKIP_MONOLOG);
|
|
return Command::SUCCESS;
|
|
}
|
|
} |