From ee759cbd5ec0027ac39b507c4c54d6e141af8155 Mon Sep 17 00:00:00 2001 From: Jonas Regner Date: Fri, 1 Dec 2023 13:15:55 +0100 Subject: [PATCH] feat: use laravel prompt --- composer.json | 3 ++- src/Commands/Abstracts/BaseCommand.php | 6 ++++-- src/Commands/MakeBuilderCommand.php | 13 +++++++------ src/NameResolver.php | 6 +++--- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 6bc7d04..65d7f4c 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,8 @@ "ext-fileinfo": "^8.2", "illuminate/support": "^10.0", "illuminate/console": "^10.0", - "illuminate/filesystem": "^10.0" + "illuminate/filesystem": "^10.0", + "laravel/prompts": "^0.1.13" }, "extra": { "laravel": { diff --git a/src/Commands/Abstracts/BaseCommand.php b/src/Commands/Abstracts/BaseCommand.php index a25af69..ab599eb 100644 --- a/src/Commands/Abstracts/BaseCommand.php +++ b/src/Commands/Abstracts/BaseCommand.php @@ -5,6 +5,8 @@ use AkrilliA\LaravelBeyond\NameResolver; use AkrilliA\LaravelBeyond\Type; use Illuminate\Console\Command; +use function Laravel\Prompts\error; +use function Laravel\Prompts\info; abstract class BaseCommand extends Command { @@ -85,13 +87,13 @@ public function handle(): void (bool) $this->option('force') ); - $this->components->info($this->getType()->getName()." [{$fqn->getPath()}] created successfully."); + info($this->getType()->getName()." [{$fqn->getPath()}] created successfully."); foreach ($this->onSuccess as $callback) { $callback($fqn->getNamespace(), $fqn->getClassName()); } } catch (\Exception $exception) { - $this->components->error($exception->getMessage()); + error($exception->getMessage()); } } } diff --git a/src/Commands/MakeBuilderCommand.php b/src/Commands/MakeBuilderCommand.php index 817d901..5c08554 100644 --- a/src/Commands/MakeBuilderCommand.php +++ b/src/Commands/MakeBuilderCommand.php @@ -5,6 +5,8 @@ use AkrilliA\LaravelBeyond\Commands\Abstracts\DomainCommand; use AkrilliA\LaravelBeyond\NameResolver; use AkrilliA\LaravelBeyond\Type; +use function Laravel\Prompts\info; +use function Laravel\Prompts\note; class MakeBuilderCommand extends DomainCommand { @@ -25,12 +27,11 @@ public function getType(): Type public function setup(NameResolver $fqn): void { $this->addOnSuccess(function (string $namespace, string $className) { - $this->info('Please add following code to your related model'); - $this->newLine(); - $this->info('public function newEloquentBuilder($query)'); - $this->info('{'); - $this->info("\t".'return new '.$className.'($query);'); - $this->info('}'); + info('Please add following code to your related model'); + note('public function newEloquentBuilder($query)'); + note('{'); + note("\t".'return new '.$className.'($query);'); + note('}'); }); } } diff --git a/src/NameResolver.php b/src/NameResolver.php index f06103b..5d46e6b 100644 --- a/src/NameResolver.php +++ b/src/NameResolver.php @@ -6,6 +6,7 @@ use AkrilliA\LaravelBeyond\Exceptions\InvalidNameException; use AkrilliA\LaravelBeyond\Exceptions\ModuleDoesNotExistsException; use Illuminate\Support\Str; +use function Laravel\Prompts\select; class NameResolver { @@ -58,10 +59,9 @@ private function init(): void $modules = beyond_get_choices(base_path('modules')); if ($numParts === 1) { - $this->module = $this->command->choice( + $this->module = select( 'On which module should we create your '.$this->command->getType()->getName().'?', - $modules, - attempts: 2 + $modules ); $this->setDirectoryAndClassName($parts[0]);