Skip to content

Commit

Permalink
feat: use laravel prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
regnerisch committed Dec 1, 2023
1 parent fb37108 commit ee759cb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 4 additions & 2 deletions src/Commands/Abstracts/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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());
}
}
}
13 changes: 7 additions & 6 deletions src/Commands/MakeBuilderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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('}');
});
}
}
6 changes: 3 additions & 3 deletions src/NameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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]);
Expand Down

0 comments on commit ee759cb

Please sign in to comment.