Skip to content

Commit

Permalink
Support specifying the source file as path
Browse files Browse the repository at this point in the history
  • Loading branch information
dragosprotung committed May 9, 2023
1 parent cabcccb commit 986f99b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Command/UploadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Translation\Translator;
use Wingu\FluffyPoRobot\POEditor\Configuration\File;
use Wingu\FluffyPoRobot\POEditor\FormatGuesser;

use function array_keys;
use function count;
use function implode;
use function is_array;
use function sprintf;

Expand All @@ -38,8 +38,8 @@ protected function doRun(): void
$terms = [];
$sourceFiles = [];
foreach ($this->config->files() as $file) {
/** @var File $file */
$finder = Finder::create()->in($this->config->basePath())->path($file->source());
$in = implode('/', [$this->config->basePath(), $file->sourceDirectory()]);
$finder = Finder::create()->in($in)->path($file->sourceFileName());
if ($finder->count() !== 1) {
if ($finder->count() === 0) {
throw new RuntimeException(sprintf('No source file found for "%s".', $file->source()));
Expand Down
13 changes: 13 additions & 0 deletions src/POEditor/Configuration/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Wingu\FluffyPoRobot\POEditor\Configuration;

use function basename;
use function dirname;

final class File
{
private string $source;
Expand All @@ -24,6 +27,16 @@ public function source(): string
return $this->source;
}

public function sourceDirectory(): string
{
return dirname($this->source);
}

public function sourceFileName(): string
{
return basename($this->source);
}

public function translation(): string
{
return $this->translation;
Expand Down

0 comments on commit 986f99b

Please sign in to comment.