From 7411ca35321c791b12d0cf3a1f1a84420e2cd7e9 Mon Sep 17 00:00:00 2001
From: guilhermeblanco <guilhermeblanco@625475ce-881a-0410-a577-b389adb331d8>
Date: Tue, 1 Sep 2009 13:43:53 +0000
Subject: [PATCH] [2.0] More work on CLI Tasks. Implemented HelpTask.

---
 lib/Doctrine/ORM/Tools/Cli.php                |  6 +++-
 lib/Doctrine/ORM/Tools/Cli/Tasks/HelpTask.php | 36 +++++++++++--------
 .../ORM/Tools/Cli/Tasks/VersionTask.php       | 15 ++++----
 3 files changed, 35 insertions(+), 22 deletions(-)

diff --git a/lib/Doctrine/ORM/Tools/Cli.php b/lib/Doctrine/ORM/Tools/Cli.php
index 0ad79cf26..51f1e5465 100644
--- a/lib/Doctrine/ORM/Tools/Cli.php
+++ b/lib/Doctrine/ORM/Tools/Cli.php
@@ -156,6 +156,10 @@ class Cli
         $processedArgs = $this->_processArguments($args);
         
         try {
+            $this->_printer->writeln(
+                'Doctrine Command Line Interface' . PHP_EOL, 'HEADER'
+            );
+        
             // Handle possible multiple tasks on a single command
             foreach($processedArgs as $taskData) {
                 // Retrieve the task name and arguments
@@ -182,7 +186,7 @@ class Cli
                 }
             }
         } catch (\Doctrine\Common\DoctrineException $e) {
-            $this->_printer->write(
+            $this->_printer->writeln(
                 $taskName . ':' . $e->getMessage() . PHP_EOL, 'ERROR'
             );
         }
diff --git a/lib/Doctrine/ORM/Tools/Cli/Tasks/HelpTask.php b/lib/Doctrine/ORM/Tools/Cli/Tasks/HelpTask.php
index 5ad52446a..4eb0584cd 100644
--- a/lib/Doctrine/ORM/Tools/Cli/Tasks/HelpTask.php
+++ b/lib/Doctrine/ORM/Tools/Cli/Tasks/HelpTask.php
@@ -21,6 +21,8 @@
  
 namespace Doctrine\ORM\Tools\Cli\Tasks;
 
+use Doctrine\Common\Util\Inflector;
+
 /**
  * CLI Task to display available commands help
  *
@@ -39,11 +41,7 @@ class HelpTask extends AbstractTask
      */
     public function extendedHelp()
     {
-        $this->getPrinter()->write('help extended help' . PHP_EOL, 'HEADER');
-        $this->getPrinter()->write('help extended help' . PHP_EOL, 'ERROR');
-        $this->getPrinter()->write('help extended help' . PHP_EOL, 'INFO');
-        $this->getPrinter()->write('help extended help' . PHP_EOL, 'COMMENT');
-        $this->getPrinter()->write('help extended help' . PHP_EOL, 'NONE');
+        $this->run();
     }
 
     /**
@@ -51,11 +49,7 @@ class HelpTask extends AbstractTask
      */
     public function basicHelp()
     {
-        $this->getPrinter()->write('help basic help' . PHP_EOL, 'HEADER');
-        $this->getPrinter()->write('help basic help' . PHP_EOL, 'ERROR');
-        $this->getPrinter()->write('help basic help' . PHP_EOL, 'INFO');
-        $this->getPrinter()->write('help basic help' . PHP_EOL, 'COMMENT');
-        $this->getPrinter()->write('help basic help' . PHP_EOL, 'NONE');
+        $this->run();
     }
 
     /**
@@ -72,10 +66,22 @@ class HelpTask extends AbstractTask
      */
     public function run()
     {
-        $this->getPrinter()->write('help run' . PHP_EOL, 'HEADER');
-        $this->getPrinter()->write('help run' . PHP_EOL, 'ERROR');
-        $this->getPrinter()->write('help run' . PHP_EOL, 'INFO');
-        $this->getPrinter()->write('help run' . PHP_EOL, 'COMMENT');
-        $this->getPrinter()->write('help run' . PHP_EOL, 'NONE');
+        // Switch between ALL available tasks and display the basic Help of each one
+        $availableTasks = $this->getAvailableTasks();
+        
+        $helpTaskName = Inflector::classify(str_replace('-', '_', 'help'));
+        unset($availableTasks[$helpTaskName]);
+        
+        ksort($availableTasks);
+        
+        foreach ($availableTasks as $taskName => $taskClass) {
+            $task = new $taskClass();
+            
+            $task->setAvailableTasks($availableTasks);
+            $task->setPrinter($this->getPrinter());
+            $task->setArguments($this->getArguments());
+            
+            $task->basicHelp();
+        }
     }
 }
\ No newline at end of file
diff --git a/lib/Doctrine/ORM/Tools/Cli/Tasks/VersionTask.php b/lib/Doctrine/ORM/Tools/Cli/Tasks/VersionTask.php
index 2b0008441..ef48e676e 100644
--- a/lib/Doctrine/ORM/Tools/Cli/Tasks/VersionTask.php
+++ b/lib/Doctrine/ORM/Tools/Cli/Tasks/VersionTask.php
@@ -39,11 +39,12 @@ class VersionTask extends AbstractTask
      */
     public function extendedHelp()
     {
-        $this->getPrinter()->write('version extended help' . PHP_EOL, 'HEADER');
+        $this->getPrinter()->writeln('version extended help.', 'INFO');
+        /*$this->getPrinter()->write('version extended help' . PHP_EOL, 'HEADER');
         $this->getPrinter()->write('version extended help' . PHP_EOL, 'ERROR');
         $this->getPrinter()->write('version extended help' . PHP_EOL, 'INFO');
         $this->getPrinter()->write('version extended help' . PHP_EOL, 'COMMENT');
-        $this->getPrinter()->write('version extended help' . PHP_EOL, 'NONE');
+        $this->getPrinter()->write('version extended help' . PHP_EOL, 'NONE');*/
     }
 
     /**
@@ -51,11 +52,12 @@ class VersionTask extends AbstractTask
      */
     public function basicHelp()
     {
-        $this->getPrinter()->write('version basic help' . PHP_EOL, 'HEADER');
+        $this->getPrinter()->writeln('version extended help.', 'INFO');
+        /*$this->getPrinter()->write('version basic help' . PHP_EOL, 'HEADER');
         $this->getPrinter()->write('version basic help' . PHP_EOL, 'ERROR');
         $this->getPrinter()->write('version basic help' . PHP_EOL, 'INFO');
         $this->getPrinter()->write('version basic help' . PHP_EOL, 'COMMENT');
-        $this->getPrinter()->write('version basic help' . PHP_EOL, 'NONE');
+        $this->getPrinter()->write('version basic help' . PHP_EOL, 'NONE');*/
     }
     
     /**
@@ -72,10 +74,11 @@ class VersionTask extends AbstractTask
      */
     public function run()
     {
-        $this->getPrinter()->write('version run' . PHP_EOL, 'HEADER');
+        $this->getPrinter()->writeln('version normal flow.', 'INFO');
+        /*$this->getPrinter()->write('version run' . PHP_EOL, 'HEADER');
         $this->getPrinter()->write('version run' . PHP_EOL, 'ERROR');
         $this->getPrinter()->write('version run' . PHP_EOL, 'INFO');
         $this->getPrinter()->write('version run' . PHP_EOL, 'COMMENT');
-        $this->getPrinter()->write('version run' . PHP_EOL, 'NONE');
+        $this->getPrinter()->write('version run' . PHP_EOL, 'NONE');*/
     }
 }
\ No newline at end of file