Skip to content

Commit 77909ea

Browse files
greg0irejaapio
authored andcommitted
Work with relative paths
getAbsolutePath() was introduced in 16635e2, 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
1 parent 3efcf20 commit 77909ea

File tree

1 file changed

+2
-22
lines changed
  • packages/guides-cli/src/Command

1 file changed

+2
-22
lines changed

packages/guides-cli/src/Command/Run.php

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,12 @@
5353
use function array_pop;
5454
use function assert;
5555
use function count;
56-
use function getcwd;
5756
use function implode;
5857
use function is_countable;
5958
use function is_dir;
6059
use function microtime;
6160
use function pathinfo;
62-
use function realpath;
6361
use function sprintf;
64-
use function str_starts_with;
6562
use function strtoupper;
6663

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

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

368365
return Command::SUCCESS;
369366
}
370-
371-
private function getAbsolutePath(string $path): string
372-
{
373-
$absolutePath = $path;
374-
if (!str_starts_with($absolutePath, '/')) {
375-
if (getcwd() === false) {
376-
throw new RuntimeException('Cannot find current working directory, use absolute paths.');
377-
}
378-
379-
$absolutePath = realpath(getcwd() . '/' . $absolutePath);
380-
if ($absolutePath === false) {
381-
throw new RuntimeException('Cannot find path "' . $path . '".');
382-
}
383-
}
384-
385-
return $absolutePath;
386-
}
387367
}

0 commit comments

Comments
 (0)