Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 ...
  • Loading branch information
AD7six committed Nov 14, 2014
1 parent 780ede5 commit e2e5363
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/Shell/BakeShell.php
Expand Up @@ -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.' .
Expand All @@ -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) {
Expand Down
17 changes: 14 additions & 3 deletions src/Shell/Task/BakeTask.php
Expand Up @@ -18,6 +18,7 @@
use Cake\Console\Shell;
use Cake\Core\Configure;
use Cake\Core\ConventionsTrait;
use Cake\Core\Plugin;
use Cake\Filesystem\File;

/**
Expand Down Expand Up @@ -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.'
Expand All @@ -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;
}

Expand Down

0 comments on commit e2e5363

Please sign in to comment.