Skip to content

Commit

Permalink
Merge pull request #746 from miketallroth/plugin-common-options
Browse files Browse the repository at this point in the history
Add Common Options to Plugin Command
  • Loading branch information
ADmad authored Apr 21, 2021
2 parents 8650c88 + 5f2b032 commit 0e679c7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/Command/PluginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,15 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar
])->addOption('composer', [
'default' => ROOT . DS . 'composer.phar',
'help' => 'The path to the composer executable.',
])->addOption('force', [
'short' => 'f',
'boolean' => true,
'help' => 'Force overwriting existing files without prompting.',
])->addOption('theme', [
'short' => 't',
'help' => 'The theme to use when baking code.',
'default' => Configure::read('Bake.theme') ?? '',
'choices' => $this->_getBakeThemes(),
]);

return $parser;
Expand Down
2 changes: 2 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ protected function discoverCommands(CommandCollection $commands): CommandCollect
* @param string $path The path to look in.
* @return string[]
* @phpstan-return class-string<\Bake\Command\BakeCommand>[]
* @psalm-suppress InvalidReturnType
*/
protected function findInPath(string $namespace, string $path): array
{
Expand Down Expand Up @@ -152,6 +153,7 @@ protected function findInPath(string $namespace, string $path): array
$candidates[$class::defaultName()] = $class;
}

/** @psalm-suppress InvalidReturnStatement */
return $candidates;
}
}
20 changes: 15 additions & 5 deletions src/Utility/CommonOptionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,11 @@ protected function extractCommonProperties(Arguments $args): void
}

/**
* Set common options used by all bake tasks.
* Get available bake themes
*
* @param \Cake\Console\ConsoleOptionParser $parser Options parser.
* @return \Cake\Console\ConsoleOptionParser
* @return array
*/
protected function _setCommonOptions(ConsoleOptionParser $parser): ConsoleOptionParser
protected function _getBakeThemes(): array
{
$bakeThemes = [];
$templates = 'templates' . DS . 'bake';
Expand All @@ -89,6 +88,17 @@ protected function _setCommonOptions(ConsoleOptionParser $parser): ConsoleOption
}
}

return $bakeThemes;
}

/**
* Set common options used by all bake tasks.
*
* @param \Cake\Console\ConsoleOptionParser $parser Options parser.
* @return \Cake\Console\ConsoleOptionParser
*/
protected function _setCommonOptions(ConsoleOptionParser $parser): ConsoleOptionParser
{
$parser->addOption('plugin', [
'short' => 'p',
'help' => 'Plugin to bake into.',
Expand All @@ -104,7 +114,7 @@ protected function _setCommonOptions(ConsoleOptionParser $parser): ConsoleOption
'short' => 't',
'help' => 'The theme to use when baking code.',
'default' => Configure::read('Bake.theme') ?? '',
'choices' => $bakeThemes,
'choices' => $this->_getBakeThemes(),
]);

return $parser;
Expand Down

0 comments on commit 0e679c7

Please sign in to comment.