function get_console_options_for($description, $console_configuration) { global $script_name, $argv; $args =& Console_Getargs::factory($console_configuration); if (PEAR::isError($args)) { $replacements = array('-p --parameters values(1-...)' => 'install plugin_name,URL ...', 'Usage: ' . basename(__FILE__) => "Usage: {$script_name}", '[param1] ' => 'plugin_name PLUGIN_URL'); echo "\n{$description}\n" . str_repeat('-', strlen($description) + 1) . "\n"; if ($args->getCode() === CONSOLE_GETARGS_ERROR_USER) { echo str_replace(array_keys($replacements), array_values($replacements), Console_Getargs::getHelp($console_configuration, null, $args->getMessage())) . "\n"; } else { if ($args->getCode() === CONSOLE_GETARGS_HELP) { echo str_replace(array_keys($replacements), array_values($replacements), @Console_Getargs::getHelp($console_configuration)) . "\n"; } } exit; } return $args->getValues(); }
/** * constructor * */ public function __construct() { $console_config = $this->getConfigArray(); $configArray = array(); // cli view argument definition $configArray['view'] = array('short' => 'v', 'min' => 1, 'max' => 1, 'desc' => 'Set the view to execute.'); $console_config = array_merge($configArray, $console_config); $this->args =& Console_Getargs::factory($console_config); if (PEAR::isError($this->args)) { $mes = ''; if ($this->args->getCode() === CONSOLE_GETARGS_ERROR_USER) { $mes = Console_Getargs::getHelp($console_config, null, $this->args->getMessage()) . "\n\n"; } else { if ($this->args->getCode() === CONSOLE_GETARGS_HELP) { $mes = Console_Getargs::getHelp($console_config) . "\n\n"; } } $this->printError($mes); } }
/** * ZE2 Constructor * * @since 1.8.0 */ function __construct() { $this->opts = array('php-dir' => array('short' => 'pd', 'desc' => 'PEAR directory', 'default' => '', 'min' => 0, 'max' => 1), 'usr-cfg' => array('short' => 'uc', 'desc' => 'User Configuration File', 'default' => '', 'min' => 0, 'max' => 1), 'sys-cfg' => array('short' => 'sc', 'desc' => 'System Configuration File', 'default' => '', 'min' => 0, 'max' => 1), 'http-proxy' => array('short' => 'hp', 'desc' => 'HTTP Proxy Server Address', 'default' => '', 'min' => 0, 'max' => 1), 'all' => array('short' => 'a', 'desc' => 'Display informations for installed packages', 'default' => PEAR_INFO_ALL, 'min' => 0, 'max' => 1), 'allchannels' => array('short' => 'A', 'desc' => 'List packages from all channels, ' . 'not just the default one', 'max' => 0), 'channel' => array('short' => 'c', 'desc' => 'Specify which channel', 'default' => '', 'min' => 0, 'max' => 1), 'version' => array('short' => 'V', 'desc' => 'Print version information', 'max' => 0), 'help' => array('short' => 'h', 'desc' => 'Show this help', 'max' => 0)); $this->args =& Console_Getargs::factory($this->opts); if (PEAR::isError($this->args)) { if ($this->args->getCode() === CONSOLE_GETARGS_HELP) { $this->error = ''; } else { $this->error = $this->args->getMessage(); } return; } $options = array('channels' => array('pear.php.net'), 'resume' => PEAR_INFO_ALL); // php-dir if ($this->args->isDefined('pd')) { $pear_dir = $this->args->getValue('pd'); } else { $pear_dir = ''; } // usr-cfg if ($this->args->isDefined('uc')) { $user_file = $this->args->getValue('uc'); if (!file_exists($user_file)) { $this->error = 'Failed opening PEAR user configuration file "' . $user_file . '". Please check your spelling and try again.'; return; } } else { $user_file = ''; } // sys-cfg if ($this->args->isDefined('sc')) { $system_file = $this->args->getValue('sc'); if (!file_exists($system_file)) { $this->error = 'Failed opening PEAR system configuration file "' . $system_file . '". Please check your spelling and try again.'; return; } } else { $system_file = ''; } // http-proxy if ($this->args->isDefined('hp')) { $proxy = $this->args->getValue('hp'); $res = PEAR_Info::setProxy($proxy); if ($res === false) { $this->error = 'Failed define Proxy Server Address.' . ' Please check your spelling and try again.'; return; } } // all if ($this->args->isDefined('a')) { $a = $this->args->getValue('a'); if (is_numeric($a)) { $options['resume'] = intval($a); } else { $this->error = "No valid 'resume' option for argument all." . ' Please check your spelling and try again.'; return; } } // allchannels $A = $this->args->getValue('A'); if (isset($A)) { $options['channels'] = array(); } // channel if ($this->args->isDefined('c')) { $chan = $this->args->getValue('c'); if (is_string($chan)) { $options['channels'] = explode(',', $chan); } else { $this->error = 'No valid channel list provided.' . ' Please check your spelling and try again.'; return; } } // version $V = $this->args->getValue('V'); if (isset($V)) { $this->error = 'PEAR_Info (cli) version 1.9.2' . ' (http://pear.php.net/package/PEAR_Info)'; return; } parent::__construct($pear_dir, $user_file, $system_file, $options); }
<?php /** * Example for Console_Getargs class * * $Id: example.php,v 1.7 2004/10/14 20:44:41 scottmattocks Exp $ */ require_once 'Console/Getargs.php'; $config = array('files|images' => array('short' => 'f|i', 'min' => 2, 'max' => 2, 'desc' => 'Set the source and destination image files.'), 'width' => array('short' => 'w', 'min' => 1, 'max' => 1, 'desc' => 'Set the new width of the image.'), 'debug' => array('short' => 'd', 'max' => 0, 'desc' => 'Switch to debug mode.'), 'formats' => array('min' => 1, 'max' => 3, 'desc' => 'Set the image destination format.', 'default' => array('jpegbig', 'jpegsmall')), 'filters' => array('short' => 'fi', 'min' => 1, 'max' => -1, 'desc' => 'Set the filters to be applied to the image upon conversion. The filters will be used in the order they are set.'), 'verbose' => array('short' => 'v', 'min' => 0, 'max' => 1, 'desc' => 'Set the verbose level.', 'default' => 3), CONSOLE_GETARGS_PARAMS => array('min' => 1, 'max' => 2, 'desc' => 'Set the application parameters.', 'default' => 'DEFAULT')); $args =& Console_Getargs::factory($config); // Use the following two lines to test passing an array // other than $_SERVER['argv'] //$test = array('-dvw', 500, 'foo1', 'foo2'); //$args =& Console_Getargs::factory($config, $test); if (PEAR::isError($args)) { $header = "Console_Getargs Example\n" . 'Usage: ' . basename($_SERVER['SCRIPT_NAME']) . " [options]\n\n"; if ($args->getCode() === CONSOLE_GETARGS_ERROR_USER) { echo Console_Getargs::getHelp($config, $header, $args->getMessage()) . "\n"; } else { if ($args->getCode() === CONSOLE_GETARGS_HELP) { echo Console_Getargs::getHelp($config, $header) . "\n"; // To see the automatic header uncomment this line //echo Console_Getargs::getHelp($config)."\n"; } } exit; } echo 'Verbose: ' . $args->getValue('verbose') . "\n"; echo 'Formats: ' . (is_array($args->getValue('formats')) ? implode(', ', $args->getValue('formats')) . "\n" : $args->getValue('formats') . "\n"); echo 'Files: ' . ($args->isDefined('files') ? implode(', ', $args->getValue('files')) . "\n" : "undefined\n"); if ($args->isDefined('fi')) {
function Version() { $config = array("server" => array('short' => 's', 'max' => 1, 'min' => 1, 'desc' => "server URL", 'default' => ""), "debug" => array('short' => 'd', 'max' => 1, 'min' => 1, 'desc' => "debug level", 'default' => "0")); $args =& Console_Getargs::factory($config); if (PEAR::isError($args)) { die(Console_Getargs::getHelp($config) . "\n"); } echo "PHP Fedora Client class version " . FedoraClient::VERSION . "\n"; $client = new FedoraPkgdb(array('debug' => intval($args->getValue('debug')), 'server' => $args->getValue('server'))); echo "pkgdb version " . $client->getVersion() . "\n"; }
/** * Run the CLI version * * Run the CLI version of PHP_CompatInfo * * @return void * @access public * @since version 0.8.0 (2004-04-22) */ function run() { $args =& Console_Getargs::factory($this->opts); if (PEAR::isError($args)) { if ($args->getCode() === CONSOLE_GETARGS_HELP) { $error = ''; } else { $error = $args->getMessage(); } $this->_printUsage($error); return; } // default parser options $this->options = array('file_ext' => array('php', 'php4', 'inc', 'phtml'), 'recurse_dir' => true, 'debug' => false, 'is_string' => false, 'ignore_files' => array(), 'ignore_dirs' => array()); // version $V = $args->getValue('V'); if (isset($V)) { $error = 'PHP_CompatInfo (cli) version 1.8.1' . ' (http://pear.php.net/package/PHP_CompatInfo)'; echo $error; return; } // debug if ($args->isDefined('v')) { $v = $args->getValue('v'); if ($v > 3) { $this->options['debug'] = true; } } // no-recurse if ($args->isDefined('n')) { $this->options['recurse_dir'] = false; } // dir if ($args->isDefined('d')) { $d = $args->getValue('d'); if (file_exists($d)) { if ($d[strlen($d) - 1] == '/' || $d[strlen($d) - 1] == '\\') { $d = substr($d, 0, -1); } $this->dataSource = realpath($d); } else { $error = 'Failed opening directory "' . $d . '". Please check your spelling and try again.'; $this->_printUsage($error); return; } } // file if ($args->isDefined('f')) { $f = $args->getValue('f'); if (file_exists($f)) { $this->dataSource = $f; } else { $error = 'Failed opening file "' . $f . '". Please check your spelling and try again.'; $this->_printUsage($error); return; } } // string if ($args->isDefined('s')) { $s = $args->getValue('s'); if (!empty($s)) { $this->dataSource = sprintf("<?php %s ?>", $s); $this->options['is_string'] = true; } else { $error = 'Failed opening string "' . $s . '". Please check your spelling and try again.'; $this->_printUsage($error); return; } } // ignore-files $if = $args->getValue('if'); if (isset($if)) { if (file_exists($if)) { $options = $this->_parseParamFile($if); $this->options['ignore_files'] = $options['std']; } else { $error = 'Failed opening file "' . $if . '" (ignore-files option). ' . 'Please check your spelling and try again.'; $this->_printUsage($error); return; } } // ignore-dirs $id = $args->getValue('id'); if (isset($id)) { if (file_exists($id)) { $options = $this->_parseParamFile($id); $this->options['ignore_dirs'] = $options['std']; } else { $error = 'Failed opening file "' . $id . '" (ignore-dirs option). ' . 'Please check your spelling and try again.'; $this->_printUsage($error); return; } } // ignore-functions $in = $args->getValue('in'); if (isset($in)) { if (file_exists($in)) { $options = $this->_parseParamFile($in); $this->options['ignore_functions'] = $options['std']; } else { $error = 'Failed opening file "' . $in . '" (ignore-functions option). ' . 'Please check your spelling and try again.'; $this->_printUsage($error); return; } } // ignore-constants $ic = $args->getValue('ic'); if (isset($ic)) { if (file_exists($ic)) { $options = $this->_parseParamFile($ic); $this->options['ignore_constants'] = $options['std']; } else { $error = 'Failed opening file "' . $ic . '" (ignore-constants option). ' . 'Please check your spelling and try again.'; $this->_printUsage($error); return; } } // ignore-extensions $ie = $args->getValue('ie'); if (isset($ie)) { if (file_exists($ie)) { $options = $this->_parseParamFile($ie); $this->options['ignore_extensions'] = $options['std']; } else { $error = 'Failed opening file "' . $ie . '" (ignore-extensions option). ' . 'Please check your spelling and try again.'; $this->_printUsage($error); return; } } // ignore-versions $iv = $args->getValue('iv'); if (isset($iv)) { if (!is_array($iv)) { $iv = array($iv); } $this->options['ignore_versions'] = $iv; } // ignore-functions-match $inm = $args->getValue('inm'); if (isset($inm)) { if (file_exists($inm)) { $patterns = $this->_parseParamFile($inm, true); if (count($patterns['std']) > 0 && count($patterns['reg']) > 0) { $error = 'Mixed "function_exists" and ' . '"preg_match" conditions are not allowed. ' . 'Please check your spelling and try again.'; $this->_printUsage($error); return; } elseif (count($patterns['std']) > 0) { $this->options['ignore_functions_match'] = array('function_exists', $patterns['std']); } elseif (count($patterns['reg']) > 0) { $this->options['ignore_functions_match'] = array('preg_match', $patterns['reg']); } } else { $error = 'Failed opening file "' . $inm . '" (ignore-functions-match option). ' . 'Please check your spelling and try again.'; $this->_printUsage($error); return; } } // ignore-extensions-match $iem = $args->getValue('iem'); if (isset($iem)) { if (file_exists($iem)) { $patterns = $this->_parseParamFile($iem, true); if (count($patterns['std']) > 0 && count($patterns['reg']) > 0) { $error = 'Mixed "extension_loaded" and ' . '"preg_match" conditions are not allowed. ' . 'Please check your spelling and try again.'; $this->_printUsage($error); return; } elseif (count($patterns['std']) > 0) { $this->options['ignore_extensions_match'] = array('extension_loaded', $patterns['std']); } elseif (count($patterns['reg']) > 0) { $this->options['ignore_extensions_match'] = array('preg_match', $patterns['reg']); } } else { $error = 'Failed opening file "' . $iem . '" (ignore-extensions-match option). ' . 'Please check your spelling and try again.'; $this->_printUsage($error); return; } } // ignore-constants-match $icm = $args->getValue('icm'); if (isset($icm)) { if (file_exists($icm)) { $patterns = $this->_parseParamFile($icm, true); if (count($patterns['std']) > 0 && count($patterns['reg']) > 0) { $error = 'Mixed "defined" and ' . '"preg_match" conditions are not allowed. ' . 'Please check your spelling and try again.'; $this->_printUsage($error); return; } elseif (count($patterns['std']) > 0) { $this->options['ignore_constants_match'] = array('defined', $patterns['std']); } elseif (count($patterns['reg']) > 0) { $this->options['ignore_constants_match'] = array('preg_match', $patterns['reg']); } } else { $error = 'Failed opening file "' . $icm . '" (ignore-constants-match option). ' . 'Please check your spelling and try again.'; $this->_printUsage($error); return; } } // file-ext if ($args->isDefined('d') && $args->isDefined('fe')) { $fe = $args->getValue('fe'); if (is_string($fe)) { $this->options['file_ext'] = explode(',', $fe); } else { $error = 'No valid file extensions provided "' . '". Please check your spelling and try again.'; $this->_printUsage($error); return; } } // file or directory options are minimum required to work if (!$args->isDefined('f') && !$args->isDefined('d') && !$args->isDefined('s')) { $error = 'ERROR: You must supply at least ' . 'one string, file or directory to process'; $this->_printUsage($error); return; } if ($args->isDefined('r')) { $report = $args->getValue('r'); } else { $report = 'text'; } if ($args->isDefined('t')) { $defs = array('f' => 29, 'e' => 12, 'c' => 20); $tabs = $args->getValue('t'); $tabs = explode(',', $tabs); for ($t = 0; $t < 3; $t++) { if (isset($tabs[$t])) { if ($t == 0) { $defs['f'] = (int) $tabs[$t]; } elseif ($t == 1) { $defs['e'] = (int) $tabs[$t]; } else { $defs['c'] = (int) $tabs[$t]; } } } $conf = array('colwidth' => $defs); } else { $conf = array(); } $conf = array_merge($conf, array('args' => $args->getValues())); $compatInfo = new PHP_CompatInfo($report, $conf); // dir if ($args->isDefined('d')) { $d = $args->getValue('d'); $files = $compatInfo->parser->getFilelist($d, $this->options); if (count($files) == 0) { $error = 'No valid files into directory "' . $d . '". Please check your spelling and try again.'; $this->_printUsage($error); return; } } $compatInfo->parseData($this->dataSource, $this->options); }
/** * ZE2 Constructor * @since 0.8.0 */ function __construct($split = null, $glue = null) { $this->split = isset($split) && is_int($split) ? $split : 32; $this->glue = isset($glue) && is_string($glue) ? $glue : '(+)'; $this->opts = array('dir' => array('short' => 'd', 'desc' => 'Parse DIR to get its compatibility info', 'default' => '', 'min' => 0, 'max' => 1), 'file' => array('short' => 'f', 'desc' => 'Parse FILE to get its compatibility info', 'default' => '', 'min' => 0, 'max' => 1), 'verbose' => array('short' => 'v', 'desc' => 'Set the verbose level', 'default' => 1, 'min' => 0, 'max' => 1), 'no-recurse' => array('short' => 'n', 'desc' => 'Do not recursively parse files when using --dir', 'max' => 0), 'ignore-files' => array('short' => 'if', 'desc' => 'Data file name which contains a list of ' . 'file to ignore', 'default' => 'files.txt', 'min' => 0, 'max' => 1), 'ignore-dirs' => array('short' => 'id', 'desc' => 'Data file name which contains a list of ' . 'directory to ignore', 'default' => 'dirs.txt', 'min' => 0, 'max' => 1), 'ignore-functions' => array('short' => 'in', 'desc' => 'Data file name which contains a list of ' . 'php function to ignore', 'default' => 'functions.txt', 'min' => 0, 'max' => 1), 'ignore-constants' => array('short' => 'ic', 'desc' => 'Data file name which contains a list of ' . 'php constant to ignore', 'default' => 'constants.txt', 'min' => 0, 'max' => 1), 'ignore-extensions' => array('short' => 'ie', 'desc' => 'Data file name which contains a list of ' . 'php extension to ignore', 'default' => 'extensions.txt', 'min' => 0, 'max' => 1), 'ignore-versions' => array('short' => 'iv', 'desc' => 'PHP versions - functions to exclude ' . 'when parsing source code', 'default' => '5.0.0', 'min' => 0, 'max' => 2), 'help' => array('short' => 'h', 'desc' => 'Show this help', 'max' => 0)); $this->args =& Console_Getargs::factory($this->opts); if (PEAR::isError($this->args)) { if ($this->args->getCode() === CONSOLE_GETARGS_HELP) { $this->error = ''; } else { $this->error = $this->args->getMessage(); } return; } // debug if ($this->args->isDefined('v')) { $v = $this->args->getValue('v'); if ($v > 3) { $this->options['debug'] = true; } } // no-recurse if ($this->args->isDefined('n')) { $this->options['recurse_dir'] = false; } // dir if ($this->args->isDefined('d')) { $d = $this->args->getValue('d'); if (file_exists($d)) { if ($d[strlen($d) - 1] == '/' || $d[strlen($d) - 1] == '\\') { $d = substr($d, 0, -1); } $this->dir = str_replace('\\', '/', realpath($d)); } else { $this->error = 'Failed opening directory "' . $d . '". Please check your spelling and try again.'; return; } } // file if ($this->args->isDefined('f')) { $f = $this->args->getValue('f'); if (file_exists($f)) { $this->file = $f; } else { $this->error = 'Failed opening file "' . $f . '". Please check your spelling and try again.'; return; } } // ignore-files $if = $this->args->getValue('if'); if (isset($if)) { if (file_exists($if)) { $options = file($if); $this->options['ignore_files'] = array_map('rtrim', $options); } else { $this->error = 'Failed opening file "' . $if . '" (ignore-files option). ' . 'Please check your spelling and try again.'; return; } } // ignore-dirs $id = $this->args->getValue('id'); if (isset($id)) { if (file_exists($id)) { $options = file($id); $this->options['ignore_dirs'] = array_map('rtrim', $options); } else { $this->error = 'Failed opening file "' . $id . '" (ignore-dirs option). ' . 'Please check your spelling and try again.'; return; } } // ignore-functions $in = $this->args->getValue('in'); if (isset($in)) { if (file_exists($in)) { $options = file($in); $this->options['ignore_functions'] = array_map('rtrim', $options); } else { $this->error = 'Failed opening file "' . $in . '" (ignore-functions option). ' . 'Please check your spelling and try again.'; return; } } // ignore-constants $ic = $this->args->getValue('ic'); if (isset($ic)) { if (file_exists($ic)) { $options = file($ic); $this->options['ignore_constants'] = array_map('rtrim', $options); } else { $this->error = 'Failed opening file "' . $ic . '" (ignore-constants option). ' . 'Please check your spelling and try again.'; return; } } // ignore-extensions $ie = $this->args->getValue('ie'); if (isset($ie)) { if (file_exists($ie)) { $options = file($ie); $this->options['ignore_extensions'] = array_map('rtrim', $options); } else { $this->error = 'Failed opening file "' . $ie . '" (ignore-extensions option). ' . 'Please check your spelling and try again.'; return; } } // ignore-versions $iv = $this->args->getValue('iv'); if (isset($iv)) { if (!is_array($iv)) { $iv = array($iv); } $this->options['ignore_versions'] = $iv; } // file or directory options are minimum required to work if (!$this->args->isDefined('f') && !$this->args->isDefined('d')) { $this->error = 'ERROR: You must supply at least one file or directory to process'; } }
/** * the framework can be run without a database even if it's configured. * to support this, we need to handle things like * --pman-nodatabase=1 on the command line. * * * @returns array() - args, false - nothing matched / invalid, true = help! * */ function parseDefaultOpts() { require_once 'Console/Getargs.php'; $ar = $_SERVER['argv']; $call = array(array_shift($ar)); // remove index.php $call[] = array_shift($ar); //var_dump($ar); $val = self::$cli_opts; $newargs = Console_Getargs::factory($val, $ar); if (is_a($newargs, 'PEAR_Error')) { if ($newargs->getCode() === CONSOLE_GETARGS_ERROR_USER) { // since we do not handle all the arguemnts here... // skip errors if we find unknown arguments. if (preg_match('/^Unknown argument/', $newargs->getMessage())) { return false; } // User put illegal values on the command line. echo Console_Getargs::getHelp($val, $helpHeader, "\n\n" . $newargs->getMessage(), 78, 4) . "\n\n"; exit; } if ($newargs->getCode() === CONSOLE_GETARGS_HELP) { return true; // hel } return false; } // now handle real arguments.. $ret = $newargs->getValues(); foreach ($ret as $k => $v) { switch ($k) { case 'pman-nodatabase': //echo "Turning off database"; $this->ff->nodatabase = true; break; default: die("need to fix option {$k}"); } } return false; }
/** * Constructor. * * This will create an instance of the example object. If * you pass an array of arguments on construction, that * array will be used instead of the default agument list. * * @access public * @param array $argArray The optional argument list. * @return void */ function Example($argArray = NULL) { // Get the config array require_once 'Getargs.php'; $config = $this->getConfigArray(); // Get the arguments. if (is_array($argArray)) { // Use given arg list not $_SERVER['argv']. $args =& Console_Getargs::factory($config, $argArray); } else { // Use $_SERVER['argv']. $args =& Console_Getargs::factory($config); } // Check for errors. if (PEAR::isError($args)) { if ($args->getCode() === CONSOLE_GETARGS_ERROR_USER) { // User put illegal values on the command line. echo Console_Getargs::getHelp($config, NULL, $args->getMessage()) . "\n"; } else { if ($args->getCode() === CONSOLE_GETARGS_HELP) { // User needs help. echo Console_Getargs::getHelp($config) . "\n"; } } exit; } else { // Assign the member vars. $this->debug = $args->getValue('debug'); $this->file = $args->getValue(CONSOLE_GETARGS_PARAMS); $this->showLines = $args->getValue('showlines'); $this->verbose = $args->getValue('verbose'); $this->findWords = $args->getValue('find'); // Make sure the file is readable. if (!@is_readable($this->file)) { $msg = $this->file . ' is not readable.'; Console_Getargs::getHelp($config, NULL, $msg); } } }
/** * Constructor for the benchmark class. Uses the PEAR package * Console_getargs for command line handling. * * @return void */ function Benchmark() { include_once 'misc/getargs.php'; include_once 'misc/timer.php'; include_once 'misc/smapsparser.php'; include_once 'misc/cachegrindparser.php'; $this->setConfig(); $args =& Console_Getargs::factory($this->config); $this->smapsparser = new Smapsparser(); if (PEAR::isError($args) || $args->getValue('help')) { $this->printHelp($args); exit; } $this->debug = $args->getValue('debug'); $this->memory_limit = $args->getValue('memory-limit'); if ($this->memory_limit == "") { $this->memory_limit = 128; } $this->include = $args->getValue('include'); if (is_array($this->include)) { $this->include[] = "tests"; // Append default directory } else { //user has one directory as input, therefore //$this->include is recognized as a string $tmpdir = $this->include; $this->include = array(); $this->include[] = $tmpdir; $this->include[] = "tests"; } $this->php = $args->getValue('php'); if ($this->php == "") { $this->php = "php"; } $this->log_file = $args->getValue('log'); if ($this->log_file == "") { $this->log_file = false; } $this->quite = $args->getValue('quite'); $this->mem_usage = $args->getValue('memory-usage'); $this->cachegrind = $args->getValue('cachegrind'); $this->setTestFiles(); }
/** * Test getValues('long') and getValues('short') with two arguments * * @access public * @return void */ function testMultiple() { $config = array('name' => array('short' => 'n', 'min' => 1, 'max' => 1, 'desc' => 'One argument.'), 'email' => array('short' => 'e', 'min' => 2, 'max' => 2, 'desc' => 'Two arguments.')); $args = array('-n', 'arg1', '-e', '*****@*****.**', '*****@*****.**'); $message = implode(' ', $args); $obj =& Console_Getargs::factory($config, $args); if (PEAR::isError($obj)) { $this->fail("'{$message}' " . $obj->getMessage()); } else { $this->assertEquals(array('name' => $args[1], 'email' => array($args[3], $args[4])), $obj->getValues('long'), "'{$message}' Incorrect value returned"); $this->assertEquals(array('n' => $args[1], 'e' => array($args[3], $args[4])), $obj->getValues('short'), "'{$message}' Incorrect value returned"); } $args = array('--name', 'arg1', '--email', '*****@*****.**', '*****@*****.**'); $message = implode(' ', $args); $obj =& Console_Getargs::factory($config, $args); if (PEAR::isError($obj)) { $this->fail("'{$message}' " . $obj->getMessage()); } else { $this->assertEquals(array('name' => $args[1], 'email' => array($args[3], $args[4])), $obj->getValues('long'), "'{$message}' Incorrect value returned"); $this->assertEquals(array('n' => $args[1], 'e' => array($args[3], $args[4])), $obj->getValues('short'), "'{$message}' Incorrect value returned"); } }
function testAlias() { $config = array('name|alias' => array('short' => 'n|a', 'min' => 0, 'max' => 0, 'desc' => 'Unlimited number of values with alias.')); $args = array('-n', '-a', '--name', '--alias'); foreach ($args as $arg) { $message = $arg; $obj =& Console_Getargs::factory($config, array($arg)); if (PEAR::isError($obj)) { $this->fail("'{$message}' " . $obj->getMessage()); } else { $this->assertTrue($obj->isDefined('name'), "Value 'name' is not defined"); $this->assertTrue($obj->isDefined('alias'), "Value 'alias' is not defined"); $this->assertTrue($obj->isDefined('n'), "Value 'n' is not defined"); $this->assertTrue($obj->isDefined('a'), "Value 'a' is not defined"); } } }