Development

/branches/1.1/lib/task/help/sfListTask.class.php

You must first sign up to be able to contribute.

root/branches/1.1/lib/task/help/sfListTask.class.php

Revision 7397, 2.6 kB (checked in by fabien, 6 years ago)

added sfTask::log() and sfTask::logSection() shortcuts

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * Lists tasks.
13  *
14  * @package    symfony
15  * @subpackage task
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
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         // it is an alias
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     // display tasks
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
Note: See TracBrowser for help on using the browser.