| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfListTask extends sfCommandApplicationTask |
|---|
| 20 |
{ |
|---|
| 21 |
|
|---|
| 22 |
* @see sfTask |
|---|
| 23 |
*/ |
|---|
| 24 |
protected function configure() |
|---|
| 25 |
{ |
|---|
| 26 |
$this->addArguments(array( |
|---|
| 27 |
new sfCommandArgument('namespace', sfCommandArgument::OPTIONAL, 'The namespace name'), |
|---|
| 28 |
)); |
|---|
| 29 |
|
|---|
| 30 |
$this->briefDescription = 'Lists tasks'; |
|---|
| 31 |
|
|---|
| 32 |
$this->detailedDescription = <<<EOF |
|---|
| 33 |
The [list|INFO] task lists all tasks: |
|---|
| 34 |
|
|---|
| 35 |
[./symfony list|INFO] |
|---|
| 36 |
|
|---|
| 37 |
You can also display the tasks for a specific namespace: |
|---|
| 38 |
|
|---|
| 39 |
[./symfony list test|INFO] |
|---|
| 40 |
EOF; |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
* @see sfTask |
|---|
| 45 |
*/ |
|---|
| 46 |
protected function execute($arguments = array(), $options = array()) |
|---|
| 47 |
{ |
|---|
| 48 |
$tasks = array(); |
|---|
| 49 |
foreach ($this->commandApplication->getTasks() as $name => $task) |
|---|
| 50 |
{ |
|---|
| 51 |
if ($arguments['namespace'] && $arguments['namespace'] != $task->getNamespace()) |
|---|
| 52 |
{ |
|---|
| 53 |
continue; |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
if ($name != $task->getFullName()) |
|---|
| 57 |
{ |
|---|
| 58 |
|
|---|
| 59 |
continue; |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
if (!$task->getNamespace()) |
|---|
| 63 |
{ |
|---|
| 64 |
$name = '_default:'.$name; |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
$tasks[$name] = $task; |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
$width = 0; |
|---|
| 71 |
foreach ($tasks as $name => $task) |
|---|
| 72 |
{ |
|---|
| 73 |
$width = strlen($task->getName()) > $width ? strlen($task->getName()) : $width; |
|---|
| 74 |
} |
|---|
| 75 |
$width += strlen($this->formatter->format(' ', 'INFO')); |
|---|
| 76 |
|
|---|
| 77 |
$messages = array(); |
|---|
| 78 |
if ($arguments['namespace']) |
|---|
| 79 |
{ |
|---|
| 80 |
$messages[] = $this->formatter->format(sprintf("Available tasks for the \"%s\" namespace:", $arguments['namespace']), 'COMMENT'); |
|---|
| 81 |
} |
|---|
| 82 |
else |
|---|
| 83 |
{ |
|---|
| 84 |
$messages[] = $this->formatter->format('Available tasks:', 'COMMENT'); |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
ksort($tasks); |
|---|
| 89 |
$currentNamespace = ''; |
|---|
| 90 |
foreach ($tasks as $name => $task) |
|---|
| 91 |
{ |
|---|
| 92 |
if (!$arguments['namespace'] && $currentNamespace != $task->getNamespace()) |
|---|
| 93 |
{ |
|---|
| 94 |
$currentNamespace = $task->getNamespace(); |
|---|
| 95 |
$messages[] = $this->formatter->format($task->getNamespace(), 'COMMENT'); |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
$aliases = $task->getAliases() ? $this->formatter->format(' ('.implode(', ', $task->getAliases()).')', 'COMMENT') : ''; |
|---|
| 99 |
|
|---|
| 100 |
$messages[] = sprintf(" %-${width}s %s%s", $this->formatter->format(':'.$task->getName(), 'INFO'), $task->getBriefDescription(), $aliases); |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
$this->log($messages); |
|---|
| 104 |
} |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|