Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Convert PEAR2_Console_CommandLine to namespaces.

  • Loading branch information...
commit e19dcb28c79f0cfc4c6826f9de9cecc554ab548c 1 parent 105515b
@saltybeagle saltybeagle authored
Showing with 467 additions and 399 deletions.
  1. +97 −96 src/Console/CommandLine.php
  2. +11 −10 src/Console/CommandLine/Action.php
  3. +8 −4 src/Console/CommandLine/Action/Callback.php
  4. +8 −4 src/Console/CommandLine/Action/Counter.php
  5. +8 −4 src/Console/CommandLine/Action/Help.php
  6. +5 −4 src/Console/CommandLine/Action/List.php
  7. +8 −4 src/Console/CommandLine/Action/Password.php
  8. +8 −4 src/Console/CommandLine/Action/StoreArray.php
  9. +8 −4 src/Console/CommandLine/Action/StoreFalse.php
  10. +10 −6 src/Console/CommandLine/Action/StoreFloat.php
  11. +10 −6 src/Console/CommandLine/Action/StoreInt.php
  12. +8 −4 src/Console/CommandLine/Action/StoreString.php
  13. +8 −4 src/Console/CommandLine/Action/StoreTrue.php
  14. +8 −4 src/Console/CommandLine/Action/Version.php
  15. +7 −6 src/Console/CommandLine/Argument.php
  16. +7 −5 src/Console/CommandLine/Command.php
  17. +7 −6 src/Console/CommandLine/CustomMessageProvider.php
  18. +7 −6 src/Console/CommandLine/Element.php
  19. +11 −10 src/Console/CommandLine/Exception.php
  20. +6 −5 src/Console/CommandLine/MessageProvider.php
  21. +8 −7 src/Console/CommandLine/MessageProvider/Default.php
  22. +24 −20 src/Console/CommandLine/Option.php
  23. +5 −4 src/Console/CommandLine/Outputter.php
  24. +6 −5 src/Console/CommandLine/Outputter/Default.php
  25. +5 −4 src/Console/CommandLine/Renderer.php
  26. +9 −8 src/Console/CommandLine/Renderer/Default.php
  27. +6 −5 src/Console/CommandLine/Result.php
  28. +30 −26 src/Console/CommandLine/XmlParser.php
  29. +7 −7 tests/AllTests.php
  30. +2 −2 tests/console_commandline_accept.phpt
  31. +7 −7 tests/console_commandline_addargument.phpt
  32. +3 −3 tests/console_commandline_addcommand.phpt
  33. +11 −11 tests/console_commandline_addoption.phpt
  34. +2 −2 tests/console_commandline_addoption_errors_1.phpt
  35. +2 −2 tests/console_commandline_addoption_errors_2.phpt
  36. +2 −2 tests/console_commandline_addoption_errors_3.phpt
  37. +2 −2 tests/console_commandline_addoption_errors_4.phpt
  38. +2 −2 tests/console_commandline_addoption_errors_5.phpt
  39. +2 −2 tests/console_commandline_addoption_errors_6.phpt
  40. +2 −2 tests/console_commandline_addoption_errors_7.phpt
  41. +2 −2 tests/console_commandline_fromxmlfile.phpt
  42. +2 −2 tests/console_commandline_fromxmlfile_error.phpt
  43. +2 −2 tests/console_commandline_fromxmlstring.phpt
  44. +2 −2 tests/console_commandline_options_defaults.phpt
  45. +1 −1  tests/console_commandline_parse_1.phpt
  46. +1 −1  tests/console_commandline_parse_10.phpt
  47. +1 −1  tests/console_commandline_parse_11.phpt
  48. +1 −1  tests/console_commandline_parse_12.phpt
  49. +2 −2 tests/console_commandline_parse_13.phpt
  50. +2 −2 tests/console_commandline_parse_14.phpt
  51. +1 −1  tests/console_commandline_parse_15.phpt
  52. +2 −2 tests/console_commandline_parse_16.phpt
  53. +2 −2 tests/console_commandline_parse_17.phpt
  54. +4 −4 tests/console_commandline_parse_18.phpt
  55. +4 −4 tests/console_commandline_parse_19.phpt
  56. +1 −1  tests/console_commandline_parse_2.phpt
  57. +2 −2 tests/console_commandline_parse_20.phpt
  58. +1 −1  tests/console_commandline_parse_21.phpt
  59. +2 −2 tests/console_commandline_parse_22.phpt
  60. +1 −1  tests/console_commandline_parse_23.phpt
  61. +2 −2 tests/console_commandline_parse_24.phpt
  62. +2 −2 tests/console_commandline_parse_25.phpt
  63. +2 −2 tests/console_commandline_parse_26.phpt
  64. +2 −2 tests/console_commandline_parse_27.phpt
  65. +2 −2 tests/console_commandline_parse_28.phpt
  66. +2 −2 tests/console_commandline_parse_29.phpt
  67. +1 −1  tests/console_commandline_parse_3.phpt
  68. +2 −2 tests/console_commandline_parse_4.phpt
  69. +2 −2 tests/console_commandline_parse_5.phpt
  70. +2 −2 tests/console_commandline_parse_6.phpt
  71. +3 −3 tests/console_commandline_parse_7.phpt
  72. +3 −3 tests/console_commandline_parse_8.phpt
  73. +1 −1  tests/console_commandline_parse_9.phpt
  74. +1 −1  tests/console_commandline_webrequest_1.phpt
  75. +1 −1  tests/console_commandline_webrequest_2.phpt
  76. +1 −1  tests/console_commandline_webrequest_3.phpt
  77. +15 −15 tests/tests.inc.php
View
193 src/Console/CommandLine.php
@@ -3,7 +3,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * This file is part of the PEAR2_Console_CommandLine package.
+ * This file is part of the pear2\Console\CommandLine package.
*
* A full featured package for managing command-line options and arguments
* hightly inspired from python optparse module, it allows the developper to
@@ -16,7 +16,7 @@
* http://opensource.org/licenses/mit-license.php
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -31,18 +31,18 @@
* There are three ways to create parsers with this class:
* <code>
* // direct usage
- * $parser = new PEAR2_Console_CommandLine();
+ * $parser = new pear2\Console\CommandLine();
*
* // with an xml definition file
- * $parser = PEAR2_Console_CommandLine::fromXmlFile('path/to/file.xml');
+ * $parser = pear2\Console\CommandLine::fromXmlFile('path/to/file.xml');
*
* // with an xml definition string
* $validXmlString = '..your xml string...';
- * $parser = PEAR2_Console_CommandLine::fromXmlString($validXmlString);
+ * $parser = pear2\Console\CommandLine::fromXmlString($validXmlString);
* </code>
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -52,7 +52,8 @@
* @example docs/examples/ex1.php
* @example docs/examples/ex2.php
*/
-class PEAR2_Console_CommandLine
+namespace pear2\Console;
+class CommandLine
{
// Public properties {{{
@@ -60,7 +61,7 @@ class PEAR2_Console_CommandLine
* Error messages.
*
* @var array $errors Error messages
- * @todo move this to PEAR2_Console_CommandLine_MessageProvider
+ * @todo move this to pear2\Console\CommandLine\MessageProvider
*/
public static $errors = array(
'option_bad_name' => 'option name must be a valid php variable name (got: {$name})',
@@ -71,7 +72,7 @@ class PEAR2_Console_CommandLine
'option_unregistered_action' => 'unregistered action "{$action}" for option "{$name}".',
'option_bad_action' => 'invalid action for option "{$name}".',
'option_invalid_callback' => 'you must provide a valid callback for option "{$name}"',
- 'action_class_does_not_exists' => 'action "{$name}" class "{$class}" not found, make sure that your class is available before calling PEAR2_Console_CommandLine::registerAction()',
+ 'action_class_does_not_exists' => 'action "{$name}" class "{$class}" not found, make sure that your class is available before calling pear2\Console\CommandLine::registerAction()',
'invalid_xml_file' => 'XML definition file "{$file}" does not exists or is not readable',
'invalid_rng_file' => 'RNG file "{$file}" does not exists or is not readable'
);
@@ -123,21 +124,21 @@ class PEAR2_Console_CommandLine
/**
* The command line parser renderer instance.
*
- * @var object that implements PEAR2_Console_CommandLine_Renderer interface
+ * @var object that implements pear2\Console\CommandLine\Renderer interface
*/
public $renderer = false;
/**
* The command line parser outputter instance.
*
- * @var PEAR2_Console_CommandLine_Outputter An outputter
+ * @var pear2\Console\CommandLine\Outputter An outputter
*/
public $outputter = false;
/**
* The command line message provider instance.
*
- * @var PEAR2_Console_CommandLine_MessageProvider A message provider instance
+ * @var pear2\Console\CommandLine\MessageProvider A message provider instance
*/
public $message_provider = false;
@@ -153,27 +154,27 @@ class PEAR2_Console_CommandLine
* Boolean that tells the parser to set relevant options default values,
* according to the option action.
*
- * @see PEAR2_Console_CommandLine_Option::setDefaults()
+ * @see pear2\Console\CommandLine\Option::setDefaults()
* @var bool $force_options_defaults Whether to force option default values
*/
public $force_options_defaults = false;
/**
- * An array of PEAR2_Console_CommandLine_Option objects.
+ * An array of pear2\Console\CommandLine\Option objects.
*
* @var array $options The options array
*/
public $options = array();
/**
- * An array of PEAR2_Console_CommandLine_Argument objects.
+ * An array of pear2\Console\CommandLine\Argument objects.
*
* @var array $args The arguments array
*/
public $args = array();
/**
- * An array of PEAR2_Console_CommandLine_Command objects (sub commands).
+ * An array of pear2\Console\CommandLine\Command objects (sub commands).
*
* @var array $commands The commands array
*/
@@ -183,8 +184,8 @@ class PEAR2_Console_CommandLine
* Parent, only relevant in Command objects but left here for interface
* convenience.
*
- * @var PEAR2_Console_CommandLine The parent instance
- * @todo move PEAR2_Console_CommandLine::parent to PEAR2_Console_CommandLine_Command
+ * @var pear2\Console\CommandLine The parent instance
+ * @todo move pear2\Console\CommandLine::parent to pear2\Console\CommandLine\Command
*/
public $parent = false;
@@ -202,18 +203,18 @@ class PEAR2_Console_CommandLine
* @var array $actions List of valid actions
*/
public static $actions = array(
- 'StoreTrue' => array('PEAR2_Console_CommandLine_Action_StoreTrue', true),
- 'StoreFalse' => array('PEAR2_Console_CommandLine_Action_StoreFalse', true),
- 'StoreString' => array('PEAR2_Console_CommandLine_Action_StoreString', true),
- 'StoreInt' => array('PEAR2_Console_CommandLine_Action_StoreInt', true),
- 'StoreFloat' => array('PEAR2_Console_CommandLine_Action_StoreFloat', true),
- 'StoreArray' => array('PEAR2_Console_CommandLine_Action_StoreArray', true),
- 'Callback' => array('PEAR2_Console_CommandLine_Action_Callback', true),
- 'Counter' => array('PEAR2_Console_CommandLine_Action_Counter', true),
- 'Help' => array('PEAR2_Console_CommandLine_Action_Help', true),
- 'Version' => array('PEAR2_Console_CommandLine_Action_Version', true),
- 'Password' => array('PEAR2_Console_CommandLine_Action_Password', true),
- 'List' => array('PEAR2_Console_CommandLine_Action_List', true),
+ 'StoreTrue' => array('pear2\\Console\\CommandLine\\Action\\StoreTrue', true),
+ 'StoreFalse' => array('pear2\\Console\\CommandLine\\Action\\StoreFalse', true),
+ 'StoreString' => array('pear2\\Console\\CommandLine\\Action\\StoreString', true),
+ 'StoreInt' => array('pear2\\Console\\CommandLine\\Action\\StoreInt', true),
+ 'StoreFloat' => array('pear2\\Console\\CommandLine\\Action\\StoreFloat', true),
+ 'StoreArray' => array('pear2\\Console\\CommandLine\\Action\\StoreArray', true),
+ 'Callback' => array('pear2\\Console\\CommandLine\\Action\\Callback', true),
+ 'Counter' => array('pear2\\Console\\CommandLine\\Action\\Counter', true),
+ 'Help' => array('pear2\\Console\\CommandLine\\Action\\Help', true),
+ 'Version' => array('pear2\\Console\\CommandLine\\Action\\Version', true),
+ 'Password' => array('pear2\\Console\\CommandLine\\Action\\Password', true),
+ 'List' => array('pear2\\Console\\CommandLine\\Action_List', true),
);
/**
@@ -241,7 +242,7 @@ class PEAR2_Console_CommandLine
* </code>
*
* @var array
- * @see PEAR2_Console_CommandLine_MessageProvider_Default
+ * @see pear2\Console\CommandLine\MessageProvider_Default
*/
public $messages = array();
@@ -263,7 +264,7 @@ class PEAR2_Console_CommandLine
* Example:
*
* <code>
- * $parser = new PEAR2_Console_CommandLine(array(
+ * $parser = new pear2\Console\CommandLine(array(
* 'name' => 'yourprogram', // defaults to argv[0]
* 'description' => 'Description of your program',
* 'version' => '0.0.1', // your program version
@@ -309,16 +310,16 @@ public function __construct(array $params = array())
$this->messages = $params['messages'];
}
// set default instances
- $this->renderer = new PEAR2_Console_CommandLine_Renderer_Default($this);
- $this->outputter = new PEAR2_Console_CommandLine_Outputter_Default();
- $this->message_provider = new PEAR2_Console_CommandLine_MessageProvider_Default();
+ $this->renderer = new CommandLine\Renderer_Default($this);
+ $this->outputter = new CommandLine\Outputter_Default();
+ $this->message_provider = new CommandLine\MessageProvider_Default();
}
// }}}
// accept() {{{
/**
- * Method to allow PEAR2_Console_CommandLine to accept either:
+ * Method to allow pear2\Console\CommandLine to accept either:
* + a custom renderer,
* + a custom outputter,
* + or a custom message provider
@@ -326,21 +327,21 @@ public function __construct(array $params = array())
* @param mixed $instance The custom instance
*
* @return void
- * @throws PEAR2_Console_CommandLine_Exception if wrong argument passed
+ * @throws pear2\Console\CommandLine\Exception if wrong argument passed
*/
public function accept($instance)
{
- if ($instance instanceof PEAR2_Console_CommandLine_Renderer) {
+ if ($instance instanceof CommandLine\Renderer) {
if (property_exists($instance, 'parser') && !$instance->parser) {
$instance->parser = $this;
}
$this->renderer = $instance;
- } else if ($instance instanceof PEAR2_Console_CommandLine_Outputter) {
+ } else if ($instance instanceof CommandLine\Outputter) {
$this->outputter = $instance;
- } else if ($instance instanceof PEAR2_Console_CommandLine_MessageProvider) {
+ } else if ($instance instanceof CommandLine\MessageProvider) {
$this->message_provider = $instance;
} else {
- throw PEAR2_Console_CommandLine_Exception::factory(
+ throw CommandLine\Exception::factory(
'INVALID_CUSTOM_INSTANCE',
array(),
$this,
@@ -357,17 +358,17 @@ public function accept($instance)
*
* Example:
* <code>
- * $parser = PEAR2_Console_CommandLine::fromXmlFile('path/to/file.xml');
+ * $parser = pear2\Console\CommandLine::fromXmlFile('path/to/file.xml');
* $result = $parser->parse();
* </code>
*
* @param string $file Path to the xml file
*
- * @return PEAR2_Console_CommandLine The parser instance
+ * @return pear2\Console\CommandLine The parser instance
*/
public static function fromXmlFile($file)
{
- return PEAR2_Console_CommandLine_XmlParser::parse($file);
+ return CommandLine\XmlParser::parse($file);
}
// }}}
@@ -392,17 +393,17 @@ public static function fromXmlFile($file)
* <multiple>true</multiple>
* </argument>
* </command>';
- * $parser = PEAR2_Console_CommandLine::fromXmlString($xmldata);
+ * $parser = pear2\Console\CommandLine::fromXmlString($xmldata);
* $result = $parser->parse();
* </code>
*
* @param string $string The xml data
*
- * @return PEAR2_Console_CommandLine The parser instance
+ * @return pear2\Console\CommandLine The parser instance
*/
public static function fromXmlString($string)
{
- return PEAR2_Console_CommandLine_XmlParser::parseString($string);
+ return CommandLine\XmlParser::parseString($string);
}
// }}}
@@ -412,16 +413,16 @@ public static function fromXmlString($string)
* Adds an argument to the command line parser and returns it.
*
* Adds an argument with the name $name and set its attributes with the
- * array $params, then return the PEAR2_Console_CommandLine_Argument instance
+ * array $params, then return the pear2\Console\CommandLine\Argument instance
* created.
* The method accepts another form: you can directly pass a
- * PEAR2_Console_CommandLine_Argument object as the sole argument, this allows
+ * pear2\Console\CommandLine\Argument object as the sole argument, this allows
* you to contruct the argument separately, in order to reuse it in
* different command line parsers or commands for example.
*
* Example:
* <code>
- * $parser = new PEAR2_Console_CommandLine();
+ * $parser = new pear2\Console\CommandLine();
* // add an array argument
* $parser->addArgument('input_files', array('multiple'=>true));
* // add a simple argument
@@ -443,18 +444,18 @@ public static function fromXmlString($string)
* </code>
*
* @param mixed $name A string containing the argument name or an
- * instance of PEAR2_Console_CommandLine_Argument
+ * instance of pear2\Console\CommandLine\Argument
* @param array $params An array containing the argument attributes
*
- * @return PEAR2_Console_CommandLine_Argument the added argument
- * @see PEAR2_Console_CommandLine_Argument
+ * @return pear2\Console\CommandLine\Argument the added argument
+ * @see pear2\Console\CommandLine\Argument
*/
public function addArgument($name, $params = array())
{
- if ($name instanceof PEAR2_Console_CommandLine_Argument) {
+ if ($name instanceof CommandLine\Argument) {
$argument = $name;
} else {
- $argument = new PEAR2_Console_CommandLine_Argument($name, $params);
+ $argument = new CommandLine\Argument($name, $params);
}
$argument->validate();
$this->args[$argument->name] = $argument;
@@ -468,14 +469,14 @@ public function addArgument($name, $params = array())
* Adds a sub-command to the command line parser.
*
* Adds a command with the given $name to the parser and returns the
- * PEAR2_Console_CommandLine_Command instance, you can then populate the command
+ * pear2\Console\CommandLine\Command instance, you can then populate the command
* with options, configure it, etc... like you would do for the main parser
- * because the class PEAR2_Console_CommandLine_Command inherits from
- * PEAR2_Console_CommandLine.
+ * because the class pear2\Console\CommandLine\Command inherits from
+ * pear2\Console\CommandLine.
*
* An example:
* <code>
- * $parser = new PEAR2_Console_CommandLine();
+ * $parser = new pear2\Console\CommandLine();
* $install_cmd = $parser->addCommand('install');
* $install_cmd->addOption(
* 'verbose',
@@ -503,19 +504,19 @@ public function addArgument($name, $params = array())
* </code>
*
* @param mixed $name A string containing the command name or an
- * instance of PEAR2_Console_CommandLine_Command
+ * instance of pear2\Console\CommandLine\Command
* @param array $params An array containing the command attributes
*
- * @return PEAR2_Console_CommandLine_Command The added subcommand
- * @see PEAR2_Console_CommandLine_Command
+ * @return pear2\Console\CommandLine\Command The added subcommand
+ * @see pear2\Console\CommandLine\Command
*/
public function addCommand($name, $params = array())
{
- if ($name instanceof PEAR2_Console_CommandLine_Command) {
+ if ($name instanceof CommandLine\Command) {
$command = $name;
} else {
$params['name'] = $name;
- $command = new PEAR2_Console_CommandLine_Command($params);
+ $command = new CommandLine\Command($params);
// some properties must cascade to the child command if not
// passed explicitely. This is done only in this case, because if
// we have a Command object we have no way to determine if theses
@@ -551,16 +552,16 @@ public function addCommand($name, $params = array())
* Adds an option to the command line parser and returns it.
*
* Adds an option with the name $name and set its attributes with the
- * array $params, then return the PEAR2_Console_CommandLine_Option instance
+ * array $params, then return the pear2\Console\CommandLine\Option instance
* created.
* The method accepts another form: you can directly pass a
- * PEAR2_Console_CommandLine_Option object as the sole argument, this allows
+ * pear2\Console\CommandLine\Option object as the sole argument, this allows
* you to contruct the option separately, in order to reuse it in different
* command line parsers or commands for example.
*
* Example:
* <code>
- * $parser = new PEAR2_Console_CommandLine();
+ * $parser = new pear2\Console\CommandLine();
* $parser->addOption('path', array(
* 'short_name' => '-p', // a short name
* 'long_name' => '--path', // a long name
@@ -590,18 +591,18 @@ public function addCommand($name, $params = array())
* </code>
*
* @param mixed $name A string containing the option name or an
- * instance of PEAR2_Console_CommandLine_Option
+ * instance of pear2\Console\CommandLine\Option
* @param array $params An array containing the option attributes
*
- * @return PEAR2_Console_CommandLine_Option The added option
- * @see PEAR2_Console_CommandLine_Option
+ * @return pear2\Console\CommandLine\Option The added option
+ * @see pear2\Console\CommandLine\Option
*/
public function addOption($name, $params = array())
{
- if ($name instanceof PEAR2_Console_CommandLine_Option) {
+ if ($name instanceof CommandLine\Option) {
$opt = $name;
} else {
- $opt = new PEAR2_Console_CommandLine_Option($name, $params);
+ $opt = new CommandLine\Option($name, $params);
}
$opt->validate();
if ($this->force_options_defaults) {
@@ -693,7 +694,7 @@ public function displayVersion($exitCode = 0)
*
* @param string $str The option identifier
*
- * @return mixed A PEAR2_Console_CommandLine_Option instance or false
+ * @return mixed A pear2\Console\CommandLine\Option instance or false
*/
public function findOption($str)
{
@@ -721,7 +722,7 @@ public function findOption($str)
$matches_str .= $padding . $opt->long_name;
$padding = ', ';
}
- throw PEAR2_Console_CommandLine_Exception::factory(
+ throw CommandLine\Exception::factory(
'OPTION_AMBIGUOUS',
array('name' => $str, 'matches' => $matches_str),
$this,
@@ -746,7 +747,7 @@ public function findOption($str)
* // and in the result we will have:
* // $result->options['range']: array(1, 5)
*
- * class ActionRange extends PEAR2_Console_CommandLine_Action
+ * class ActionRange extends pear2\Console\CommandLine\Action
* {
* public function execute($value=false, $params=array())
* {
@@ -761,9 +762,9 @@ public function findOption($str)
* }
* }
* // then we can register our action
- * PEAR2_Console_CommandLine::registerAction('Range', 'ActionRange');
+ * pear2\Console\CommandLine::registerAction('Range', 'ActionRange');
* // and now our action is available !
- * $parser = new PEAR2_Console_CommandLine();
+ * $parser = new pear2\Console\CommandLine();
* $parser->addOption('range', array(
* 'short_name' => '-r',
* 'long_name' => '--range',
@@ -820,12 +821,12 @@ public static function triggerError($msgId, $level, $params=array())
/**
* Parses the command line arguments and returns a
- * PEAR2_Console_CommandLine_Result instance.
+ * pear2\Console\CommandLine\Result instance.
*
* @param integer $userArgc Number of arguments (optional)
* @param array $userArgv Array containing arguments (optional)
*
- * @return PEAR2_Console_CommandLine_Result The result instance
+ * @return pear2\Console\CommandLine\Result The result instance
* @throws Exception on user errors
*/
public function parse($userArgc=null, $userArgv=null)
@@ -838,8 +839,8 @@ public function parse($userArgc=null, $userArgv=null)
list($argc, $argv) = $this->getArgcArgv();
}
// build an empty result
- $result = new PEAR2_Console_CommandLine_Result();
- if (!($this instanceof PEAR2_Console_CommandLine_Command)) {
+ $result = new CommandLine\Result();
+ if (!($this instanceof CommandLine\Command)) {
// remove script name if we're not in a subcommand
array_shift($argv);
$argc--;
@@ -873,7 +874,7 @@ public function parse($userArgc=null, $userArgv=null)
&& count($this->args) === 0
&& count($args) > 0
) {
- throw PEAR2_Console_CommandLine_Exception::factory(
+ throw CommandLine\Exception::factory(
'INVALID_SUBCOMMAND',
array('command' => $args[0]),
$this,
@@ -888,7 +889,7 @@ public function parse($userArgc=null, $userArgv=null)
}
}
if (count($args) < $argnum) {
- throw PEAR2_Console_CommandLine_Exception::factory(
+ throw CommandLine\Exception::factory(
'ARGUMENT_REQUIRED',
array('argnum' => $argnum, 'plural' => $argnum>1 ? 's': ''),
$this,
@@ -920,7 +921,7 @@ public function parse($userArgc=null, $userArgv=null)
* and $args arrays.
*
* @param string $token The command line token to parse
- * @param object $result The PEAR2_Console_CommandLine_Result instance
+ * @param object $result The pear2\Console\CommandLine\Result instance
* @param array &$args The argv array
* @param int $argc Number of lasting args
*
@@ -944,7 +945,7 @@ protected function parseToken($token, $result, &$args, $argc)
// case of an option that expect a list of args
$lastopt = false;
} else {
- throw PEAR2_Console_CommandLine_Exception::factory(
+ throw CommandLine\Exception::factory(
'OPTION_VALUE_REQUIRED',
array('name' => $lastopt->name),
$this,
@@ -984,7 +985,7 @@ protected function parseToken($token, $result, &$args, $argc)
}
$opt = $this->findOption($optkv[0]);
if (!$opt) {
- throw PEAR2_Console_CommandLine_Exception::factory(
+ throw CommandLine\Exception::factory(
'OPTION_UNKNOWN',
array('name' => $optkv[0]),
$this,
@@ -993,7 +994,7 @@ protected function parseToken($token, $result, &$args, $argc)
}
$value = isset($optkv[1]) ? $optkv[1] : false;
if (!$opt->expectsArgument() && $value !== false) {
- throw PEAR2_Console_CommandLine_Exception::factory(
+ throw CommandLine\Exception::factory(
'OPTION_VALUE_UNEXPECTED',
array('name' => $opt->name, 'value' => $value),
$this,
@@ -1004,7 +1005,7 @@ protected function parseToken($token, $result, &$args, $argc)
// maybe the long option argument is separated by a space, if
// this is the case it will be the next arg
if ($last && !$opt->argument_optional) {
- throw PEAR2_Console_CommandLine_Exception::factory(
+ throw CommandLine\Exception::factory(
'OPTION_VALUE_REQUIRED',
array('name' => $opt->name),
$this,
@@ -1029,7 +1030,7 @@ protected function parseToken($token, $result, &$args, $argc)
}
$opt = $this->findOption($optname);
if (!$opt) {
- throw PEAR2_Console_CommandLine_Exception::factory(
+ throw CommandLine\Exception::factory(
'OPTION_UNKNOWN',
array('name' => $optname),
$this,
@@ -1043,7 +1044,7 @@ protected function parseToken($token, $result, &$args, $argc)
if ($next === false) {
if ($opt->expectsArgument()) {
if ($last && !$opt->argument_optional) {
- throw PEAR2_Console_CommandLine_Exception::factory(
+ throw CommandLine\Exception::factory(
'OPTION_VALUE_REQUIRED',
array('name' => $opt->name),
$this,
@@ -1063,7 +1064,7 @@ protected function parseToken($token, $result, &$args, $argc)
$args, $last);
return;
} else {
- throw PEAR2_Console_CommandLine_Exception::factory(
+ throw CommandLine\Exception::factory(
'OPTION_UNKNOWN',
array('name' => $next),
$this,
@@ -1134,7 +1135,7 @@ public function addBuiltinOptions()
* if it fails to get them.
*
* @return array The argc/argv array
- * @throws PEAR2_Console_CommandLine_Exception
+ * @throws pear2\Console\CommandLine\Exception
*/
protected function getArgcArgv()
{
@@ -1147,7 +1148,7 @@ protected function getArgcArgv()
$value = array($value);
}
$opt = $this->findOption($key);
- if ($opt instanceof PEAR2_Console_CommandLine_Option) {
+ if ($opt instanceof CommandLine\Option) {
// match a configured option
$argv[] = $opt->short_name ?
$opt->short_name : $opt->long_name;
@@ -1184,9 +1185,9 @@ protected function getArgcArgv()
/**
* Dispatches the given option or store the option to dispatch it later.
*
- * @param PEAR2_Console_CommandLine_Option $option The option instance
+ * @param pear2\Console\CommandLine\Option $option The option instance
* @param string $token Command line token to parse
- * @param PEAR2_Console_CommandLine_Result $result The result instance
+ * @param pear2\Console\CommandLine\Result $result The result instance
*
* @return void
*/
@@ -1207,7 +1208,7 @@ private function _dispatchAction($option, $token, $result)
*
* @param string $token Current command line token
*
- * @return mixed An instance of Console_CommandLine_Command or false
+ * @return mixed An instance of pear2\Console\CommandLine\Command or false
*/
private function _getSubCommand($token)
{
View
21 src/Console/CommandLine/Action.php
@@ -3,7 +3,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * This file is part of the PEAR2_Console_CommandLine package.
+ * This file is part of the pear2\Console\CommandLine package.
*
* PHP version 5
*
@@ -12,7 +12,7 @@
* http://opensource.org/licenses/mit-license.php
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -26,7 +26,7 @@
* Class that represent an option action.
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -34,28 +34,29 @@
* @link http://pear.php.net/package/Console_CommandLine
* @since Class available since release 0.1.0
*/
-abstract class PEAR2_Console_CommandLine_Action
+namespace pear2\Console\CommandLine;
+abstract class Action
{
// Properties {{{
/**
* A reference to the result instance.
*
- * @var PEAR2_Console_CommandLine_Result $result The result instance
+ * @var pear2\Console\CommandLine_Result $result The result instance
*/
protected $result;
/**
* A reference to the option instance.
*
- * @var PEAR2_Console_CommandLine_Option $option The action option
+ * @var pear2\Console\CommandLine_Option $option The action option
*/
protected $option;
/**
* A reference to the parser instance.
*
- * @var PEAR2_Console_CommandLine $parser The parser
+ * @var pear2\Console\CommandLine $parser The parser
*/
protected $parser;
@@ -65,9 +66,9 @@
/**
* Constructor
*
- * @param PEAR2_Console_CommandLine_Result $result The result instance
- * @param PEAR2_Console_CommandLine_Option $option The action option
- * @param PEAR2_Console_CommandLine $parser The current parser
+ * @param pear2\Console\CommandLine_Result $result The result instance
+ * @param pear2\Console\CommandLine_Option $option The action option
+ * @param pear2\Console\CommandLine $parser The current parser
*
* @return void
*/
View
12 src/Console/CommandLine/Action/Callback.php
@@ -3,7 +3,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * This file is part of the PEAR2_Console_CommandLine package.
+ * This file is part of the pear2\Console\CommandLine package.
*
* PHP version 5
*
@@ -12,7 +12,7 @@
* http://opensource.org/licenses/mit-license.php
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -46,7 +46,7 @@
* and *must* return the option value.
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -54,7 +54,11 @@
* @link http://pear.php.net/package/Console_CommandLine
* @since Class available since release 0.1.0
*/
-class PEAR2_Console_CommandLine_Action_Callback extends PEAR2_Console_CommandLine_Action
+namespace pear2\Console\CommandLine\Action;
+
+use pear2\Console\CommandLine;
+
+class Callback extends CommandLine\Action
{
// execute() {{{
View
12 src/Console/CommandLine/Action/Counter.php
@@ -3,7 +3,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * This file is part of the PEAR2_Console_CommandLine package.
+ * This file is part of the pear2\Console\CommandLine package.
*
* PHP version 5
*
@@ -12,7 +12,7 @@
* http://opensource.org/licenses/mit-license.php
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -49,7 +49,7 @@
* the verbose variable will be set to to 3.
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -57,7 +57,11 @@
* @link http://pear.php.net/package/Console_CommandLine
* @since Class available since release 0.1.0
*/
-class PEAR2_Console_CommandLine_Action_Counter extends PEAR2_Console_CommandLine_Action
+namespace pear2\Console\CommandLine\Action;
+
+use pear2\Console\CommandLine;
+
+class Counter extends CommandLine\Action
{
// execute() {{{
View
12 src/Console/CommandLine/Action/Help.php
@@ -3,7 +3,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * This file is part of the PEAR2_Console_CommandLine package.
+ * This file is part of the pear2\Console\CommandLine package.
*
* PHP version 5
*
@@ -12,7 +12,7 @@
* http://opensource.org/licenses/mit-license.php
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -27,7 +27,7 @@
* help message, telling the user how to use the program.
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -35,7 +35,11 @@
* @link http://pear.php.net/package/Console_CommandLine
* @since Class available since release 0.1.0
*/
-class PEAR2_Console_CommandLine_Action_Help extends PEAR2_Console_CommandLine_Action
+namespace pear2\Console\CommandLine\Action;
+
+use pear2\Console\CommandLine;
+
+class Help extends CommandLine\Action
{
// execute() {{{
View
9 src/Console/CommandLine/Action/List.php
@@ -3,7 +3,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * This file is part of the PEAR2_Console_CommandLine package.
+ * This file is part of the pear2\Console\CommandLine package.
*
* PHP version 5
*
@@ -12,7 +12,7 @@
* http://opensource.org/licenses/mit-license.php
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -27,7 +27,7 @@
* array as a list.
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -35,7 +35,8 @@
* @link http://pear.php.net/package/Console_CommandLine
* @since Class available since release 0.1.0
*/
-class PEAR2_Console_CommandLine_Action_List extends PEAR2_Console_CommandLine_Action
+namespace pear2\Console\CommandLine;
+class Action_List extends Action
{
// execute() {{{
View
12 src/Console/CommandLine/Action/Password.php
@@ -3,7 +3,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * This file is part of the PEAR2_Console_CommandLine package.
+ * This file is part of the pear2\Console\CommandLine package.
*
* PHP version 5
*
@@ -12,7 +12,7 @@
* http://opensource.org/licenses/mit-license.php
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -28,7 +28,7 @@
* entering it.
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -36,7 +36,11 @@
* @link http://pear.php.net/package/Console_CommandLine
* @since Class available since release 0.1.0
*/
-class PEAR2_Console_CommandLine_Action_Password extends PEAR2_Console_CommandLine_Action
+namespace pear2\Console\CommandLine\Action;
+
+use pear2\Console\CommandLine;
+
+class Password extends CommandLine\Action
{
// execute() {{{
View
12 src/Console/CommandLine/Action/StoreArray.php
@@ -3,7 +3,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * This file is part of the PEAR2_Console_CommandLine package.
+ * This file is part of the pear2\Console\CommandLine package.
*
* PHP version 5
*
@@ -12,7 +12,7 @@
* http://opensource.org/licenses/mit-license.php
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -29,7 +29,7 @@
* the result option array entry.
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -37,7 +37,11 @@
* @link http://pear.php.net/package/Console_CommandLine
* @since Class available since release 0.1.0
*/
-class PEAR2_Console_CommandLine_Action_StoreArray extends PEAR2_Console_CommandLine_Action
+namespace pear2\Console\CommandLine\Action;
+
+use pear2\Console\CommandLine;
+
+class StoreArray extends CommandLine\Action
{
// Protected properties {{{
View
12 src/Console/CommandLine/Action/StoreFalse.php
@@ -3,7 +3,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * This file is part of the PEAR2_Console_CommandLine package.
+ * This file is part of the pear2\Console\CommandLine package.
*
* PHP version 5
*
@@ -12,7 +12,7 @@
* http://opensource.org/licenses/mit-license.php
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -30,7 +30,7 @@
* command line entered by the user).
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -38,7 +38,11 @@
* @link http://pear.php.net/package/Console_CommandLine
* @since Class available since release 0.1.0
*/
-class PEAR2_Console_CommandLine_Action_StoreFalse extends PEAR2_Console_CommandLine_Action
+namespace pear2\Console\CommandLine\Action;
+
+use pear2\Console\CommandLine;
+
+class StoreFalse extends CommandLine\Action
{
// execute() {{{
View
16 src/Console/CommandLine/Action/StoreFloat.php
@@ -3,7 +3,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * This file is part of the PEAR2_Console_CommandLine package.
+ * This file is part of the pear2\Console\CommandLine package.
*
* PHP version 5
*
@@ -12,7 +12,7 @@
* http://opensource.org/licenses/mit-license.php
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -30,7 +30,7 @@
* an Exception is raised.
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -38,7 +38,11 @@
* @link http://pear.php.net/package/Console_CommandLine
* @since Class available since release 0.1.0
*/
-class PEAR2_Console_CommandLine_Action_StoreFloat extends PEAR2_Console_CommandLine_Action
+namespace pear2\Console\CommandLine\Action;
+
+use pear2\Console\CommandLine;
+
+class StoreFloat extends CommandLine\Action
{
// execute() {{{
@@ -49,12 +53,12 @@ class PEAR2_Console_CommandLine_Action_StoreFloat extends PEAR2_Console_CommandL
* @param array $params An array of optional parameters
*
* @return string
- * @throws PEAR2_Console_CommandLine_Exception
+ * @throws pear2\Console\CommandLine_Exception
*/
public function execute($value = false, $params = array())
{
if (!is_numeric($value)) {
- throw PEAR2_Console_CommandLine_Exception::factory(
+ throw CommandLine\Exception::factory(
'OPTION_VALUE_TYPE_ERROR',
array(
'name' => $this->option->name,
View
16 src/Console/CommandLine/Action/StoreInt.php
@@ -3,7 +3,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * This file is part of the PEAR2_Console_CommandLine package.
+ * This file is part of the pear2\Console\CommandLine package.
*
* PHP version 5
*
@@ -12,7 +12,7 @@
* http://opensource.org/licenses/mit-license.php
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -30,7 +30,7 @@
* integer an Exception is raised.
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -38,7 +38,11 @@
* @link http://pear.php.net/package/Console_CommandLine
* @since Class available since release 0.1.0
*/
-class PEAR2_Console_CommandLine_Action_StoreInt extends PEAR2_Console_CommandLine_Action
+namespace pear2\Console\CommandLine\Action;
+
+use pear2\Console\CommandLine;
+
+class StoreInt extends CommandLine\Action
{
// execute() {{{
@@ -49,12 +53,12 @@ class PEAR2_Console_CommandLine_Action_StoreInt extends PEAR2_Console_CommandLin
* @param array $params An array of optional parameters
*
* @return string
- * @throws PEAR2_Console_CommandLine_Exception
+ * @throws pear2\Console\CommandLine_Exception
*/
public function execute($value = false, $params = array())
{
if (!is_numeric($value)) {
- throw PEAR2_Console_CommandLine_Exception::factory(
+ throw CommandLine\Exception::factory(
'OPTION_VALUE_TYPE_ERROR',
array(
'name' => $this->option->name,
View
12 src/Console/CommandLine/Action/StoreString.php
@@ -3,7 +3,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * This file is part of the PEAR2_Console_CommandLine package.
+ * This file is part of the pear2\Console\CommandLine package.
*
* PHP version 5
*
@@ -12,7 +12,7 @@
* http://opensource.org/licenses/mit-license.php
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -29,7 +29,7 @@
* string in the result option array entry.
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -37,7 +37,11 @@
* @link http://pear.php.net/package/Console_CommandLine
* @since Class available since release 0.1.0
*/
-class PEAR2_Console_CommandLine_Action_StoreString extends PEAR2_Console_CommandLine_Action
+namespace pear2\Console\CommandLine\Action;
+
+use pear2\Console\CommandLine;
+
+class StoreString extends CommandLine\Action
{
// execute() {{{
View
12 src/Console/CommandLine/Action/StoreTrue.php
@@ -3,7 +3,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * This file is part of the PEAR2_Console_CommandLine package.
+ * This file is part of the pear2\Console\CommandLine package.
*
* PHP version 5
*
@@ -12,7 +12,7 @@
* http://opensource.org/licenses/mit-license.php
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -30,7 +30,7 @@
* command line entered by the user).
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -38,7 +38,11 @@
* @link http://pear.php.net/package/Console_CommandLine
* @since Class available since release 0.1.0
*/
-class PEAR2_Console_CommandLine_Action_StoreTrue extends PEAR2_Console_CommandLine_Action
+namespace pear2\Console\CommandLine\Action;
+
+use pear2\Console\CommandLine;
+
+class StoreTrue extends CommandLine\Action
{
// execute() {{{
View
12 src/Console/CommandLine/Action/Version.php
@@ -3,7 +3,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * This file is part of the PEAR2_Console_CommandLine package.
+ * This file is part of the pear2\Console\CommandLine package.
*
* PHP version 5
*
@@ -12,7 +12,7 @@
* http://opensource.org/licenses/mit-license.php
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -27,7 +27,7 @@
* version string of the program.
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -35,7 +35,11 @@
* @link http://pear.php.net/package/Console_CommandLine
* @since Class available since release 0.1.0
*/
-class PEAR2_Console_CommandLine_Action_Version extends PEAR2_Console_CommandLine_Action
+namespace pear2\Console\CommandLine\Action;
+
+use pear2\Console\CommandLine;
+
+class Version extends CommandLine\Action
{
// execute() {{{
View
13 src/Console/CommandLine/Argument.php
@@ -3,7 +3,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * This file is part of the PEAR2_Console_CommandLine package.
+ * This file is part of the pear2\Console\CommandLine package.
*
* PHP version 5
*
@@ -12,7 +12,7 @@
* http://opensource.org/licenses/mit-license.php
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -26,7 +26,7 @@
* Class that represent a command line argument.
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -34,7 +34,8 @@
* @link http://pear.php.net/package/Console_CommandLine
* @since Class available since release 0.1.0
*/
-class PEAR2_Console_CommandLine_Argument extends PEAR2_Console_CommandLine_Element
+namespace pear2\Console\CommandLine;
+class Argument extends Element
{
// Public properties {{{
@@ -63,7 +64,7 @@ class PEAR2_Console_CommandLine_Argument extends PEAR2_Console_CommandLine_Eleme
* Validates the argument instance.
*
* @return void
- * @throws PEAR2_Console_CommandLine_Exception
+ * @throws pear2\Console\CommandLine_Exception
* @todo use exceptions
*/
public function validate()
@@ -71,7 +72,7 @@ public function validate()
// check if the argument name is valid
if (!preg_match('/^[a-zA-Z_\x7f-\xff]+[a-zA-Z0-9_\x7f-\xff]*$/',
$this->name)) {
- PEAR2_Console_CommandLine::triggerError(
+ \pear2\Console\CommandLine::triggerError(
'argument_bad_name',
E_USER_ERROR,
array('{$name}' => $this->name)
View
12 src/Console/CommandLine/Command.php
@@ -3,7 +3,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * This file is part of the PEAR2_Console_CommandLine package.
+ * This file is part of the pear2\Console\CommandLine package.
*
* PHP version 5
*
@@ -12,7 +12,7 @@
* http://opensource.org/licenses/mit-license.php
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -26,11 +26,11 @@
* Class that represent a command with option and arguments.
*
* This class exist just to clarify the interface but at the moment it is
- * strictly identical to PEAR2_Console_CommandLine class, it could change in the
+ * strictly identical to pear2\Console\CommandLine class, it could change in the
* future though.
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -38,7 +38,9 @@
* @link http://pear.php.net/package/Console_CommandLine
* @since Class available since release 0.1.0
*/
-class PEAR2_Console_CommandLine_Command extends PEAR2_Console_CommandLine
+namespace pear2\Console\CommandLine;
+
+class Command extends \pear2\Console\CommandLine
{
// Public properties {{{
View
13 src/Console/CommandLine/CustomMessageProvider.php
@@ -3,7 +3,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * This file is part of the PEAR2_Console_CommandLine package.
+ * This file is part of the pear2\Console\CommandLine package.
*
* PHP version 5
*
@@ -12,7 +12,7 @@
* http://opensource.org/licenses/mit-license.php
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @author Michael Gauthier <mike@silverorange.com>
* @copyright 2007 David JEAN LOUIS, 2009 silverorange
@@ -30,7 +30,7 @@
* Message providers may optionally implement this interface.
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @author Michael Gauthier <mike@silverorange.com>
* @copyright 2007 David JEAN LOUIS, 2009 silverorange
@@ -39,7 +39,8 @@
* @link http://pear.php.net/package/Console_CommandLine
* @since Interface available since release 1.1.0
*/
-interface PEAR2_Console_CommandLine_CustomMessageProvider
+namespace pear2\Console\CommandLine;
+interface CustomMessageProvider
{
// getWithCustomMesssages() {{{
@@ -55,8 +56,8 @@
* indexes are message codes.
*
* @return string
- * @see PEAR2_Console_CommandLine_MessageProvider
- * @see PEAR2_Console_CommandLine_MessageProvider_Default
+ * @see pear2\Console\CommandLine_MessageProvider
+ * @see pear2\Console\CommandLine_MessageProvider_Default
*/
public function getWithCustomMessages(
$code, $vars = array(), $messages = array()
View
13 src/Console/CommandLine/Element.php
@@ -3,7 +3,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * This file is part of the PEAR2_Console_CommandLine package.
+ * This file is part of the pear2\Console\CommandLine package.
*
* PHP version 5
*
@@ -12,7 +12,7 @@
* http://opensource.org/licenses/mit-license.php
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -26,7 +26,7 @@
* Class that represent a command line element (an option, or an argument).
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -34,7 +34,8 @@
* @link http://pear.php.net/package/Console_CommandLine
* @since Class available since release 0.1.0
*/
-abstract class PEAR2_Console_CommandLine_Element
+namespace pear2\Console\CommandLine;
+abstract class Element
{
// Public properties {{{
@@ -85,7 +86,7 @@
* </code>
*
* @var array
- * @see PEAR2_Console_CommandLine_MessageProvider_Default
+ * @see pear2\Console\CommandLine_MessageProvider_Default
*/
public $messages = array();
@@ -130,7 +131,7 @@ public function toString()
* Validates the element instance and set it's default values.
*
* @return void
- * @throws PEAR2_Console_CommandLine_Exception
+ * @throws pear2\Console\CommandLine_Exception
*/
public function validate()
{
View
21 src/Console/CommandLine/Exception.php
@@ -3,7 +3,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * This file is part of the PEAR2_Console_CommandLine package.
+ * This file is part of the pear2\Console\CommandLine package.
*
* PHP version 5
*
@@ -12,7 +12,7 @@
* http://opensource.org/licenses/mit-license.php
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -23,10 +23,10 @@
*/
/**
- * Class for exceptions raised by the PEAR2_Console_CommandLine package.
+ * Class for exceptions raised by the pear2\Console\CommandLine package.
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -34,7 +34,8 @@
* @link http://pear.php.net/package/Console_CommandLine
* @since Class available since release 0.1.0
*/
-class PEAR2_Console_CommandLine_Exception extends \pear2\Exception
+namespace pear2\Console\CommandLine;
+class Exception extends \pear2\Exception
{
// Codes constants {{{
@@ -59,17 +60,17 @@ class PEAR2_Console_CommandLine_Exception extends \pear2\Exception
* @param string $code The string identifier of the
* exception.
* @param array $params Array of template vars/values
- * @param PEAR2_Console_CommandLine $parser An instance of the parser
+ * @param pear2\Console\CommandLine $parser An instance of the parser
* @param array $messages An optional array of messages
* passed to the message provider.
*
- * @return PEAR2_Console_CommandLine_Exception The exception instance
+ * @return pear2\Console\CommandLine_Exception The exception instance
*/
public static function factory(
$code, $params, $parser, array $messages = array()
) {
$provider = $parser->message_provider;
- if ($provider instanceof PEAR2_Console_CommandLine_CustomMessageProvider) {
+ if ($provider instanceof CommandLine\CustomMessageProvider) {
$msg = $provider->getWithCustomMessages(
$code,
$params,
@@ -78,9 +79,9 @@ public static function factory(
} else {
$msg = $provider->get($code, $params);
}
- $const = 'PEAR2_Console_CommandLine_Exception::' . $code;
+ $const = '\pear2\Console\CommandLine\Exception::' . $code;
$code = defined($const) ? constant($const) : 0;
- return new PEAR2_Console_CommandLine_Exception($msg, $code);
+ return new Exception($msg, $code);
}
// }}}
View
11 src/Console/CommandLine/MessageProvider.php
@@ -3,7 +3,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * This file is part of the PEAR2_Console_CommandLine package.
+ * This file is part of the pear2\Console\CommandLine package.
*
* PHP version 5
*
@@ -12,7 +12,7 @@
* http://opensource.org/licenses/mit-license.php
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -27,7 +27,7 @@
* this interface.
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -35,7 +35,8 @@
* @link http://pear.php.net/package/Console_CommandLine
* @since Class available since release 0.1.0
*/
-interface PEAR2_Console_CommandLine_MessageProvider
+namespace pear2\Console\CommandLine;
+interface MessageProvider
{
// get() {{{
@@ -48,7 +49,7 @@
* @param array $vars An array of template variables
*
* @return string
- * @see PEAR2_Console_CommandLine_MessageProvider_Default
+ * @see pear2\Console\CommandLine_MessageProvider_Default
*/
public function get($code, $vars=array());
View
15 src/Console/CommandLine/MessageProvider/Default.php
@@ -3,7 +3,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * This file is part of the PEAR2_Console_CommandLine package.
+ * This file is part of the pear2\Console\CommandLine package.
*
* PHP version 5
*
@@ -12,7 +12,7 @@
* http://opensource.org/licenses/mit-license.php
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -24,12 +24,12 @@
/**
- * Lightweight class that manages messages used by PEAR2_Console_CommandLine package,
+ * Lightweight class that manages messages used by pear2\Console\CommandLine package,
* allowing the developper to customize these messages, for example to
* internationalize a command line frontend.
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -37,9 +37,10 @@
* @link http://pear.php.net/package/Console_CommandLine
* @since Class available since release 0.1.0
*/
-class PEAR2_Console_CommandLine_MessageProvider_Default
- implements PEAR2_Console_CommandLine_MessageProvider,
- PEAR2_Console_CommandLine_CustomMessageProvider
+namespace pear2\Console\CommandLine;
+class MessageProvider_Default
+ implements MessageProvider,
+ CustomMessageProvider
{
// Properties {{{
View
44 src/Console/CommandLine/Option.php
@@ -3,7 +3,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * This file is part of the PEAR2_Console_CommandLine package.
+ * This file is part of the pear2\Console\CommandLine package.
*
* PHP version 5
*
@@ -12,7 +12,7 @@
* http://opensource.org/licenses/mit-license.php
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -26,7 +26,7 @@
* Class that represent a commandline option.
*
* @category Console
- * @package PEAR2_Console_CommandLine
+ * @package pear2\Console\CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
@@ -34,7 +34,11 @@
* @link http://pear.php.net/package/Console_CommandLine
* @since Class available since release 0.1.0
*/
-class PEAR2_Console_CommandLine_Option extends PEAR2_Console_CommandLine_Element
+namespace pear2\Console\CommandLine;
+
+use pear2\Console;
+
+class Option extends Element
{
// Public properties {{{
@@ -223,18 +227,18 @@ public function expectsArgument()
/**
* Formats the value $value according to the action of the option and
- * updates the passed PEAR2_Console_CommandLine_Result object.
+ * updates the passed pear2\Console\CommandLine_Result object.
*
* @param mixed $value The value to format
- * @param PEAR2_Console_CommandLine_Result $result The result instance
- * @param PEAR2_Console_CommandLine $parser The parser instance
+ * @param pear2\Console\CommandLine_Result $result The result instance
+ * @param pear2\Console\CommandLine $parser The parser instance
*
* @return void
- * @throws PEAR2_Console_CommandLine_Exception
+ * @throws pear2\Console\CommandLine_Exception
*/
public function dispatchAction($value, $result, $parser)
{
- $actionInfo = PEAR2_Console_CommandLine::$actions[$this->action];
+ $actionInfo = Console\CommandLine::$actions[$this->action];
$clsname = $actionInfo[0];
if ($this->_action_instance === null) {
$this->_action_instance = new $clsname($result, $this, $parser);
@@ -242,7 +246,7 @@ public function dispatchAction($value, $result, $parser)
// check value is in option choices
if (!empty($this->choices) && !in_array($this->_action_instance->format($value), $this->choices)) {
- throw PEAR2_Console_CommandLine_Exception::factory(
+ throw Console\CommandLine\Exception::factory(
'OPTION_VALUE_NOT_VALID',
array(
'name' => $this->name,
@@ -263,7 +267,7 @@ public function dispatchAction($value, $result, $parser)
* Validates the option instance.
*
* @return void
- * @throws PEAR2_Console_CommandLine_Exception
+ * @throws pear2\Console\CommandLine_Exception
* @todo use exceptions instead
*/
public function validate()
@@ -271,20 +275,20 @@ public function validate()
// check if the option name is valid
if (!preg_match('/^[a-zA-Z_\x7f-\xff]+[a-zA-Z0-9_\x7f-\xff]*$/',
$this->name)) {
- PEAR2_Console_CommandLine::triggerError('option_bad_name',
+ Console\CommandLine::triggerError('option_bad_name',
E_USER_ERROR, array('{$name}' => $this->name));
}
// call the parent validate method
parent::validate();
// a short_name or a long_name must be provided
if ($this->short_name == null && $this->long_name == null) {
- PEAR2_Console_CommandLine::triggerError('option_long_and_short_name_missing',
+ Console\CommandLine::triggerError('option_long_and_short_name_missing',
E_USER_ERROR, array('{$name}' => $this->name));
}
// check if the option short_name is valid
if ($this->short_name != null &&
!(preg_match('/^\-[a-zA-Z]{1}$/', $this->short_name))) {
- PEAR2_Console_CommandLine::triggerError('option_bad_short_name',
+ Console\CommandLine::triggerError('option_bad_short_name',
E_USER_ERROR, array(
'{$name}' => $this->name,
'{$short_name}' => $this->short_name
@@ -293,7 +297,7 @@ public function validate()
// check if the option long_name is valid
if ($this->long_name != null &&
!preg_match('/^\-\-[a-zA-Z]+[a-zA-Z0-9_\-]*$/', $this->long_name)) {
- PEAR2_Console_CommandLine::triggerError('option_bad_long_name',
+ Console\CommandLine::triggerError('option_bad_long_name',
E_USER_ERROR, array(
'{$name}' => $this->name,
'{$long_name}' => $this->long_name
@@ -301,11 +305,11 @@ public function validate()
}
// check if we have a valid action
if (!is_string($this->action)) {
- PEAR2_Console_CommandLine::triggerError('option_bad_action',
+ Console\CommandLine::triggerError('option_bad_action',
E_USER_ERROR, array('{$name}' => $this->name));
}
- if (!isset(PEAR2_Console_CommandLine::$actions[$this->action])) {
- PEAR2_Console_CommandLine::triggerError('option_unregistered_action',
+ if (!isset(Console\CommandLine::$actions[$this->action])) {
+ Console\CommandLine::triggerError('option_unregistered_action',
E_USER_ERROR, array(
'{$action}' => $this->action,
'{$name}' => $this->name
@@ -313,7 +317,7 @@ public function validate()
}
// if the action is a callback, check that we have a valid callback
if ($this->action == 'Callback' && !is_callable($this->callback)) {
- PEAR2_Console_CommandLine::triggerError('option_invalid_callback',
+ Console\CommandLine::triggerError('option_invalid_callback',