Skip to content

Commit

Permalink
Merge pull request #1030 from cakephp/command-name
Browse files Browse the repository at this point in the history
Set the name for baked commands
  • Loading branch information
markstory authored Jan 30, 2025
2 parents 13de03b + 243e2e0 commit 210bcba
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Command/CommandCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
namespace Bake\Command;

use Cake\Console\Arguments;
use Cake\Utility\Inflector;

/**
* Console Command generator.
*/
Expand Down Expand Up @@ -51,4 +54,24 @@ public function template(): string
{
return 'Bake.Command/command';
}

/**
* Get template data.
*
* @param \Cake\Console\Arguments $arguments Arguments object.
* @return array
* @phpstan-return array<string, mixed>
*/
public function templateData(Arguments $arguments): array
{
$data = parent::templateData($arguments);

$data['command_name'] = Inflector::underscore(str_replace(
'.',
' ',
$arguments->getArgument('name')
));

return $data;
}
}
17 changes: 17 additions & 0 deletions templates/bake/Command/command.twig
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@
*/
class {{ name }}Command extends Command
{
/**
* The name of this command.
*
* @var string
*/
protected string $name = '{{ command_name }}';

/**
* Get the default command name.
*
* @return string
*/
public static function defaultName(): string
{
return '{{ command_name }}';
}

/**
* Get the command description.
*
Expand Down
17 changes: 17 additions & 0 deletions tests/comparisons/Command/testBakePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@
*/
class ExampleCommand extends Command
{
/**
* The name of this command.
*
* @var string
*/
protected string $name = 'test_bake example';

/**
* Get the default command name.
*
* @return string
*/
public static function defaultName(): string
{
return 'test_bake example';
}

/**
* Get the command description.
*
Expand Down

0 comments on commit 210bcba

Please sign in to comment.