Skip to content

Commit

Permalink
[10.x] Generate default command name based on class name (#46256)
Browse files Browse the repository at this point in the history
* [10.x] Generate default command name based on class name

* formatting

* formatting

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
iamgergo and taylorotwell authored Feb 25, 2023
1 parent 2c4a4e7 commit 3b7f6d0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Illuminate/Foundation/Console/ConsoleMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Console\Concerns\CreatesMatchingTest;
use Illuminate\Console\GeneratorCommand;
use Illuminate\Support\Str;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -45,7 +46,9 @@ protected function replaceClass($stub, $name)
{
$stub = parent::replaceClass($stub, $name);

return str_replace(['dummy:command', '{{ command }}'], $this->option('command'), $stub);
$command = $this->option('command') ?: 'app:'.Str::of($name)->classBasename()->kebab()->value();

return str_replace(['dummy:command', '{{ command }}'], $command, $stub);
}

/**
Expand Down Expand Up @@ -94,7 +97,7 @@ protected function getOptions()
{
return [
['force', 'f', InputOption::VALUE_NONE, 'Create the class even if the console command already exists'],
['command', null, InputOption::VALUE_OPTIONAL, 'The terminal command that should be assigned', 'command:name'],
['command', null, InputOption::VALUE_OPTIONAL, 'The terminal command that will be used to invoke the class'],
];
}
}

0 comments on commit 3b7f6d0

Please sign in to comment.