Skip to content

Commit

Permalink
Merge pull request #98 from mxr576/drupal-root-fix
Browse files Browse the repository at this point in the history
Introduce new --drupal-root option
  • Loading branch information
mglaman authored Aug 2, 2019
2 parents f973c95 + 204991d commit 37401b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Options:

* `-a` Check analysis
* `-d` Check deprecations (default)
* `--drupal-root` Path to Drupal root. Fallback option if drupal-check could not identify Drupal root from the provided path(s).

Examples:

Expand Down
16 changes: 13 additions & 3 deletions src/Command/CheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace DrupalCheck\Command;

use DrupalCheck\DrupalCheckErrorHandler;
use DrupalCheck\PHPStan\DrupalCheckAnalyze;
use DrupalFinder\DrupalFinder;
use PHPStan\Command\AnalyseApplication;
use PHPStan\Command\CommandHelper;
Expand All @@ -30,6 +29,7 @@ protected function configure(): void
->setName('check')
->setDescription('Checks a Drupal site')
->addArgument('path', InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'The Drupal code path(s) to inspect')
->addOption('drupal-root', null, InputOption::VALUE_OPTIONAL, 'Path to Drupal root.')
->addOption('format', null, InputOption::VALUE_OPTIONAL, 'Formatter to use: raw, table, checkstyle, json, or junit', 'table')
->addOption('deprecations', 'd', InputOption::VALUE_NONE, 'Check for deprecations')
->addOption('analysis', 'a', InputOption::VALUE_NONE, 'Check code analysis')
Expand Down Expand Up @@ -93,12 +93,22 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$paths[] = $realPath;
}

$drupalFinder->locateRoot($paths[0]);
$drupalRootCandidate = $paths[0];

if (!empty($input->getOption('drupal-root'))) {
$drupalRootCandidate = realpath($input->getOption('drupal-root'));
if ($drupalRootCandidate === false) {
$output->writeln(sprintf('<error>%s does not exist</error>', $input->getOption('drupal-root')));
return 1;
}
}

$drupalFinder->locateRoot($drupalRootCandidate);
$this->drupalRoot = $drupalFinder->getDrupalRoot();
$this->vendorRoot = $drupalFinder->getVendorDir();

if (!$this->drupalRoot) {
$output->writeln(sprintf('<error>Unable to locate the Drupal root in %s</error>', $paths[0]));
$output->writeln(sprintf('<error>Unable to locate the Drupal root in %s</error>', $drupalRootCandidate));
return 1;
}

Expand Down

0 comments on commit 37401b4

Please sign in to comment.