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

Request #15324 Add ability to set custom error messages
Submitted: 2008-12-16 21:55 UTC
From: gauthierm Assigned: izi
Status: Closed Package: Console_CommandLine (version CVS)
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  


 [2008-12-16 21:55 UTC] gauthierm (Michael Gauthier)
Description: ------------ There is no way to have custom error messages for missing arguments, options, etc. For example, I'm defining a sub-command `create' which requires a name argument. Using the documentation, I see I can catch an exception and display its message, resulting in the following: "Error: You must provide at least 1 argument." What I'd really like to display to the user here is: "No queue name specified." After discussing with David, it seems the best way to implement this would be to create different exception classes and provide a method to get the error element. * Console_CommandLine_Exception * Console_CommandLine_OptionException::getErrorElement() * Console_CommandLine_ArgumentException::getErrorElement() * Console_CommandLine_SubCommandException::getErrorElement() * etc... All child exceptions would return the element that caused the error. See the test script for am example. Test script: --------------- try { $result = $parser->parse(); } catch (Console_CommandLine_ArgumentException $exc) { $argument = $exc->getErrorElement(); if ($argument->name == 'queue') { $parser->displayError('No queue name specified.'); } } catch (...) { // etc... }

Comments

 [2009-06-19 10:53 UTC] gauthierm (Michael Gauthier)
The following patch has been added/updated: Patch Name: custom-messages-2009-06-19.diff Revision: 1245390825 URL: http://pear.php.net/bugs/patch-display.php?bug=15324&patch=custom-messages-2009-06-19.diff&revision=1245390825&display=1
 [2009-06-19 10:55 UTC] gauthierm (Michael Gauthier)
The attached patch adds support for specifying custom messages. A new interface Console_CommandLine_CustomMessageProvider is added to preserve backwards compatibility with the existing Console_CommandLine_MessageProvider interface. Unit tests for custom messages are added and existing tests are updated to work with new object properties.
 [2009-06-19 16:39 UTC] izi (David Jean Louis)
-Status: Open +Status: Closed -Assigned To: +Assigned To: izi
you rock Mike ! 1.0.7 released