Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to exclude paths #131

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ final class Application extends DefaultApplication
public const ACTIVE_DIR_OPTION = 'active-dir';
public const STAGING_DIR_OPTION = 'staging-dir';

public const EXCLUDE_OPTION = 'exclude';

public const ACTIVE_DIR_DEFAULT = '.';
public const STAGING_DIR_DEFAULT = '.composer_staging';

Expand Down Expand Up @@ -50,6 +52,15 @@ protected function getDefaultInputDefinition(): InputDefinition
self::STAGING_DIR_DEFAULT,
),
);

$inputDefinition->addOption(
new InputOption(
self::EXCLUDE_OPTION,
'e',
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
'Specify paths to exclude from syncing.',
),
);
} catch (InvalidArgumentException $e) {
throw new LogicException($e->getMessage(), $e->getCode(), $e);
}
Expand Down
23 changes: 21 additions & 2 deletions src/Console/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace PhpTuf\ComposerStagerConsole\Console\Command;

use PhpTuf\ComposerStager\API\Path\Factory\PathFactoryInterface;
use PhpTuf\ComposerStager\API\Path\Factory\PathListFactoryInterface;
use PhpTuf\ComposerStager\API\Path\Value\PathInterface;
use PhpTuf\ComposerStager\API\Path\Value\PathListInterface;
use PhpTuf\ComposerStagerConsole\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -24,8 +26,13 @@ abstract class AbstractCommand extends Command

private PathInterface $stagingDir;

public function __construct(string $name, protected PathFactoryInterface $pathFactory)
{
private PathListInterface $exclusions;

public function __construct(
string $name,
protected PathFactoryInterface $pathFactory,
private ?PathListFactoryInterface $pathListFactory = null,
) {
parent::__construct($name);
}

Expand All @@ -44,10 +51,22 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
$stagingDir = $input->getOption(Application::STAGING_DIR_OPTION);
assert(is_string($stagingDir));
$this->stagingDir = $this->pathFactory->create($stagingDir);

if (!$this->pathListFactory) {
return;
}

$exclude = $input->getOption(Application::EXCLUDE_OPTION);
$this->exclusions = $this->pathListFactory->create(...$exclude);
}

protected function getActiveDir(): PathInterface
{
return $this->activeDir;
}

protected function getExclusions(): PathListInterface
{
return $this->exclusions;
}
}
12 changes: 8 additions & 4 deletions src/Console/Command/BeginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PhpTuf\ComposerStager\API\Core\BeginnerInterface;
use PhpTuf\ComposerStager\API\Exception\ExceptionInterface;
use PhpTuf\ComposerStager\API\Path\Factory\PathFactoryInterface;
use PhpTuf\ComposerStager\API\Path\Factory\PathListFactoryInterface;
use PhpTuf\ComposerStagerConsole\Console\Output\ProcessOutputCallback;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -14,9 +15,12 @@ final class BeginCommand extends AbstractCommand
{
private const NAME = 'begin';

public function __construct(private readonly BeginnerInterface $beginner, PathFactoryInterface $pathFactory)
{
parent::__construct(self::NAME, $pathFactory);
public function __construct(
private readonly BeginnerInterface $beginner,
PathFactoryInterface $pathFactory,
PathListFactoryInterface $pathListFactory,
) {
parent::__construct(self::NAME, $pathFactory, $pathListFactory);
}

protected function configure(): void
Expand All @@ -34,7 +38,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->beginner->begin(
$this->getActiveDir(),
$this->getStagingDir(),
null,
$this->getExclusions(),
new ProcessOutputCallback($input, $output),
);

Expand Down
12 changes: 8 additions & 4 deletions src/Console/Command/CommitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PhpTuf\ComposerStager\API\Core\CommitterInterface;
use PhpTuf\ComposerStager\API\Exception\ExceptionInterface;
use PhpTuf\ComposerStager\API\Path\Factory\PathFactoryInterface;
use PhpTuf\ComposerStager\API\Path\Factory\PathListFactoryInterface;
use PhpTuf\ComposerStagerConsole\Console\Output\ProcessOutputCallback;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Exception\LogicException;
Expand All @@ -19,9 +20,12 @@ final class CommitCommand extends AbstractCommand
{
private const NAME = 'commit';

public function __construct(private readonly CommitterInterface $committer, PathFactoryInterface $pathFactory)
{
parent::__construct(self::NAME, $pathFactory);
public function __construct(
private readonly CommitterInterface $committer,
PathFactoryInterface $pathFactory,
PathListFactoryInterface $pathListFactory,
) {
parent::__construct(self::NAME, $pathFactory, $pathListFactory);
}

protected function configure(): void
Expand All @@ -46,7 +50,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->committer->commit(
$this->getStagingDir(),
$this->getActiveDir(),
null,
$this->getExclusions(),
new ProcessOutputCallback($input, $output),
);

Expand Down