Skip to content

Commit

Permalink
Introducing Artisan Find Command
Browse files Browse the repository at this point in the history
  • Loading branch information
devajmeireles committed Sep 17, 2024
1 parent 0d0f55f commit 0f4f4b1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/Illuminate/Foundation/Console/FindCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Illuminate\Foundation\Console;

use Illuminate\Console\Command;
use Symfony\Component\Console\Attribute\AsCommand;

use function Laravel\Prompts\suggest;

#[AsCommand(name: 'find')]
class FindCommand extends Command
{
/**
* The console command signature.
*
* @var string
*/
protected $signature = 'find';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Find an Artisan command.';


/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
$commands = collect(array_keys($this->getApplication()->all()))
->filter(fn (string $command) => $command !== $this->signature)
->values();

$command = suggest(
'Search for a command',
options: $commands->toArray(),
required: true,
hint: 'Type parts of a command name to search for'
);

$this->call($command);

return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
use Illuminate\Foundation\Console\EventListCommand;
use Illuminate\Foundation\Console\EventMakeCommand;
use Illuminate\Foundation\Console\ExceptionMakeCommand;
use Illuminate\Foundation\Console\FindCommand;
use Illuminate\Foundation\Console\InterfaceMakeCommand;
use Illuminate\Foundation\Console\JobMakeCommand;
use Illuminate\Foundation\Console\KeyGenerateCommand;
Expand Down Expand Up @@ -136,6 +137,7 @@ class ArtisanServiceProvider extends ServiceProvider implements DeferrableProvid
'EventCache' => EventCacheCommand::class,
'EventClear' => EventClearCommand::class,
'EventList' => EventListCommand::class,
'Find' => FindCommand::class,
'InvokeSerializedClosure' => InvokeSerializedClosureCommand::class,
'KeyGenerate' => KeyGenerateCommand::class,
'Optimize' => OptimizeCommand::class,
Expand Down

0 comments on commit 0f4f4b1

Please sign in to comment.