diff --git a/app/Generators/BitoCliGenerator.php b/app/Generators/BitoCliGenerator.php index 393a68e..6ebe62f 100644 --- a/app/Generators/BitoCliGenerator.php +++ b/app/Generators/BitoCliGenerator.php @@ -15,6 +15,8 @@ use App\ConfigManager; use App\Contracts\GeneratorContract; use Illuminate\Console\OutputStyle; +use Illuminate\Support\Facades\Artisan; +use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Process\Process; final class BitoCliGenerator implements GeneratorContract @@ -29,10 +31,22 @@ final class BitoCliGenerator implements GeneratorContract */ private $outputStyle; + /** + * @var \Symfony\Component\Console\Helper\ProcessHelper + */ + private $processHelper; + + /** + * @psalm-suppress UndefinedMethod + */ public function __construct(array $config) { $this->config = $config; - $this->outputStyle = resolve(OutputStyle::class); + $this->outputStyle = tap(clone resolve(OutputStyle::class))->setVerbosity(OutputInterface::VERBOSITY_DEBUG); + $this->processHelper = (function () { + /** @noinspection PhpUndefinedMethodInspection */ + return $this->getArtisan()->getHelperSet()->get('process'); + })->call(Artisan::getFacadeRoot()); } /** @@ -41,12 +55,23 @@ public function __construct(array $config) public function generate(string $prompt): string { // file_put_contents($promptFile = ConfigManager::globalPath($this->config['prompt_filename']), $prompt); + // + // return resolve( + // Process::class, + // ['command' => [$this->config['path'] ?: 'bito', '-p', $promptFile]] + $this->config['parameters'] + // )->mustRun(function (string $type, string $data): void { + // Process::OUT === $type ? $this->outputStyle->write($data) : $this->outputStyle->write("$data"); + // })->getOutput(); - return resolve(Process::class, ['command' => [$this->config['path']]] + $this->config['parameters']) - ->setInput($prompt) - ->mustRun(function (string $type, string $data): void { - Process::OUT === $type ? $this->outputStyle->write($data) : $this->outputStyle->write("$data"); - }) + return $this + ->processHelper + ->mustRun( + $this->outputStyle, + resolve( + Process::class, + ['command' => [$this->config['path']]] + $this->config['parameters'] + )->setInput($prompt) + ) ->getOutput(); } }