Skip to content

Commit

Permalink
Add getDescription() to command template
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Oct 8, 2024
1 parent b6ced75 commit 8be277c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
17 changes: 13 additions & 4 deletions templates/bake/Command/command.twig
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,27 @@
*/
class {{ name }}Command extends Command
{
/**
* Get the command description.
*
* @return string
*/
public static function getDescription(): string
{
return 'Command description here.';
}

/**
* Hook method for defining this command's option parser.
*
* @see https://book.cakephp.org/4/en/console-commands/commands.html#defining-arguments-and-options
* @see https://book.cakephp.org/5/en/console-commands/commands.html#defining-arguments-and-options
* @param \Cake\Console\ConsoleOptionParser $parser The parser to be defined
* @return \Cake\Console\ConsoleOptionParser The built parser.
*/
public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
{
$parser = parent::buildOptionParser($parser);

return $parser;
return parent::buildOptionParser($parser)
->setDescription(static::getDescription());
}

/**
Expand Down
17 changes: 13 additions & 4 deletions tests/comparisons/Command/testBakePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,27 @@
*/
class ExampleCommand extends Command
{
/**
* Get the command description.
*
* @return string
*/
public static function getDescription(): string
{
return 'Command description here.';
}

/**
* Hook method for defining this command's option parser.
*
* @see https://book.cakephp.org/4/en/console-commands/commands.html#defining-arguments-and-options
* @see https://book.cakephp.org/5/en/console-commands/commands.html#defining-arguments-and-options
* @param \Cake\Console\ConsoleOptionParser $parser The parser to be defined
* @return \Cake\Console\ConsoleOptionParser The built parser.
*/
public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
{
$parser = parent::buildOptionParser($parser);

return $parser;
return parent::buildOptionParser($parser)
->setDescription(static::getDescription());
}

/**
Expand Down

0 comments on commit 8be277c

Please sign in to comment.