- Handle "-" in command-line controller names automatically
authorChuck Hagenbuch <chuck@horde.org>
Sat, 30 May 2009 15:02:48 +0000 (11:02 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Sat, 30 May 2009 15:02:48 +0000 (11:02 -0400)
- Allow much more flexibility in setting the path for command line requests

framework/Controller/lib/Horde/Controller/Request/Cli.php

index a0ec810..ea3dd78 100644 (file)
@@ -36,15 +36,7 @@ class Horde_Controller_Request_Cli extends Horde_Controller_Request_Base
     {
         parent::__construct($options);
 
-        $parser = new Horde_Argv_Parser(array(
-            'allowUnknownArgs' => true,
-            'addHelpOption' => false,
-        ));
-        list($this->_argv, $args) = $parser->parseArgs();
-        if (!count($args)) {
-            throw new Horde_Controller_Exception('unknown command: ' . implode(' ', $args));
-        }
-        $this->_path = $args[0];
+        $this->setPath();
     }
 
     public function getUri()
@@ -57,6 +49,29 @@ class Horde_Controller_Request_Cli extends Horde_Controller_Request_Base
         return $this->_path;
     }
 
+    public function setPath($args = null)
+    {
+        if (is_string($args)) {
+            $this->_path = $args;
+        } else {
+            if ($args instanceof Horde_Argv_Parser) {
+                $parser = $args;
+            } else {
+                $parser = new Horde_Argv_Parser(array(
+                    'allowUnknownArgs' => true,
+                    'addHelpOption' => false,
+                ));
+            }
+
+            list($this->_argv, $args) = $parser->parseArgs();
+            if (!count($args)) {
+                throw new Horde_Controller_Exception('unknown command: ' . implode(' ', $args));
+            }
+            $this->_path = $args[0];
+            $this->_path = str_replace('-', '_', $this->_path);
+        }
+    }
+
     /**
      * Get all command line parameters.
      * some wacky loops to make sure that nested values in one