Skip to content

Commit

Permalink
fix: prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
regnerisch committed Dec 1, 2023
1 parent fb3a02b commit 14ad7de
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 2 additions & 5 deletions src/Commands/MakeBuilderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'}');
});
}
}
24 changes: 20 additions & 4 deletions src/NameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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]);
Expand Down

0 comments on commit 14ad7de

Please sign in to comment.