Skip to content

Commit

Permalink
Merge pull request #124 from openeuropa/exec-task
Browse files Browse the repository at this point in the history
Add a new 'exec' task for dynamic commands
  • Loading branch information
idimopoulos authored May 19, 2020
2 parents c9a6d9a + ae1c03f commit 4d1884e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Tasks/CollectionFactory/CollectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public function getHelp()
protected function taskFactory($task)
{
if (is_string($task)) {
@trigger_error('Defining a task as a plain text is deprecated in openeuropa/task-runner:1.0.0 and is removed from openeuropa/task-runner:2.0.0. Use the "exec" task and pass arguments and options.', E_USER_DEPRECATED);
return $this->taskExec($task)->interactive($this->isTtySupported());
}

Expand Down Expand Up @@ -202,6 +203,19 @@ protected function taskFactory($task)

return $this->collectionBuilder()->addTaskList($tasks);

case 'exec':
$taskExec = $this->taskExec($task['command'])->interactive($this->isTtySupported());
if (!empty($task['arguments'])) {
$taskExec->args($task['arguments']);
}
if (!empty($task['options'])) {
$taskExec->options($task['options']);
}
if (!empty($task['dir'])) {
$taskExec->dir($task['dir']);
}
return $taskExec;

default:
throw new TaskException($this, "Task '{$task['task']}' not supported.");
}
Expand Down
26 changes: 26 additions & 0 deletions tests/Tasks/CollectionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,32 @@ public function testRunTask()
$this->assertSame(__METHOD__, file_get_contents($filePath));
}

/**
* Tests the 'exec' task.
*/
public function testExecTask(): void
{
$tasks = [
[
'task' => 'exec',
'command' => 'touch',
'arguments' => [
'file.txt',
],
'options' => [
// 1980-06-06 23:59:59.
'-t' => '198006062359.59'
],
'dir' => $this->getSandboxRoot(),
],
];
$this->taskCollectionFactory($tasks)->run();

$this->assertFileExists($this->getSandboxFilepath('file.txt'));
$mtime = gmdate('Y-m-d H:i:s', filemtime($this->getSandboxFilepath('file.txt')));
$this->assertSame('1980-06-06 23:59:59', $mtime);
}

/**
* @return array
*/
Expand Down

0 comments on commit 4d1884e

Please sign in to comment.