Skip to content

Commit

Permalink
Merge pull request #1008 from mbrodala/get-defined-task
Browse files Browse the repository at this point in the history
Add a way to retrieve a defined task
  • Loading branch information
antonmedv authored Feb 13, 2017
2 parents d2cbc89 + 2b5e0cc commit 0fd8254
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
## master
[v4.2.1...master](https://github.com/deployphp/deployer/compare/v4.2.1...master)

### Added
- Add a way to retrieve a defined task [#1008](https://github.com/deployphp/deployer/pull/1008)

### Fixed
- Fixed scalar override on recursive option merge [#1003](https://github.com/deployphp/deployer/pull/1003)

Expand Down
11 changes: 9 additions & 2 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,22 @@ function desc($title = null)
/**
* Define a new task and save to tasks list.
*
* Alternatively get a defined task.
*
* @param string $name Name of current task.
* @param callable|array|string $body Callable task or array of other tasks names.
* @param callable|array|string|null $body Callable task, array of other tasks names or nothing to get a defined tasks
* @return Task\Task
* @throws \InvalidArgumentException
*/
function task($name, $body)
function task($name, $body = null)
{
$deployer = Deployer::get();

if (empty($body)) {
$task = $deployer->tasks->get($name);
return $task;
}

if ($body instanceof \Closure) {
$task = new T($name, $body);
} elseif (is_array($body)) {
Expand Down
3 changes: 3 additions & 0 deletions test/src/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ public function testTask()
$task = $this->deployer->tasks->get('task');
$this->assertInstanceOf('Deployer\Task\Task', $task);

$task = task('task');
$this->assertInstanceOf('Deployer\Task\Task', $task);

task('group', ['task']);
$task = $this->deployer->tasks->get('group');
$this->assertInstanceOf('Deployer\Task\GroupTask', $task);
Expand Down

0 comments on commit 0fd8254

Please sign in to comment.