Skip to content

Commit

Permalink
Show error when --drall-* options are detected
Browse files Browse the repository at this point in the history
  • Loading branch information
jigarius committed Dec 27, 2024
1 parent 8774059 commit 2d1d40d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/Command/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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());
}
Expand Down
17 changes: 17 additions & 0 deletions src/Command/ExecCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(<<<EOT
In Drall 4.x, all --drall-* options have been renamed.
See https://github.com/jigarius/drall/issues/99
EOT);
throw new \RuntimeException('Obsolete options detected.');
}
}
}

parent::initialize($input, $output);
}

protected function execute(InputInterface $input, OutputInterface $output): int {
$this->preExecute($input, $output);

Expand Down
23 changes: 20 additions & 3 deletions test/Integration/DrallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@
*/
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');
$this->assertStringContainsString(Drall::NAME . ' ' . $version, $process->getOutput());
}

/**
* 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(<<<EOT
Expand All @@ -35,4 +38,18 @@ public function testUnrecognizedCommand() {
EOT, $process->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(<<<EOT
In Drall 4.x, all --drall-* options have been renamed.
See https://github.com/jigarius/drall/issues/99
EOT, $process->getOutput());
$this->assertEquals(1, $process->getExitCode());
}

}

0 comments on commit 2d1d40d

Please sign in to comment.