Skip to content

Commit

Permalink
Merge pull request #597 from jolicode/tweak-path-completions
Browse files Browse the repository at this point in the history
Tweak path directory suggestions to include a leading dir separator
  • Loading branch information
pyrech authored Dec 30, 2024
2 parents 902c05d + 91bf094 commit 3dbf4cf
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/Console/Command/TaskCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ private function getPathSuggestions(string $path, string $baseValue): array
}

return array_map(
fn (string $item) => $baseValue . $item,
fn (string $item) => $baseValue . $item . (is_dir($baseValue . $item) ? DIRECTORY_SEPARATOR : ''),
array_filter(
$items,
fn (string $suggestion) => '.' !== $suggestion && '..' !== $suggestion,
Expand Down
38 changes: 19 additions & 19 deletions tests/AutocompleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,33 +91,33 @@ public function providePathCompletionTests(): \Generator
$fs->mkdir($tmpDir . '/bar');
$fs->touch($tmpDir . '/foo/baz.txt');

yield [task_with_path_argument(...), [''], ['bin', 'doc', 'src', 'tools']];
yield [task_with_path_argument(...), ['.'], ['bin', 'doc', 'src', 'tools']];
yield [task_with_path_argument(...), ['./'], ['./bin', './doc', './src', './tools']];
yield [task_with_path_argument(...), ['b'], ['bin', 'doc', 'src', 'tools']];
yield [task_with_path_argument(...), [''], ['bin/', 'doc/', 'src/', 'tools/']];
yield [task_with_path_argument(...), ['.'], ['bin/', 'doc/', 'src/', 'tools/']];
yield [task_with_path_argument(...), ['./'], ['./bin/', './doc/', './src/', './tools/']];
yield [task_with_path_argument(...), ['b'], ['bin/', 'doc/', 'src/', 'tools/']];
yield [task_with_path_argument(...), ['bin'], ['bin/castor']];
yield [task_with_path_argument(...), ['bin/'], ['bin/castor']];
yield [task_with_path_argument(...), ['yolooooooooo'], []];
yield [task_with_path_argument(...), ['yolooooooooo/'], []];
yield [task_with_path_argument(...), [$tmpDir], [$tmpDir . '/bar', $tmpDir . '/foo'], true];
yield [task_with_path_argument(...), [$tmpDir . '/'], [$tmpDir . '/bar', $tmpDir . '/foo'], true];
yield [task_with_path_argument(...), [$tmpDir . '/.'], [$tmpDir . '/bar', $tmpDir . '/foo'], true];
yield [task_with_path_argument(...), [$tmpDir . '/./'], [$tmpDir . '/./bar', $tmpDir . '/./foo'], true];
yield [task_with_path_argument(...), [$tmpDir . '/f'], [$tmpDir . '/bar', $tmpDir . '/foo'], true];

yield [task_with_path_option(...), ['--option'], ['bin', 'doc', 'src', 'tools']];
yield [task_with_path_option(...), ['--option', '.'], ['bin', 'doc', 'src', 'tools']];
yield [task_with_path_option(...), ['--option', './'], ['./bin', './doc', './src', './tools']];
yield [task_with_path_option(...), ['--option', 'b'], ['bin', 'doc', 'src', 'tools']];
yield [task_with_path_argument(...), [$tmpDir], [$tmpDir . '/bar/', $tmpDir . '/foo/'], true];
yield [task_with_path_argument(...), [$tmpDir . '/'], [$tmpDir . '/bar/', $tmpDir . '/foo/'], true];
yield [task_with_path_argument(...), [$tmpDir . '/.'], [$tmpDir . '/bar/', $tmpDir . '/foo/'], true];
yield [task_with_path_argument(...), [$tmpDir . '/./'], [$tmpDir . '/./bar/', $tmpDir . '/./foo/'], true];
yield [task_with_path_argument(...), [$tmpDir . '/f'], [$tmpDir . '/bar/', $tmpDir . '/foo/'], true];

yield [task_with_path_option(...), ['--option'], ['bin/', 'doc/', 'src/', 'tools/']];
yield [task_with_path_option(...), ['--option', '.'], ['bin/', 'doc/', 'src/', 'tools/']];
yield [task_with_path_option(...), ['--option', './'], ['./bin/', './doc/', './src/', './tools/']];
yield [task_with_path_option(...), ['--option', 'b'], ['bin/', 'doc/', 'src/', 'tools/']];
yield [task_with_path_option(...), ['--option', 'bin'], ['bin/castor']];
yield [task_with_path_option(...), ['--option', 'bin/'], ['bin/castor']];
yield [task_with_path_option(...), ['--option', 'yolooooooooo'], []];
yield [task_with_path_option(...), ['--option', 'yolooooooooo/'], []];
yield [task_with_path_option(...), ['--option', $tmpDir], [$tmpDir . '/bar', $tmpDir . '/foo'], true];
yield [task_with_path_option(...), ['--option', $tmpDir . '/'], [$tmpDir . '/bar', $tmpDir . '/foo'], true];
yield [task_with_path_option(...), ['--option', $tmpDir . '/.'], [$tmpDir . '/bar', $tmpDir . '/foo'], true];
yield [task_with_path_option(...), ['--option', $tmpDir . '/./'], [$tmpDir . '/./bar', $tmpDir . '/./foo'], true];
yield [task_with_path_option(...), ['--option', $tmpDir . '/f'], [$tmpDir . '/bar', $tmpDir . '/foo'], true];
yield [task_with_path_option(...), ['--option', $tmpDir], [$tmpDir . '/bar/', $tmpDir . '/foo/'], true];
yield [task_with_path_option(...), ['--option', $tmpDir . '/'], [$tmpDir . '/bar/', $tmpDir . '/foo/'], true];
yield [task_with_path_option(...), ['--option', $tmpDir . '/.'], [$tmpDir . '/bar/', $tmpDir . '/foo/'], true];
yield [task_with_path_option(...), ['--option', $tmpDir . '/./'], [$tmpDir . '/./bar/', $tmpDir . '/./foo/'], true];
yield [task_with_path_option(...), ['--option', $tmpDir . '/f'], [$tmpDir . '/bar/', $tmpDir . '/foo/'], true];
}
}

Expand Down
22 changes: 22 additions & 0 deletions tests/Generated/ArgsAutocompletePathTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Castor\Tests\Generated;

use Castor\Tests\TaskTestCase;
use Symfony\Component\Process\Exception\ProcessFailedException;

class ArgsAutocompletePathTest extends TaskTestCase
{
// args:autocomplete-path
public function test(): void
{
$process = $this->runTask(['args:autocomplete-path', 'FIXME(argument)']);

if (0 !== $process->getExitCode()) {
throw new ProcessFailedException($process);
}

$this->assertStringEqualsFile(__FILE__ . '.output.txt', $process->getOutput());
$this->assertSame('', $process->getErrorOutput());
}
}
4 changes: 4 additions & 0 deletions tests/Generated/ArgsAutocompletePathTest.php.output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
array(1) {
[0]=>
string(15) "FIXME(argument)"
}
2 changes: 1 addition & 1 deletion tests/Generated/SshDownloadTest.php.output.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
In ssh.php line XXXX:

[ERROR] The following process did not finish successfully (exit code 1):
[ERROR] The following process did not finish successfully (exit code 255):

scp -r [email protected]:/tmp/test.html /var/www/index.html

2 changes: 1 addition & 1 deletion tests/Generated/SshUploadTest.php.output.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
In ssh.php line XXXX:

[ERROR] The following process did not finish successfully (exit code 1):
[ERROR] The following process did not finish successfully (exit code 255):

scp -r .../examples/ssh.php [email protected]:/var/www/index.html

0 comments on commit 3dbf4cf

Please sign in to comment.