Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to retrieve a defined task #1008

Merged
merged 2 commits into from
Feb 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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