Permalink
Browse files

PEAR2_Console_CommandLine is now up-to-date ! All tests pass.

  • Loading branch information...
izimobil committed Jun 3, 2009
1 parent 1e22d0b commit ba63247f557c511e6168c111e2835edcefcdb434
Showing with 1,364 additions and 670 deletions.
  1. +1 −1 CREDITS
  2. +22 −15 data/xmlschema.rng
  3. +5 −4 examples/ex1.php
  4. +3 −3 examples/ex2.php
  5. +92 −0 examples/ex3.php
  6. +55 −0 examples/ex4.php
  7. +37 −0 examples/ex4.xml
  8. +1 −1 makepackage.php
  9. +142 −147 src/Console/CommandLine.php
  10. +17 −26 src/Console/CommandLine/Action.php
  11. +7 −9 src/Console/CommandLine/Action/Callback.php
  12. +7 −9 src/Console/CommandLine/Action/Counter.php
  13. +7 −9 src/Console/CommandLine/Action/Help.php
  14. +68 −0 src/Console/CommandLine/Action/List.php
  15. +10 −12 src/Console/CommandLine/Action/Password.php
  16. +7 −9 src/Console/CommandLine/Action/StoreArray.php
  17. +8 −9 src/Console/CommandLine/Action/StoreFalse.php
  18. +9 −11 src/Console/CommandLine/Action/StoreFloat.php
  19. +9 −11 src/Console/CommandLine/Action/StoreInt.php
  20. +7 −9 src/Console/CommandLine/Action/StoreString.php
  21. +7 −9 src/Console/CommandLine/Action/StoreTrue.php
  22. +7 −9 src/Console/CommandLine/Action/Version.php
  23. +20 −10 src/Console/CommandLine/Argument.php
  24. +3 −4 src/Console/CommandLine/Command.php
  25. +15 −19 src/Console/CommandLine/Element.php
  26. +9 −12 src/Console/CommandLine/Exception.php
  27. +9 −8 src/Console/CommandLine/MessageProvider.php
  28. +12 −14 src/Console/CommandLine/MessageProvider/Default.php
  29. +103 −83 src/Console/CommandLine/Option.php
  30. +7 −10 src/Console/CommandLine/Outputter.php
  31. +7 −10 src/Console/CommandLine/Outputter/Default.php
  32. +10 −14 src/Console/CommandLine/Renderer.php
  33. +56 −51 src/Console/CommandLine/Renderer/Default.php
  34. +8 −13 src/Console/CommandLine/Result.php
  35. +36 −50 src/Console/CommandLine/XmlParser.php
  36. +2 −2 tests/AllTests.php
  37. +24 −4 tests/console_commandline_addargument.phpt
  38. +49 −4 tests/console_commandline_addoption.phpt
  39. +6 −4 tests/console_commandline_fromxmlfile.phpt
  40. +6 −4 tests/console_commandline_fromxmlstring.phpt
  41. +34 −0 tests/console_commandline_options_defaults.phpt
  42. +3 −3 tests/console_commandline_parse_13.phpt
  43. +3 −3 tests/console_commandline_parse_14.phpt
  44. +3 −3 tests/console_commandline_parse_15.phpt
  45. +3 −3 tests/console_commandline_parse_16.phpt
  46. +2 −2 tests/console_commandline_parse_17.phpt
  47. +1 −1 tests/console_commandline_parse_18.phpt
  48. +57 −0 tests/console_commandline_parse_19.phpt
  49. +2 −2 tests/console_commandline_parse_2.phpt
  50. +17 −0 tests/console_commandline_parse_20.phpt
  51. +47 −0 tests/console_commandline_parse_21.phpt
  52. +27 −0 tests/console_commandline_parse_22.phpt
  53. +2 −2 tests/console_commandline_parse_4.phpt
  54. +2 −2 tests/console_commandline_parse_5.phpt
  55. +5 −5 tests/console_commandline_parse_6.phpt
  56. +0 −1 tests/console_commandline_parse_7.phpt
  57. +2 −2 tests/console_commandline_parse_9.phpt
  58. +2 −2 tests/console_commandline_webrequest_1.phpt
  59. +2 −2 tests/console_commandline_webrequest_2.phpt
  60. +2 −2 tests/console_commandline_webrequest_3.phpt
  61. +19 −5 tests/test.xml
  62. +219 −11 tests/tests.inc.php
View
@@ -1,3 +1,3 @@
-; Maintainers of Console_CommandLine
+; Maintainers of PEAR2_Console_CommandLine
David JEAN LOUIS [izi] <izi@php.net> (lead)
View
@@ -66,21 +66,23 @@
<!-- options and arguments common elements -->
<define name="ref_option_argument_common">
- <optional>
- <element name="description">
- <text/>
- </element>
- </optional>
- <optional>
- <element name="help_name">
- <text/>
- </element>
- </optional>
- <optional>
- <element name="default">
- <text/>
- </element>
- </optional>
+ <interleave>
+ <optional>
+ <element name="description">
+ <text/>
+ </element>
+ </optional>
+ <optional>
+ <element name="help_name">
+ <text/>
+ </element>
+ </optional>
+ <optional>
+ <element name="default">
+ <text/>
+ </element>
+ </optional>
+ </interleave>
</define>
<!-- Option node -->
@@ -115,6 +117,11 @@
</zeroOrMore>
</element>
</optional>
+ <optional>
+ <element name="add_list_option">
+ <ref name="ref_bool_choices"/>
+ </element>
+ </optional>
</interleave>
</element>
</define>
View
@@ -18,16 +18,16 @@
* @category Console
* @package PEAR2_Console_CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
- * @copyright 2007 David JEAN LOUIS
+ * @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
* @version SVN: $Id$
* @link http://pear.php.net/package/Console_CommandLine
* @since File available since release 0.1.0
*/
// uncomment this when package won't be in the SandBox anymore
-// $basedir = __DIR__ . '/..';
-$basedir = __DIR__ . '/../..';
+// $basedir = __DIR__ . '/../..';
+$basedir = __DIR__ . '/../../..';
// Include PEAR2 autoload
require_once $basedir . '/autoload.php';
@@ -52,7 +52,8 @@
'long_name' => '--delete',
'action' => 'StoreString',
'description' => 'delete original files after zip operation',
- 'choices' => array('foo', 'bar')
+ 'choices' => array('foo', 'bar'),
+ 'add_list_option' => true
));
// add the files argument, the user can specify one or several files
View
@@ -17,16 +17,16 @@
* @category Console
* @package PEAR2_Console_CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
- * @copyright 2007 David JEAN LOUIS
+ * @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
* @version SVN: $Id$
* @link http://pear.php.net/package/Console_CommandLine
* @since File available since release 0.1.0
*/
// uncomment this when package won't be in the SandBox anymore
-// $basedir = __DIR__ . '/..';
-$basedir = __DIR__ . '/../..';
+// $basedir = __DIR__ . '/../..';
+$basedir = __DIR__ . '/../../..';
// Include PEAR2 autoload
require_once $basedir . '/autoload.php';
View
@@ -0,0 +1,92 @@
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * This file is part of the PEAR PEAR2_Console_CommandLine package.
+ *
+ * A simple example demonstrating the use of subcommands.
+ *
+ * PHP version 5
+ *
+ * LICENSE: This source file is subject to the MIT license that is available
+ * through the world-wide-web at the following URI:
+ * http://opensource.org/licenses/mit-license.php
+ *
+ * @category Console
+ * @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
+ * @version CVS: $Id: ex3.php,v 1.1 2008/12/06 11:46:28 izi Exp $
+ * @link http://pear.php.net/package/Console_CommandLine
+ * @since File available since release 0.1.0
+ */
+
+// uncomment this when package won't be in the SandBox anymore
+// $basedir = __DIR__ . '/../..';
+$basedir = __DIR__ . '/../../..';
+
+// Include PEAR2 autoload
+require_once $basedir . '/autoload.php';
+
+// create the parser
+$parser = new PEAR2_Console_CommandLine(array(
+ 'description' => 'A great program that can foo and bar !',
+ 'version' => '1.0.0'
+));
+
+// add a global option to make the program verbose
+$parser->addOption('verbose', array(
+ 'short_name' => '-v',
+ 'long_name' => '--verbose',
+ 'action' => 'StoreTrue',
+ 'description' => 'turn on verbose output'
+));
+
+// add the foo subcommand
+$foo_cmd = $parser->addCommand('foo', array(
+ 'description' => 'output the given string with a foo prefix'
+));
+$foo_cmd->addOption('reverse', array(
+ 'short_name' => '-r',
+ 'long_name' => '--reverse',
+ 'action' => 'StoreTrue',
+ 'description' => 'reverse the given string before echoing it'
+));
+$foo_cmd->addArgument('text', array(
+ 'description' => 'the text to output'
+));
+
+// add the bar subcommand
+$bar_cmd = $parser->addCommand('bar', array(
+ 'description' => 'output the given string with a bar prefix'
+));
+$bar_cmd->addOption('reverse', array(
+ 'short_name' => '-r',
+ 'long_name' => '--reverse',
+ 'action' => 'StoreTrue',
+ 'description' => 'reverse the given string before echoing it'
+));
+$bar_cmd->addArgument('text', array(
+ 'description' => 'the text to output'
+));
+
+// run the parser
+try {
+ $result = $parser->parse();
+ if ($result->command_name) {
+ $st = $result->command->options['reverse']
+ ? strrev($result->command->args['text'])
+ : $result->command->args['text'];
+ if ($result->command_name == 'foo') {
+ echo "Foo says: $st\n";
+ } else if ($result->command_name == 'bar') {
+ echo "Bar says: $st\n";
+ }
+ }
+} catch (Exception $exc) {
+ $parser->displayError($exc->getMessage());
+}
+
+?>
View
@@ -0,0 +1,55 @@
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * This file is part of the PEAR PEAR2_Console_CommandLine package.
+ *
+ * A simple example demonstrating the use of subcommands.
+ * (Same as ex3.php but using an xml file).
+ *
+ * PHP version 5
+ *
+ * LICENSE: This source file is subject to the MIT license that is available
+ * through the world-wide-web at the following URI:
+ * http://opensource.org/licenses/mit-license.php
+ *
+ * @category Console
+ * @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
+ * @version CVS: $Id: ex4.php,v 1.1 2008/12/06 11:46:28 izi Exp $
+ * @link http://pear.php.net/package/Console_CommandLine
+ * @since File available since release 0.1.0
+ */
+
+// uncomment this when package won't be in the SandBox anymore
+// $basedir = __DIR__ . '/../..';
+$basedir = __DIR__ . '/../../..';
+
+// Include PEAR2 autoload
+require_once $basedir . '/autoload.php';
+
+// create the parser
+$xmlfile = __DIR__ . DIRECTORY_SEPARATOR . 'ex4.xml';
+$parser = PEAR2_Console_CommandLine::fromXmlFile($xmlfile);
+
+// run the parser
+try {
+ $result = $parser->parse();
+ if ($result->command_name) {
+ $st = $result->command->options['reverse']
+ ? strrev($result->command->args['text'])
+ : $result->command->args['text'];
+ if ($result->command_name == 'foo') {
+ echo "Foo says: $st\n";
+ } else if ($result->command_name == 'bar') {
+ echo "Bar says: $st\n";
+ }
+ }
+} catch (Exception $exc) {
+ $parser->displayError($exc->getMessage());
+}
+
+?>
View
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes"?>
+<command>
+ <description>A great program that can foo and bar !</description>
+ <version>1.0.0</version>
+ <option name="verbose">
+ <short_name>-v</short_name>
+ <long_name>--verbose</long_name>
+ <description>turn on verbose output</description>
+ <action>StoreTrue</action>
+ </option>
+ <command>
+ <name>foo</name>
+ <description>output the given string with a foo prefix</description>
+ <option name="reverse">
+ <short_name>-r</short_name>
+ <long_name>--reverse</long_name>
+ <description>reverse the string before echoing it</description>
+ <action>StoreTrue</action>
+ </option>
+ <argument name="text">
+ <description>the text to output</description>
+ </argument>
+ </command>
+ <command>
+ <name>bar</name>
+ <description>output the given string with a bar prefix</description>
+ <option name="reverse">
+ <short_name>-r</short_name>
+ <long_name>--reverse</long_name>
+ <description>reverse the string before echoing it</description>
+ <action>StoreTrue</action>
+ </option>
+ <argument name="text">
+ <description>the text to output</description>
+ </argument>
+ </command>
+</command>
View
@@ -18,7 +18,7 @@
* @category Console
* @package PEAR2_Console_CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
- * @copyright 2007 David JEAN LOUIS
+ * @copyright 2007-2009 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
* @version SVN: $Id$
* @link http://pear.php.net/package/Console_CommandLine
Oops, something went wrong.

0 comments on commit ba63247

Please sign in to comment.