From 0e4cc94471e122a1ab0ed8e54576195310cf5a77 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Fri, 17 Mar 2023 10:58:23 +0000 Subject: [PATCH] feat: improve `--init` command --- src/Console/Thanks.php | 11 +++++++---- src/Plugins/Init.php | 12 ++++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/Console/Thanks.php b/src/Console/Thanks.php index cd149a0d..342df2e1 100644 --- a/src/Console/Thanks.php +++ b/src/Console/Thanks.php @@ -8,6 +8,7 @@ use Pest\Bootstrappers\BootView; use Pest\Support\View; use Symfony\Component\Console\Helper\SymfonyQuestionHelper; use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; @@ -30,8 +31,10 @@ final class Thanks /** * Creates a new Console Command instance. */ - public function __construct(private readonly OutputInterface $output) - { + public function __construct( + private readonly InputInterface $input, + private readonly OutputInterface $output + ) { // .. } @@ -43,11 +46,11 @@ final class Thanks $bootstrapper = new BootView($this->output); $bootstrapper->boot(); - $wantsToSupport = (new SymfonyQuestionHelper())->ask( + $wantsToSupport = $this->input->isInteractive() && (new SymfonyQuestionHelper())->ask( new ArrayInput([]), $this->output, new ConfirmationQuestion( - ' Would you like to show your support by starring the project on GitHub?', + ' Wanna show Pest some love by starring it on GitHub?', true, ) ); diff --git a/src/Plugins/Init.php b/src/Plugins/Init.php index 07c78cc1..aa66df09 100644 --- a/src/Plugins/Init.php +++ b/src/Plugins/Init.php @@ -9,6 +9,7 @@ use Pest\Console\Thanks; use Pest\Contracts\Plugins\HandlesArguments; use Pest\Support\View; use Pest\TestSuite; +use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Process\Process; @@ -38,6 +39,7 @@ final class Init implements HandlesArguments */ public function __construct( private readonly TestSuite $testSuite, + private readonly InputInterface $input, private readonly OutputInterface $output ) { // .. @@ -54,6 +56,7 @@ final class Init implements HandlesArguments if ($arguments[1] !== self::INIT_OPTION) { return $arguments; } + unset($arguments[1]); $this->init(); @@ -61,7 +64,10 @@ final class Init implements HandlesArguments return array_values($arguments); } - private function init(): void + /** + * Initializes the tests directory. + */ + private function init(): never { $testsBaseDir = "{$this->testSuite->rootPath}/tests"; @@ -92,6 +98,8 @@ final class Init implements HandlesArguments continue; } + @mkdir(dirname($toPath)); + copy($fromPath, $toPath); View::render('components.two-column-detail', [ @@ -102,7 +110,7 @@ final class Init implements HandlesArguments View::render('components.new-line'); - (new Thanks($this->output))(); + (new Thanks($this->input, $this->output))(); exit(0); }