Development

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

You must first sign up to be able to contribute.

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

Revision 11505, 2.7 kB (checked in by fabien, 6 years ago)

[1.2] added symfony help message before tasks when calling symfony without any option (closes #4218)

  • 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     $this->commandApplication->help();
49     $this->log('');
50
51     $tasks = array();
52     foreach ($this->commandApplication->getTasks() as $name => $task)
53     {
54       if ($arguments['namespace'] && $arguments['namespace'] != $task->getNamespace())
55       {
56         continue;
57       }
58
59       if ($name != $task->getFullName())
60       {
61         // it is an alias
62         continue;
63       }
64
65       if (!$task->getNamespace())
66       {
67         $name = '_default:'.$name;
68       }
69
70       $tasks[$name] = $task;
71     }
72
73     $width = 0;
74     foreach ($tasks as $name => $task)
75     {
76       $width = strlen($task->getName()) > $width ? strlen($task->getName()) : $width;
77     }
78     $width += strlen($this->formatter->format('  ', 'INFO'));
79
80     $messages = array();
81     if ($arguments['namespace'])
82     {
83       $messages[] = $this->formatter->format(sprintf("Available tasks for the \"%s\" namespace:", $arguments['namespace']), 'COMMENT');
84     }
85     else
86     {
87       $messages[] = $this->formatter->format('Available tasks:', 'COMMENT');
88     }
89
90     // display tasks
91     ksort($tasks);
92     $currentNamespace = '';
93     foreach ($tasks as $name => $task)
94     {
95       if (!$arguments['namespace'] && $currentNamespace != $task->getNamespace())
96       {
97         $currentNamespace = $task->getNamespace();
98         $messages[] = $this->formatter->format($task->getNamespace(), 'COMMENT');
99       }
100
101       $aliases = $task->getAliases() ? $this->formatter->format(' ('.implode(', ', $task->getAliases()).')', 'COMMENT') : '';
102
103       $messages[] = sprintf("  %-${width}s %s%s", $this->formatter->format(':'.$task->getName(), 'INFO'), $task->getBriefDescription(), $aliases);
104     }
105
106     $this->log($messages);
107   }
108 }
109
Note: See TracBrowser for help on using the browser.