Skip to content

Commit

Permalink
Factor out createCommandsFromClass
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-1-anderson committed Mar 23, 2016
1 parent efae2f5 commit a0df446
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ public function addCommandsFromClass($className, $passThrough = null)
$roboTasks->setContainer($container);
}

$commandList = $this->createCommandsFromClass($roboTasks, $passThrough);
foreach ($commandList as $command) {
$this->add($command);
}
}

public function createCommandsFromClass($roboTasks, $passThrough = null)
{
$className = get_class($roboTasks);
$commandList = [];

// Ignore special functions, such as __construct() and __call(), and
// accessor methods such as getFoo() and setFoo(), while allowing
// set or setup.
Expand All @@ -40,7 +51,7 @@ public function addCommandsFromClass($className, $passThrough = null)

foreach ($commandNames as $commandName) {
$command = $this->createCommand(new TaskInfo($className, $commandName));
$command->setCode(function (InputInterface $input) use ($roboTasks, $commandName, $passThrough, $container) {
$command->setCode(function (InputInterface $input) use ($roboTasks, $commandName, $passThrough) {
// get passthru args
$args = $input->getArguments();
array_shift($args);
Expand All @@ -60,8 +71,9 @@ public function addCommandsFromClass($className, $passThrough = null)
exit($res->getExitCode());
}
});
$this->add($command);
$commandList[] = $command;
}
return $commandList;
}

public function createCommand(TaskInfo $taskInfo)
Expand Down

0 comments on commit a0df446

Please sign in to comment.