/** * 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); } }
/** * Show full help information * * @param string $footer (optional) page footer content * * @return void * @access private */ function _printUsage($footer = '') { $header = 'Usage: ' . basename($_SERVER['SCRIPT_NAME']) . " [options]\n\n"; echo Console_Getargs::getHelp($this->opts, $header, "\n{$footer}\n", 78, 2) . "\n"; }
* $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')) { echo 'Filters: ' . (is_array($args->getValue('fi')) ? implode(', ', $args->getValue('fi')) . "\n" : $args->getValue('fi') . "\n"); } else { echo "Filters: undefined\n"; } echo 'Width: ' . $args->getValue('w') . "\n";
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"; }
/** * 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; }
$db_type = prompt_var('Database type', 'mysql', $defaults ? @$options['database'] : null); $db_user = prompt_var('Database user', $FrameworkSetup->suggestUserName(), $defaults ? @$options['user'] : null); $db_pass = prompt_var('Database password', '', $defaults ? @$options['password'] : null); if (!@NewADOConnection("{$db_type}://{$db_user}:{$db_pass}@localhost")) { echo Ak::t('Could not connect to the database' . "\n"); set_db_user_and_pass($FrameworkSetup, $db_user, $db_pass, $db_type, false); } } $config = array('user' => array('short' => 'u', 'max' => 1, 'min' => 1, 'default' => 'root', 'desc' => 'Database user'), 'password' => array('short' => 'p', 'max' => 1, 'min' => 1, 'default' => '', 'desc' => 'Database password'), 'database' => array('short' => 'd', 'max' => 1, 'min' => 1, 'default' => 'mysql', 'desc' => 'Database type'), 'name' => array('short' => 'n', 'max' => 1, 'min' => 1, 'default' => AkInflector::underscore(basename(AK_BASE_DIR)), 'desc' => 'Database name. This is the name of your database. It will be prefixed with _dev and _tests for non production environments.'), 'languages' => array('short' => 'l', 'max' => 1, 'min' => 1, 'default' => 'en', 'desc' => 'Language codes for this application.'), 'interactive' => array('short' => 'i', 'max' => 0, 'min' => 0, 'default' => false, 'desc' => 'Interactive mode.')); $args =& Console_Getargs::factory($config); if (PEAR::isError($args)) { if ($args->getCode() === CONSOLE_GETARGS_ERROR_USER) { echo Console_Getargs::getHelp($config, null, $args->getMessage()) . "\n"; } else { if ($args->getCode() === CONSOLE_GETARGS_HELP) { echo @Console_Getargs::getHelp($config) . "\n"; } } exit; } $options = $args->getValues(); $FrameworkSetup = new FrameworkSetup(); $FrameworkSetup->setDefaultOptions(); $FrameworkSetup->getAvailableDatabases(); $app_name = empty($options['interactive']) ? $options['name'] : prompt_var('Database name. This is the name of your database. It will be prefixed with _dev and _tests for non production environments.', $options['name']); $db_user = $db_pass = $db_type = ''; set_db_user_and_pass($FrameworkSetup, $db_user, $db_pass, $db_type); $FrameworkSetup->setDatabaseUser($db_user, 'admin'); $FrameworkSetup->setDatabasePassword($db_pass, 'admin'); $FrameworkSetup->setDatabaseType($db_type); foreach (array('development', 'production', 'testing') as $mode) {
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(); }
* Fetch the statistics for a torrent * * Usage: * # php scrape.php -t file * * @author Markus Tacker <*****@*****.**> * @version $Id$ */ // Includes require_once 'File/Bittorrent2/Decode.php'; require_once 'Console/Getargs.php'; // Get filename from command line $args_config = array('torrent' => array('short' => 't', 'min' => 1, 'max' => 1, 'desc' => 'Filename of the torrent')); $args =& Console_Getargs::factory($args_config); if (PEAR::isError($args) or !($torrent = $args->getValue('torrent'))) { echo Console_Getargs::getHelp($args_config) . "\n"; exit; } if (!is_readable($torrent)) { echo 'ERROR: "' . $torrent . "\" is not readable.\n"; exit; } // Decode the torrent $File_Bittorrent2_Decode = new File_Bittorrent2_Decode(); $File_Bittorrent2_Decode->decodeFile($torrent); echo "\nStatistics\n"; echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"; echo 'Tracker: ' . $File_Bittorrent2_Decode->getAnnounce() . "\n"; echo 'info hash: ' . $File_Bittorrent2_Decode->getInfoHash() . "\n"; foreach ($File_Bittorrent2_Decode->getStats() as $key => $val) { echo str_pad($key . ':', 20) . $val . "\n";
/** * 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); } } }
/** * Prints the help message for the benchmark * * @param array $args The arguments to be listed * * @return void */ function printHelp($args) { $header = "Php Benchmark Example\n" . 'Usage: ' . basename($_SERVER['SCRIPT_NAME']) . " [options]\n\n"; if ($args->getCode() === CONSOLE_GETARGS_ERROR_USER) { echo Console_Getargs::getHelp($this->config, $header, $args->getMessage()) . "\n"; } else { if ($args->getCode() === CONSOLE_GETARGS_HELP) { echo Console_Getargs::getHelp($this->config, $header) . "\n"; } } }
/** * @file * This file is a simple, commandline front end for the included * PES_File_PDF_Splitter class. It allows for splitting a multi-page PDF file * into several PNG files, with each page being a single image ones. * Configuration options are described below, or can be read by running * "php pdf_splitter.php --help" on the command line. */ // The used PEAR Console_Getargs class isn't PHP5 compliant, so hide // hide the depreciated error messages. error_reporting(E_ALL ^ E_DEPRECATED); include 'Console/Getargs.php'; include 'PES/File/PDF/Splitter.php'; $config = array('x_res' => array('desc' => 'The x resolution used to read in the PDF', 'min' => 0, 'max' => 1, 'default' => 100), 'y_res' => array('desc' => 'The y resolution used to read in the PDF', 'min' => 0, 'max' => 1, 'default' => 100), 'dest' => array('desc' => 'The path to write the created, child PNG pages to', 'min' => 0, 'max' => 1, 'default' => __DIR__), 'source' => array('desc' => 'The PDF file to split into PNG page files.', 'min' => 1, 'max' => 1)); $args = Console_Getargs::factory($config); if (PEAR::isError($args)) { if ($args->getCode() === CONSOLE_GETARGS_ERROR_USER) { echo Console_Getargs::getHelp($config, NULL, $args->getMessage()); } else { if ($args->getCode() === CONSOLE_GETARGS_HELP) { echo Console_Getargs::getHelp($config); } } } else { $splitter = new PES_File_PDF_Splitter(); $created_files = $splitter->setPDFPath($args->getValue('source'))->setXResolution($args->getValue('x_res') ?: 100)->setYResolution($args->getValue('y_res') ?: 100)->convertToPNG($args->getValue('dest') ?: __DIR__); echo 'Wrote ' . count($created_files) . ' PNG files:' . PHP_EOL; foreach ($created_files as $a_file) { echo ' - ' . $a_file . PHP_EOL; } }