From 8be277cd215333f201de95a426f4c86ad32c1c54 Mon Sep 17 00:00:00 2001 From: ADmad Date: Tue, 8 Oct 2024 12:04:52 +0530 Subject: [PATCH] Add getDescription() to command template --- templates/bake/Command/command.twig | 17 +++++++++++++---- tests/comparisons/Command/testBakePlugin.php | 17 +++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/templates/bake/Command/command.twig b/templates/bake/Command/command.twig index fe126f6c..3654c334 100644 --- a/templates/bake/Command/command.twig +++ b/templates/bake/Command/command.twig @@ -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()); } /** diff --git a/tests/comparisons/Command/testBakePlugin.php b/tests/comparisons/Command/testBakePlugin.php index c762139d..da518ce2 100644 --- a/tests/comparisons/Command/testBakePlugin.php +++ b/tests/comparisons/Command/testBakePlugin.php @@ -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()); } /**