Skip to content

Commit

Permalink
fix: add non interactive option
Browse files Browse the repository at this point in the history
  • Loading branch information
yusuftaufiq committed Jun 3, 2022
1 parent efd4452 commit d7c76e2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Commands/GenerateHelperCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ public function execute(): void
public function __invoke(
string $dir = './',
array $pattern = [],
string $output = '_ide_helper.php'
string $output = '_ide_helper.php',
bool $noInteraction
): int {
$this->facade->withDirectory($dir);
$this->facade->withPatterns($pattern);
$this->facade->withOutputPath($output);
$this->facade->setInteractive(!$noInteraction);

return $this->facade->generate();
}
Expand Down
16 changes: 14 additions & 2 deletions src/Facades/GenerateHelperFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Haemanthus\CodeIgniter3IdeHelper\Application;
use Haemanthus\CodeIgniter3IdeHelper\Contracts\FileWriter;
use Silly\Command\Command as SillyCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class GenerateHelperFacade
Expand All @@ -15,6 +16,8 @@ class GenerateHelperFacade

protected FileWriter $writer;

protected InputInterface $input;

protected SymfonyStyle $io;

protected int $availableAskAttempts = 2;
Expand All @@ -23,11 +26,13 @@ public function __construct(
ReaderFacade $reader,
ParserFacade $parser,
FileWriter $writer,
InputInterface $input,
SymfonyStyle $io
) {
$this->reader = $reader;
$this->parser = $parser;
$this->writer = $writer;
$this->input = $input;
$this->io = $io;
}

Expand All @@ -52,6 +57,13 @@ public function withOutputPath(string $path): self
return $this;
}

public function setInteractive(bool $interactive): self
{
$this->input->setInteractive($interactive);

return $this;
}

protected function checkDirectory(): bool
{
while (
Expand All @@ -60,7 +72,7 @@ protected function checkDirectory(): bool
) {
$this->availableAskAttempts -= 1;

$this->io->error("CodeIgniter 3 directory can't be found");
$this->io->error("CodeIgniter 3 directory can't be found.");

$this->withDirectory($this->io->ask('Please enter a valid CodeIgniter 3 directory again', './'));
}
Expand Down Expand Up @@ -94,7 +106,7 @@ public function generate(): int

$this->writer->write($structuralElements);

$this->io->success('Successfully generated IDE Helper file');
$this->io->success('Successfully generated IDE helper file');

return SillyCommand::SUCCESS;
}
Expand Down

0 comments on commit d7c76e2

Please sign in to comment.