From 2d1d40dd143c109cc7671f469aced517c84a28c5 Mon Sep 17 00:00:00 2001 From: Jerry Radwick Date: Fri, 27 Dec 2024 00:18:58 -0500 Subject: [PATCH] Show error when --drall-* options are detected --- src/Command/BaseCommand.php | 12 ++++++++---- src/Command/ExecCommand.php | 17 +++++++++++++++++ test/Integration/DrallTest.php | 23 ++++++++++++++++++++--- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/Command/BaseCommand.php b/src/Command/BaseCommand.php index 9a5abac..2299e6e 100644 --- a/src/Command/BaseCommand.php +++ b/src/Command/BaseCommand.php @@ -32,6 +32,14 @@ protected function configure() { ); } + protected function initialize(InputInterface $input, OutputInterface $output): void { + if (!$this->logger) { + $this->logger = new ConsoleLogger($output); + } + + parent::initialize($input, $output); + } + /** * Gets the active Drall group. * @@ -65,10 +73,6 @@ protected function getDrallFilter(InputInterface $input): ?string { } protected function preExecute(InputInterface $input, OutputInterface $output) { - if (!$this->logger) { - $this->logger = new ConsoleLogger($output); - } - if (!$this->hasSiteDetector()) { $this->setSiteDetector(new SiteDetector()); } diff --git a/src/Command/ExecCommand.php b/src/Command/ExecCommand.php index 3894d66..28a9b4c 100644 --- a/src/Command/ExecCommand.php +++ b/src/Command/ExecCommand.php @@ -90,6 +90,23 @@ protected function configure() { $this->ignoreValidationErrors(); } + protected function initialize(InputInterface $input, OutputInterface $output): void { + // If obsolete --drall-* options are present, then abort. + if (method_exists($input, 'getRawTokens')) { + foreach ($input->getRawTokens() as $token) { + if (str_starts_with($token, '--drall-')) { + $output->writeln(<<preExecute($input, $output); diff --git a/test/Integration/DrallTest.php b/test/Integration/DrallTest.php index 69489b1..2f55e63 100644 --- a/test/Integration/DrallTest.php +++ b/test/Integration/DrallTest.php @@ -12,7 +12,10 @@ */ class DrallTest extends TestCase { - public function testVersion() { + /** + * @testdox Returns correct version string. + */ + public function testVersion(): void { $process = Process::fromShellCommandline('drall --version', static::PATH_DRUPAL); $process->run(); $version = InstalledVersions::getPrettyVersion('jigarius/drall'); @@ -20,9 +23,9 @@ public function testVersion() { } /** - * Run drall with a command it doesn't recognize. + * @testdox Suggests "drush" for unrecognized commands. */ - public function testUnrecognizedCommand() { + public function testUnrecognizedCommand(): void { $process = Process::fromShellCommandline('drall st', static::PATH_DRUPAL); $process->run(); $this->assertOutputEquals(<<getErrorOutput()); } + /** + * @testdox Shows error when --drall-* options are detected. + */ + public function testShowErrorForObsoleteOptions(): void { + $process = Process::fromShellCommandline('./vendor/bin/drall exec --drall-foo drush st', static::PATH_DRUPAL); + $process->run(); + $this->assertOutputEquals(<<getOutput()); + $this->assertEquals(1, $process->getExitCode()); + } + }