From e2e53632b0e9a40a5a925b4470e8981d86c4c736 Mon Sep 17 00:00:00 2001 From: AD7six Date: Wed, 12 Nov 2014 22:18:40 +0000 Subject: [PATCH] let users know which themes are available This also means users get a standard error message if they use a theme that doesn't exist: -> bin/cake bake controller posts --theme asdf Error: "asdf" is not a valid value for --theme. Please use one of ... --- src/Shell/BakeShell.php | 11 ++++++++++- src/Shell/Task/BakeTask.php | 17 ++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Shell/BakeShell.php b/src/Shell/BakeShell.php index ba9bffe8429..54538bc1987 100644 --- a/src/Shell/BakeShell.php +++ b/src/Shell/BakeShell.php @@ -231,6 +231,14 @@ public function all($name = null) { public function getOptionParser() { $parser = parent::getOptionParser(); + $bakeThemes = []; + foreach (Plugin::loaded() as $plugin) { + $path = Plugin::classPath($plugin); + if (is_dir($path . 'Template' . DS . 'Bake')) { + $bakeThemes[] = $plugin; + } + } + $parser->description( 'The Bake script generates controllers, views and models for your application.' . ' If run with no command line arguments, Bake guides the user through the class creation process.' . @@ -243,7 +251,8 @@ public function getOptionParser() { 'default' => 'default' ])->addOption('theme', [ 'short' => 't', - 'help' => 'Theme to use when baking code.' + 'help' => 'The theme to use when baking code.', + 'choices' => $bakeThemes ]); foreach ($this->_taskMap as $task => $config) { diff --git a/src/Shell/Task/BakeTask.php b/src/Shell/Task/BakeTask.php index 8941158200b..65f819fe1c9 100644 --- a/src/Shell/Task/BakeTask.php +++ b/src/Shell/Task/BakeTask.php @@ -18,6 +18,7 @@ use Cake\Console\Shell; use Cake\Core\Configure; use Cake\Core\ConventionsTrait; +use Cake\Core\Plugin; use Cake\Filesystem\File; /** @@ -183,6 +184,15 @@ protected function _deleteEmptyFile($path) { */ public function getOptionParser() { $parser = parent::getOptionParser(); + + $bakeThemes = []; + foreach (Plugin::loaded() as $plugin) { + $path = Plugin::classPath($plugin); + if (is_dir($path . 'Template' . DS . 'Bake')) { + $bakeThemes[] = $plugin; + } + } + $parser->addOption('plugin', [ 'short' => 'p', 'help' => 'Plugin to bake into.' @@ -194,11 +204,12 @@ public function getOptionParser() { 'short' => 'c', 'default' => 'default', 'help' => 'The datasource connection to get data from.' - ])->addOption('template', [ + ])->addOption('theme', [ 'short' => 't', - 'default' => 'default', - 'help' => 'Template to use when baking code.' + 'help' => 'The theme to use when baking code.', + 'choices' => $bakeThemes ]); + return $parser; }