Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.2.0

Request #16370 Allow pre-processing of arguments for lists.
Submitted: 2009-06-23 14:42 UTC Modified: 2009-11-11 17:55 UTC
From: rquadling Assigned: izi
Status: Closed Package: Console_CommandLine (version 1.1.0)
PHP Version: 5_3 CVS-2009-06-23 OS: Windows XP SP3
Roadmaps: (Not assigned)    
Subscription  



Patch allow-formatting-of-choice Revisions
Revision 2009-08-18 13:11 UTC
Developer rquadling
 
Download patch

This patch is obsolete

Obsoleted by patches:

This patch renders other patches obsolete

Obsolete patches:

Index: trunk/Console/CommandLine.php
===================================================================
--- trunk/Console/CommandLine.php	(revision 287440)
+++ trunk/Console/CommandLine.php	(working copy)
@@ -277,8 +277,8 @@
      *     'name'               => 'yourprogram', // defaults to argv[0]
      *     'description'        => 'Description of your program',
      *     'version'            => '0.0.1', // your program version
-     *     'add_help_option'    => true, // or false to disable --version option
-     *     'add_version_option' => true, // or false to disable --help option
+     *     'add_help_option'    => true, // or false to disable --help option
+     *     'add_version_option' => true, // or false to disable --version option
      *     'force_posix'        => false // or true to force posix compliance
      * ));
      * </code>
Index: trunk/Console/CommandLine/Action.php
===================================================================
--- trunk/Console/CommandLine/Action.php	(revision 287440)
+++ trunk/Console/CommandLine/Action.php	(working copy)
@@ -95,9 +95,24 @@
     }
 
     // }}}
-    // setResult() {{{
+    // format() {{{
 
     /**
+     * Allow a value to be pre-formatted prior to being used in a choices test.
+     * Setting $value to the new format will keep the formatting.
+     *
+     * @param mixed &$value The value to format
+     *
+     * @return mixed The supplied value
+     */
+    public function format(&$value)
+    {
+        return $value;
+    }
+
+    // }}}    // setResult() {{{
+
+    /**
      * Convenience method to assign the result->options[name] value.
      *
      * @param mixed $result The result value
Index: trunk/Console/CommandLine/Option.php
===================================================================
--- trunk/Console/CommandLine/Option.php	(revision 287440)
+++ trunk/Console/CommandLine/Option.php	(working copy)
@@ -240,8 +240,19 @@
      */
     public function dispatchAction($value, $result, $parser)
     {
+        $actionInfo = Console_CommandLine::$actions[$this->action];
+        if (true === $actionInfo[1]) {
+            // we have a "builtin" action
+            $tokens = explode('_', $actionInfo[0]);
+            include_once implode('/', $tokens) . '.php';
+        }
+        $clsname = $actionInfo[0];
+        if ($this->_action_instance === null) {
+            $this->_action_instance  = new $clsname($result, $this, $parser);
+        }
+
         // check value is in option choices
-        if (!empty($this->choices) && !in_array($value, $this->choices)) {
+        if (!empty($this->choices) && !in_array($this->_action_instance->format($value), $this->choices)) {
             throw Console_CommandLine_Exception::factory(
                 'OPTION_VALUE_NOT_VALID',
                 array(
@@ -253,16 +264,6 @@
                 $this->messages
             );
         }
-        $actionInfo = Console_CommandLine::$actions[$this->action];
-        if (true === $actionInfo[1]) {
-            // we have a "builtin" action
-            $tokens = explode('_', $actionInfo[0]);
-            include_once implode('/', $tokens) . '.php';
-        }
-        $clsname = $actionInfo[0];
-        if ($this->_action_instance === null) {
-            $this->_action_instance  = new $clsname($result, $this, $parser);
-        }
         $this->_action_instance->execute($value, $this->action_params);
     }