Skip to content

Commit

Permalink
Switch tasks from using execute() to using main().
Browse files Browse the repository at this point in the history
This change unifies Tasks and Shells. It removes an un-necessary
convention that has little benefit but causes additional human mental
energy to remember. Removing it makes refactoring a shell into a task
easier.
  • Loading branch information
markstory committed Apr 24, 2014
1 parent 3e2282c commit 2b40223
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Console/Command/Task/BakeTask.php
Expand Up @@ -80,7 +80,7 @@ public function getPath() {
*
* @return void
*/
public function execute() {
public function main() {
foreach ($this->args as $i => $arg) {
if (strpos($arg, '.')) {
list($this->params['plugin'], $this->args[$i]) = pluginSplit($arg);
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Command/Task/ControllerTask.php
Expand Up @@ -44,8 +44,8 @@ class ControllerTask extends BakeTask {
*
* @return void
*/
public function execute($name = null) {
parent::execute();
public function main($name = null) {
parent::main();

if (!isset($this->connection)) {
$this->connection = 'default';
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Command/Task/ExtractTask.php
Expand Up @@ -145,7 +145,7 @@ protected function _getPaths() {
*
* @return void
*/
public function execute() {
public function main() {
if (!empty($this->params['exclude'])) {
$this->_exclude = explode(',', $this->params['exclude']);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Command/Task/FixtureTask.php
Expand Up @@ -90,8 +90,8 @@ public function getOptionParser() {
*
* @return void
*/
public function execute($name = null) {
parent::execute();
public function main($name = null) {
parent::main();
if (!isset($this->connection)) {
$this->connection = 'default';
}
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Command/Task/ModelTask.php
Expand Up @@ -75,8 +75,8 @@ class ModelTask extends BakeTask {
*
* @return void
*/
public function execute($name = null) {
parent::execute();
public function main($name = null) {
parent::main();

if (!isset($this->connection)) {
$this->connection = 'default';
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Command/Task/PluginTask.php
Expand Up @@ -56,7 +56,7 @@ public function initialize() {
*
* @return void
*/
public function execute($name = null) {
public function main($name = null) {
if (empty($name)) {
$this->err('<error>You must provide a plugin name in CamelCase format.</error>');
$this->err('To make an "Example" plugin, run <info>Console/cake bake plugin Example</info>.');
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Command/Task/ProjectTask.php
Expand Up @@ -41,7 +41,7 @@ class ProjectTask extends BakeTask {
*
* @return mixed
*/
public function execute() {
public function main() {
$project = null;
if (isset($this->args[0])) {
$project = $this->args[0];
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Command/Task/SimpleBakeTask.php
Expand Up @@ -72,8 +72,8 @@ public function templateData() {
*
* @return void
*/
public function execute($name = null) {
parent::execute();
public function main($name = null) {
parent::main();
if (empty($name)) {
return $this->error('You must provide a name to bake a ' . $this->name());
}
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Command/Task/TestTask.php
Expand Up @@ -81,8 +81,8 @@ class TestTask extends BakeTask {
*
* @return void
*/
public function execute($type = null, $name = null) {
parent::execute();
public function main($type = null, $name = null) {
parent::main();
if (empty($type) && empty($name)) {
return $this->outputTypeChoices();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Command/Task/ViewTask.php
Expand Up @@ -98,8 +98,8 @@ public function initialize() {
*
* @return mixed
*/
public function execute($name = null, $template = null, $action = null) {
parent::execute();
public function main($name = null, $template = null, $action = null) {
parent::main();

if (!isset($this->connection)) {
$this->connection = 'default';
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Shell.php
Expand Up @@ -381,7 +381,7 @@ public function runCommand($argv) {
if ($this->hasTask($command) && isset($subcommands[$command])) {
$this->startup();
$command = Inflector::camelize($command);
$argv[0] = 'execute';
array_shift($argv);
return $this->{$command}->runCommand($argv);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/Console/ShellTest.php
Expand Up @@ -715,10 +715,10 @@ public function testRunCommandHittingTaskInSubcommand() {
$parser->addSubcommand('slice');

$shell = $this->getMock('Cake\Console\Shell', ['hasTask', 'startup', 'getOptionParser'], [], '', false);
$task = $this->getMock('Cake\Console\Shell', ['execute', 'runCommand'], [], '', false);
$task->expects($this->any())
$task = $this->getMock('Cake\Console\Shell', ['main', 'runCommand'], [], '', false);
$task->expects($this->once())
->method('runCommand')
->with(['execute', 'one']);
->with(['one']);

$shell->expects($this->once())->method('getOptionParser')
->will($this->returnValue($parser));
Expand Down

0 comments on commit 2b40223

Please sign in to comment.