Mercurial > hg > rc1
comparison vendor/pear/console_commandline/Console/CommandLine/Argument.php @ 0:1e000243b222
vanilla 1.3.3 distro, I hope
| author | Charlie Root |
|---|---|
| date | Thu, 04 Jan 2018 15:50:29 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:1e000243b222 |
|---|---|
| 1 <?php | |
| 2 | |
| 3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 4 | |
| 5 /** | |
| 6 * This file is part of the PEAR Console_CommandLine package. | |
| 7 * | |
| 8 * PHP version 5 | |
| 9 * | |
| 10 * LICENSE: This source file is subject to the MIT license that is available | |
| 11 * through the world-wide-web at the following URI: | |
| 12 * http://opensource.org/licenses/mit-license.php | |
| 13 * | |
| 14 * @category Console | |
| 15 * @package Console_CommandLine | |
| 16 * @author David JEAN LOUIS <izimobil@gmail.com> | |
| 17 * @copyright 2007 David JEAN LOUIS | |
| 18 * @license http://opensource.org/licenses/mit-license.php MIT License | |
| 19 * @version CVS: $Id$ | |
| 20 * @link http://pear.php.net/package/Console_CommandLine | |
| 21 * @since File available since release 0.1.0 | |
| 22 * @filesource | |
| 23 */ | |
| 24 | |
| 25 /** | |
| 26 * Include base element class. | |
| 27 */ | |
| 28 require_once 'Console/CommandLine/Element.php'; | |
| 29 | |
| 30 /** | |
| 31 * Class that represent a command line argument. | |
| 32 * | |
| 33 * @category Console | |
| 34 * @package Console_CommandLine | |
| 35 * @author David JEAN LOUIS <izimobil@gmail.com> | |
| 36 * @copyright 2007 David JEAN LOUIS | |
| 37 * @license http://opensource.org/licenses/mit-license.php MIT License | |
| 38 * @version Release: @package_version@ | |
| 39 * @link http://pear.php.net/package/Console_CommandLine | |
| 40 * @since Class available since release 0.1.0 | |
| 41 */ | |
| 42 class Console_CommandLine_Argument extends Console_CommandLine_Element | |
| 43 { | |
| 44 // Public properties {{{ | |
| 45 | |
| 46 /** | |
| 47 * Setting this to true will tell the parser that the argument expects more | |
| 48 * than one argument and that argument values should be stored in an array. | |
| 49 * | |
| 50 * @var boolean $multiple Whether the argument expects multiple values | |
| 51 */ | |
| 52 public $multiple = false; | |
| 53 | |
| 54 /** | |
| 55 * Setting this to true will tell the parser that the argument is optional | |
| 56 * and can be ommited. | |
| 57 * Note that it is not a good practice to make arguments optional, it is | |
| 58 * the role of the options to be optional, by essence. | |
| 59 * | |
| 60 * @var boolean $optional Whether the argument is optional or not. | |
| 61 */ | |
| 62 public $optional = false; | |
| 63 | |
| 64 /** | |
| 65 * An array of possible values for the argument. | |
| 66 * | |
| 67 * @var array $choices Valid choices for the argument | |
| 68 */ | |
| 69 public $choices = array(); | |
| 70 | |
| 71 // }}} | |
| 72 // validate() {{{ | |
| 73 | |
| 74 /** | |
| 75 * Validates the argument instance. | |
| 76 * | |
| 77 * @return void | |
| 78 * @throws Console_CommandLine_Exception | |
| 79 * @todo use exceptions | |
| 80 */ | |
| 81 public function validate() | |
| 82 { | |
| 83 // check if the argument name is valid | |
| 84 if (!preg_match('/^[a-zA-Z_\x7f-\xff]+[a-zA-Z0-9_\x7f-\xff]*$/', | |
| 85 $this->name)) { | |
| 86 Console_CommandLine::triggerError( | |
| 87 'argument_bad_name', | |
| 88 E_USER_ERROR, | |
| 89 array('{$name}' => $this->name) | |
| 90 ); | |
| 91 } | |
| 92 if (!$this->optional && $this->default !== null) { | |
| 93 Console_CommandLine::triggerError( | |
| 94 'argument_no_default', | |
| 95 E_USER_ERROR | |
| 96 ); | |
| 97 } | |
| 98 parent::validate(); | |
| 99 } | |
| 100 | |
| 101 // }}} | |
| 102 } |
