Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Generate default command name based on class name #46256

Merged
merged 3 commits into from
Feb 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'],
];
}
}