silverstripe-framework/tests/php/Cli/Command/PolyCommandCliWrapperTest/TestPolyCommand.php
Guy Sartorelli e46135be0a
NEW Refactor CLI interaction with Silverstripe app (#11353)
- Turn sake into a symfony/console app
- Avoid using HTTPRequest for CLI interaction
- Implement abstract hybrid execution path
2024-09-26 17:16:47 +12:00

44 lines
1.2 KiB
PHP

<?php
namespace SilverStripe\Cli\Tests\Command\PolyCommandCliWrapperTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\PolyExecution\PolyCommand;
use SilverStripe\PolyExecution\PolyOutput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
class TestPolyCommand extends PolyCommand implements TestOnly
{
protected static string $commandName = 'test:poly';
protected static string $description = 'simple command for testing CLI wrapper';
private int $exitCode = 0;
public function getTitle(): string
{
return 'This is the title!';
}
public function run(InputInterface $input, PolyOutput $output): int
{
$output->writeln('Has option 1: ' . ($input->getOption('option1') ? 'true' : 'false'));
$output->writeln('option 2 value: ' . $input->getOption('option2'));
return $this->exitCode;
}
public function setExitCode(int $code): void
{
$this->exitCode = $code;
}
public function getOptions(): array
{
return [
new InputOption('option1', null, InputOption::VALUE_NONE),
new InputOption('option2', null, InputOption::VALUE_REQUIRED),
];
}
}