diff --git a/CHANGELOG.md b/CHANGELOG.md index 29bd2bf..62f05ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Add missing changes in CHANGELOG.md by [@regnerisch](https://github.com/regnerisch) +### Changed +- Change module selection by [@regnerisch](https://github.com/regnerisch) + ## [7.0.0-beta.5] ### Added - Add tests by [@alexanderkroneis](https://github.com/alexanderkroneis) diff --git a/src/Commands/MakeBuilderCommand.php b/src/Commands/MakeBuilderCommand.php index b2187b1..463a73a 100644 --- a/src/Commands/MakeBuilderCommand.php +++ b/src/Commands/MakeBuilderCommand.php @@ -28,11 +28,8 @@ public function getType(): Type public function setup(NameResolver $fqn): void { $this->addOnSuccess(function (string $namespace, string $className) { - info('Please add following code to your related model'); - note('public function newEloquentBuilder($query)'); - note('{'); - note("\t".'return new '.$className.'($query);'); - note('}'); + info('Please add following code to your related model:'); + note('public function newEloquentBuilder($query)'.PHP_EOL.'{'.PHP_EOL."\t".'return new '.$className.'($query);'.PHP_EOL.'}'); }); } } diff --git a/src/NameResolver.php b/src/NameResolver.php index 4c3cbba..a693757 100644 --- a/src/NameResolver.php +++ b/src/NameResolver.php @@ -7,7 +7,7 @@ use AkrilliA\LaravelBeyond\Exceptions\ModuleDoesNotExistsException; use Illuminate\Support\Str; -use function Laravel\Prompts\select; +use function Laravel\Prompts\search; class NameResolver { @@ -60,9 +60,25 @@ private function init(): void $modules = beyond_get_choices(base_path('modules')); if ($numParts === 1) { - $this->module = select( - 'On which module should we create your '.$this->command->getType()->getName().'?', - $modules + $this->module = search( + 'Please select a module for your '.$this->command->getType()->getName().'?', + function (string $value) use ($modules) { + if ($value !== '') { + return array_values( + array_filter( + $modules, + static fn ($module) => Str::startsWith(Str::lower($module), Str::lower($value)) + ) + ); + } + + return $modules; + }, + validate: function (string $value) use ($modules) { + if (! in_array($value, $modules)) { + return 'The given module does not exist.'; + } + } ); $this->setDirectoryAndClassName($parts[0]);