Skip to content

Commit

Permalink
Work with relative paths
Browse files Browse the repository at this point in the history
getAbsolutePath() was introduced in
16635e2ce062a4ffe0ebbbfa1c4d551b0e2e2521, but it is unclear to me why.
Removing it seems to fix UX inconsistencies without introducing other
issues.

It causes non-existent relative paths to be treated differently than
non-existent absolute paths: using the former crashes the program, while
using the latter results in directories being created at the provided
paths.

Closes #825
  • Loading branch information
greg0ire authored and jaapio committed Feb 8, 2024
1 parent b7c7041 commit 7a65053
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions src/Command/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,12 @@
use function array_pop;
use function assert;
use function count;
use function getcwd;
use function implode;
use function is_countable;
use function is_dir;
use function microtime;
use function pathinfo;
use function realpath;
use function sprintf;
use function str_starts_with;
use function strtoupper;

final class Run extends Command
Expand Down Expand Up @@ -261,7 +258,7 @@ private function getSettingsOverriddenWithInput(InputInterface $input): ProjectS
protected function execute(InputInterface $input, OutputInterface $output): int
{
$settings = $this->getSettingsOverriddenWithInput($input);
$inputDir = $this->getAbsolutePath($settings->getInput());
$inputDir = $settings->getInput();
if (!is_dir($inputDir)) {
throw new RuntimeException(sprintf('Input directory "%s" was not found! ' . "\n" .
'Run "vendor/bin/guides -h" for information on how to configure this command.', $inputDir));
Expand All @@ -281,7 +278,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$projectNode = $event->getProjectNode();
$settings = $event->getSettings();

$outputDir = $this->getAbsolutePath($settings->getOutput());
$outputDir = $settings->getOutput();
$sourceFileSystem = new Filesystem(new Local($settings->getInput()));
$sourceFileSystem->addPlugin(new Finder());
$logPath = $settings->getLogPath();
Expand Down Expand Up @@ -367,21 +364,4 @@ protected function execute(InputInterface $input, OutputInterface $output): int

return Command::SUCCESS;
}

private function getAbsolutePath(string $path): string
{
$absolutePath = $path;
if (!str_starts_with($absolutePath, '/')) {
if (getcwd() === false) {
throw new RuntimeException('Cannot find current working directory, use absolute paths.');
}

$absolutePath = realpath(getcwd() . '/' . $absolutePath);
if ($absolutePath === false) {
throw new RuntimeException('Cannot find path "' . $path . '".');
}
}

return $absolutePath;
}
}

0 comments on commit 7a65053

Please sign in to comment.