本文整理汇总了PHP中Console_CommandLine::addArgument方法的典型用法代码示例。如果您正苦于以下问题:PHP Console_CommandLine::addArgument方法的具体用法?PHP Console_CommandLine::addArgument怎么用?PHP Console_CommandLine::addArgument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Console_CommandLine
的用法示例。
在下文中一共展示了Console_CommandLine::addArgument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadParams
/**
* Loads and parses command line parameters.
* Also takes care of the --help switch.
*
* @return void
*
* @throws Exception When the rST file does not exist
*/
protected function loadParams()
{
$parser = new \Console_CommandLine();
$parser->description = 'Deploy reStructuredText documents into a wiki';
$parser->version = '@version@';
$parser->addArgument('file', array('description' => 'rST file path'));
$parser->addOption('driver', array('long_name' => '--driver', 'optional' => true, 'action' => 'StoreString', 'description' => 'Wiki driver to use'));
//No -D options: https://pear.php.net/bugs/bug.php?id=19163
//yep, that does not automatically work with new drivers
Driver_Confluence::loadHelp($parser);
try {
$result = $parser->parse();
foreach (array_keys($result->options) as $key) {
if ($result->options[$key] === null) {
unset($result->options[$key]);
}
}
$this->options = array_merge($this->options, $result->options);
} catch (\Console_CommandLine_Exception $e) {
$parser->displayError($e->getMessage());
}
$this->file = $result->args['file'];
if (!file_exists($this->file)) {
throw new Exception('File does not exist', 2);
}
}
示例2: buildParser1
/**
* Build a parser instance and return it.
*
* @return object Console_CommandLine instance
*/
function buildParser1()
{
$parser = new Console_CommandLine();
$parser->name = 'some_program';
$parser->version = '0.1.0';
$parser->description = 'Description of our parser goes here...';
// add options
$parser->addOption('true', array('short_name' => '-t', 'long_name' => '--true', 'action' => 'StoreTrue', 'description' => 'test the StoreTrue action'));
$parser->addOption('false', array('short_name' => '-f', 'long_name' => '--false', 'action' => 'StoreFalse', 'description' => 'test the StoreFalse action'));
$parser->addOption('int', array('long_name' => '--int', 'action' => 'StoreInt', 'description' => 'test the StoreInt action', 'help_name' => 'INT', 'default' => 1));
$parser->addOption('float', array('long_name' => '--float', 'action' => 'StoreFloat', 'description' => 'test the StoreFloat action', 'help_name' => 'FLOAT', 'default' => 1.0));
$parser->addOption('string', array('short_name' => '-s', 'long_name' => '--string', 'action' => 'StoreString', 'description' => 'test the StoreString action', 'help_name' => 'STRING', 'choices' => array('foo', 'bar', 'baz')));
$parser->addOption('counter', array('short_name' => '-c', 'long_name' => '--counter', 'action' => 'Counter', 'description' => 'test the Counter action'));
$parser->addOption('callback', array('long_name' => '--callback', 'action' => 'Callback', 'description' => 'test the Callback action', 'callback' => 'rot13Callback', 'action_params' => array('prefix' => 'foo', 'suffix' => 'bar')));
$parser->addOption('array', array('short_name' => '-a', 'long_name' => '--array', 'default' => array('spam', 'egg'), 'action' => 'StoreArray', 'help_name' => 'ARRAY', 'description' => 'test the StoreArray action'));
$parser->addOption('password', array('short_name' => '-p', 'long_name' => '--password', 'action' => 'Password', 'description' => 'test the Password action'));
$parser->addArgument('simple', array('description' => 'test a simple argument'));
$parser->addArgument('multiple', array('description' => 'test a multiple argument', 'multiple' => true, 'optional' => true));
return $parser;
}
示例3: createParser
/**
* Creates the command line parser and populates it with all allowed
* options and parameters.
*
* @return Console_CommandLine CommandLine object
*/
protected function createParser()
{
$parser = new Console_CommandLine();
$parser->description = 'CLI interface to GeSHi, the generic syntax highlighter';
$parser->version = '0.1.0';
/*
$parser->addOption('outfile', array(
'short_name' => '-o',
'long_name' => '--outfile',
'description' => 'File to save output to',
'help_name' => 'FILE',
'action' => 'StoreString'
));
*/
$parser->addOption('format', array('short_name' => '-f', 'long_name' => '--format', 'description' => 'Format of file to highlight (e.g. php).', 'help_name' => 'FORMAT', 'action' => 'StoreString', 'default' => false));
$parser->addOption('renderer', array('short_name' => '-r', 'long_name' => '--renderer', 'description' => 'Renderer to use', 'help_name' => 'RENDERER', 'action' => 'StoreString', 'default' => 'html', 'choices' => array_keys(self::$arRenderers), 'list' => array_keys(self::$arRenderers), 'add_list_option' => true));
$parser->addArgument('infile', array('help_name' => 'source file'));
return $parser;
}
示例4: die
* Dependencies:
* pear install --alldeps Console_CommandLine
*
* Forked from Nooku Framework repositories
* Copyright 2007 - 2009 Johan Janssens and Mathias Verraes. Released under GNU/GPL2.
*/
include_once 'Console/CommandLine.php';
if (!class_exists('Console_CommandLine')) {
die(PHP_EOL . "You need PEAR Console_CommandLine to use this script. Install using the following command: " . PHP_EOL . "pear install --alldeps Console_CommandLine\n\n");
}
// General
$parser = new Console_CommandLine();
$parser->description = "Make symlinks for Joomla extensions on Windows.";
$parser->version = '1.0';
// Arguments
$parser->addArgument('source', array('description' => 'The source dir (usually from an IDE workspace)', 'help_name' => 'SOURCE'));
$parser->addArgument('target', array('description' => "the target dir (usually where a joomla installation resides", 'help_name' => 'TARGET'));
// Parse input
try {
$result = $parser->parse();
$source = realpath($result->args['source']);
$target = realpath($result->args['target']);
} catch (Exception $e) {
$parser->displayError($e->getMessage());
die;
}
// Defines
define('DS', DIRECTORY_SEPARATOR);
define('SRCDIR', $source);
$srcdirs = array(SRCDIR . '/administrator/components', SRCDIR . '/administrator/language/en-GB', SRCDIR . '/administrator/language/tr-TR', SRCDIR . '/administrator/modules', SRCDIR . '/media', SRCDIR . '/language/en-GB', SRCDIR . '/language/tr-TR', SRCDIR . '/libraries', SRCDIR . '/plugins/authentication', SRCDIR . '/plugins/content', SRCDIR . '/plugins/editors', SRCDIR . '/plugins/editors-xtd', SRCDIR . '/plugins/koowa', SRCDIR . '/plugins/search', SRCDIR . '/plugins/system', SRCDIR . '/plugins/user', SRCDIR . '/plugins/xmlrpc', SRCDIR . '/site/components', SRCDIR . '/site/modules');
// Make symlinks
示例5: array
/**
* Verify Phar archive signature using a public key file
*
* This file is part of the PharUtil library.
* @author Krzysztof Kotowicz <kkotowicz at gmail dot com>
* @package PharUtil
*/
// Include the Console_CommandLine package.
require_once 'Console/CommandLine.php';
require_once 'PharUtil/RemotePharVerifier.php';
// create the parser
$parser = new Console_CommandLine(array('description' => 'Verify Phar archive signature using a public key file', 'version' => '@package_version@', 'name' => 'phar-verify'));
$parser->addOption('public', array('short_name' => '-P', 'long_name' => '--public', 'action' => 'StoreString', 'default' => './cert/pub.pem', 'description' => "Public key file (PEM) to verify signature\n(./cert/pub.pem by default)"));
$parser->addOption('nosign', array('short_name' => '-n', 'long_name' => '--ns', 'action' => 'StoreTrue', 'description' => 'Archive is not signed, don\'t require an OpenSSL signature'));
$parser->addOption('temp', array('short_name' => '-t', 'long_name' => '--temp', 'action' => 'StoreString', 'description' => 'Temporary directory (' . sys_get_temp_dir() . ' by default)'));
$parser->addArgument('phar', array('action' => 'StoreString', 'description' => "Input Phar archive URI e.g.\n/path/to/local/phar.phar or http://path/to/remote/phar.phar"));
// run the parser
try {
$result = $parser->parse();
} catch (Exception $exc) {
$parser->displayError($exc->getMessage());
}
$options = $result->options;
$args = $result->args;
echo $parser->name . ' ' . $parser->version . PHP_EOL . PHP_EOL;
// validate parameters
if (substr($args['phar'], -5) !== '.phar') {
$parser->displayError("Input Phar must have .phar extension, {$args['phar']} given.", 2);
}
if ($options['nosign']) {
$options['public'] = null;
示例6: array
*
* @category Console
* @package Console_CommandLine
* @author David JEAN LOUIS <izimobil@gmail.com>
* @copyright 2007 David JEAN LOUIS
* @license http://opensource.org/licenses/mit-license.php MIT License
* @version CVS: $Id$
* @link http://pear.php.net/package/Console_CommandLine
* @since File available since release 0.1.0
*/
// Include the Console_CommandLine package.
require_once 'Console/CommandLine.php';
// create the parser
$parser = new Console_CommandLine(array('description' => 'zip given files using the php zip module.', 'version' => '1.0.0'));
// add an option to make the program verbose
$parser->addOption('verbose', array('short_name' => '-v', 'long_name' => '--verbose', 'action' => 'StoreTrue', 'description' => 'turn on verbose output'));
// add an option to delete original files after zipping
$parser->addOption('delete', array('short_name' => '-d', 'long_name' => '--delete', 'action' => 'StoreString', 'description' => 'delete original files after zip operation', 'choices' => array('foo', 'bar'), 'add_list_option' => true));
// add the files argument, the user can specify one or several files
$parser->addArgument('files', array('multiple' => true, 'description' => 'list of files to zip separated by spaces'));
// add the zip file name argument
$parser->addArgument('zipfile', array('description' => 'zip file name'));
// run the parser
try {
$result = $parser->parse();
// write your program here...
print_r($result->options);
print_r($result->args);
} catch (Exception $exc) {
$parser->displayError($exc->getMessage());
}
示例7: expected
- value is lower/higher than expected
- value is within % of expected (below/above ?)
- value is
- value is last value
- value is avg/min/max of last 1h
- expected is a number
- expected is value from last day/week/month (avg/min/max)
- expected is value from multiple last x
*/
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/classes/RRDValue.php';
require_once __DIR__ . '/inc/nagios.php';
require_once __DIR__ . '/inc/array_funcs.php';
// Command line parser
$parser = new Console_CommandLine(array('description' => 'Check RRD', 'version' => '0.0.1', 'force_posix' => true));
$parser->addArgument('config', array('description' => 'Config name', 'optional' => false));
try {
$result = $parser->parse();
// Getting config
$config = $result->args['config'];
if (empty($config)) {
echo 'No config specified' . "\n";
exit(NAGIOS_UNKNOWN);
}
$config_file = __DIR__ . '/configs/' . $config . '.php';
if (!file_exists($config_file)) {
echo 'Config specified doesn\'t exist' . "\n";
exit(NAGIOS_UNKNOWN);
}
require_once $config_file;
$args = $argv;
示例8: define
if (!defined('__DIR__')) {
define('__DIR__', dirname(__FILE__));
}
// Pull in the configuration file.. (Yes this actually works)
$config = (include __DIR__ . "/config.php");
// Set debugging if enabled
define('DEBUG', !empty($config->debug));
// Load up the class auto loader
require_once __DIR__ . "/../classes/Init.php";
include "common.php";
$parser = new Console_CommandLine();
$parser->description = "Convers the raw spell icons into strips for the trainer";
$parser->version = "0.0.1";
$parser->addOption('newsize', array('long_name' => '--size', 'description' => 'Size of new icons', 'default' => 64, 'help_name' => 'SIZE', 'action' => 'StoreInt'));
$parser->addOption('prefix', array('long_name' => '--prefix', 'description' => 'The output filename prefix', 'default' => 'trainer-icon-', 'help_name' => 'PREFIX'));
$parser->addArgument('mapfile', array('description' => 'The input JSON map file process', 'help_name' => 'INPUTFILE'));
$parser->addArgument('outputdir', array('description' => 'The output dir for images', 'help_name' => 'OUTPUTDIR'));
try {
$args = $parser->parse();
} catch (Exception $ex) {
$parser->displayError($ex->getMessage());
}
$map = json_decode(file_get_contents($args->args['mapfile']));
$size = $args->options['newsize'];
$imagedir = dirname($args->args['mapfile']);
$imageunused = $imagedir . DIRECTORY_SEPARATOR . 'unused';
if (!is_dir($imageunused)) {
mkdir($imageunused);
}
$d = dir($imageunused);
while (false !== ($entry = $d->read())) {
示例9: print_log
require_once 'Console/CommandLine.php';
require_once 'Log.php';
require_once 'Net/URL2.php';
$blacklist = get_domain_blacklist();
global $logger;
$logger = Log::singleton('console', '', 'ident', NULL, PEAR_LOG_INFO);
function print_log($message, $priority = PEAR_LOG_INFO)
{
global $logger;
$logger->log($message, $priority);
}
// Start parsing options
$parser = new Console_CommandLine();
$parser->description = 'Lists files in the current directory and creates a full size PDF or HTML page listing them with any available metadata.';
$parser->version = '1.1';
$parser->addArgument('url', array('multiple' => true, 'required' => TRUE));
$parser->addOption('quiet', array('short_name' => '-q', 'long_name' => '--quiet', 'description' => "Don't print status messages to stdout", 'action' => 'StoreTrue'));
$parser->addOption('verbose', array('short_name' => '-v', 'long_name' => '--verbose', 'description' => "Display extra log messages", 'action' => 'StoreTrue'));
$parser->addOption('rename', array('short_name' => '-r', 'long_name' => '--rename', 'description' => "Rename downloaded files to an autogenerated style.", 'action' => 'StoreTrue'));
global $commandline_input;
try {
$commandline_input = $parser->parse();
} catch (Exception $exc) {
$parser->displayError($exc->getMessage());
}
$options = $commandline_input->options;
if ($options['verbose']) {
$logger->setMask(PEAR_LOG_ALL);
}
if ($options['quiet']) {
$logger->setMask(PEAR_LOG_NONE);
示例10: parseOptions
protected function parseOptions()
{
$argf = new ARGF();
$argc =& $argf->argc();
$argv =& $argf->argv();
$optparser = new Console_CommandLine(array('name' => basename($argv[0]), 'description' => 'A php migratory tool from 4 to 5 written in pure php', 'version' => '0.0.1'));
$optparser->addOption('format', array('choices' => array('nodes', 'string', 'terminals', 'tokens', 'tree'), 'default' => 'string', 'description' => 'format of output (default: string)', 'long_name' => '--format', 'short_name' => '-f'));
$optparser->addOption('in_place', array('action' => 'StoreTrue', 'description' => 'edit files in place', 'long_name' => '--in-place', 'short_name' => '-i'));
$optparser->addOption('recursive', array('action' => 'StoreTrue', 'description' => 'migrate recursively', 'long_name' => '--recursive', 'short_name' => '-r'));
$optparser->addOption('suffixes', array('default' => 'php,php4,php5,inc', 'description' => 'suffixes of files to be migrated (default: php,php4,php5,inc)', 'long_name' => '--suffixes', 'short_name' => '-s'));
$optparser->addArgument('files', array('multiple' => true));
try {
$result = $optparser->parse();
} catch (Exception $e) {
$optparser->displayError($e->getMessage());
}
$options =& $result->options;
$args =& $result->args['files'];
if ($options['recursive']) {
if (count($args) < 2) {
$optparser->displayError('target directory must be specified with -r');
}
$target = $args[count($args) - 1];
if (!is_dir($target) && file_exists($target)) {
$optparser->displayError('target directory cannot be a regular file');
}
}
$options['suffixes'] = split(',', $options['suffixes']);
return array('options' => $options, 'args' => $args);
}
示例11: array
<?php
// Load vendor lib paths from Composer
require_once 'vendor/autoload.php';
// Actual required libs
require_once 'Console/CommandLine.php';
$cmdline_parser = new Console_CommandLine();
$cmdline_parser->addArgument('inputFile', array('description' => 'Clover XML file'));
$cmdline_parser->addArgument('minPercentage', array('description' => 'Minimum percentage required to pass'));
$cmdline_parser->addOption('print_uncovered', array('short_name' => '-u', 'long_name' => '--uncovered', 'description' => 'Output uncovered lines', 'action' => 'StoreTrue'));
$cmdline_parser->addOption('print_uncovered_verbose', array('short_name' => '-v', 'long_name' => '--uncovered-verbose', 'description' => 'Output uncovered lines - more verbosely', 'action' => 'StoreTrue'));
$cmdline_parser->addOption('print_uncovered_verbose_whitespace', array('short_name' => '-w', 'long_name' => '--uncovered-verbose-whitespace', 'description' => 'Output uncovered lines - even if they contain only whitespace', 'action' => 'StoreTrue'));
$cmdline_result = $cmdline_parser->parse();
$inputFile = $cmdline_result->args['inputFile'];
$percentage = min(100, max(0, (int) $cmdline_result->args['minPercentage']));
if (!file_exists($inputFile)) {
throw new InvalidArgumentException('Invalid input file provided');
}
if (!$percentage) {
throw new InvalidArgumentException('An integer checked percentage must be given as second parameter');
}
$xml = new SimpleXMLElement(file_get_contents($inputFile));
$metrics = $xml->xpath('//metrics');
$totalElements = 0;
$checkedElements = 0;
foreach ($metrics as $metric) {
$totalElements += (int) $metric['elements'];
$checkedElements += (int) $metric['coveredelements'];
}
$coverage = $checkedElements / $totalElements * 100;
$exit_code = 0;
示例12: parseOptions
protected function parseOptions()
{
$argf = new ARGF();
$argc =& $argf->argc();
$argv =& $argf->argv();
$optparser = new Console_CommandLine(array('name' => basename($argv[0]), 'description' => 'Find bugs in PHP5 Programs', 'version' => '0.0.1'));
$optparser->addOption('format', array('long_name' => '--format', 'help_name' => 'FORMAT', 'choices' => array('nodes', 'string', 'terminals', 'tokens', 'tree'), 'default' => 'string', 'description' => 'format of output (default: string)'));
$optparser->addOption('suffixes', array('long_name' => '--suffixes', 'help_name' => 'PATTERNS', 'default' => 'php,yml', 'description' => 'suffixes of files to be checked (default: php,yml)'));
$optparser->addOption('priority', array('long_name' => '--priority', 'help_name' => 'LEVEL', 'choices' => array('low', 'middle', 'high'), 'default' => 'middle', 'description' => 'specify priority for bug reporting (default: middle)'));
$optparser->addOption('recursive', array('action' => 'StoreTrue', 'description' => 'check recursively', 'long_name' => '--recursive', 'short_name' => '-r'));
$optparser->addOption('debug', array('action' => 'StoreTrue', 'description' => 'turn on debug mode', 'long_name' => '--debug'));
$optparser->addArgument('files', array('multiple' => true));
try {
$result = $optparser->parse();
} catch (Exception $e) {
$optparser->displayError($e->getMessage());
}
$options =& $result->options;
$args =& $result->args['files'];
if ($options['recursive']) {
if (count($args) < 2) {
$optparser->displayError('target directory must be specified with -r');
}
$target = $args[count($args) - 1];
if (!is_dir($target) && file_exists($target)) {
$optparser->displayError('target directory cannot be a regular file');
}
}
$options['suffixes'] = split(',', $options['suffixes']);
return array('options' => $options, 'args' => $args);
}
示例13: __construct
define('__DIR__', dirname(__FILE__));
}
// Pull in the configuration file.. (Yes this actually works)
$config = (include __DIR__ . "/config.php");
// Set debugging if enabled
define('DEBUG', !empty($config->debug));
// Load up the class auto loader
require_once __DIR__ . "/../classes/Init.php";
include "common.php";
$parser = new Console_CommandLine();
$parser->description = "Converts the raw map tiles into smaller slices with different scales";
$parser->version = "0.0.1";
$parser->addOption('scale', array('long_name' => '--scale', 'description' => 'Scale Factor for the image (numerator:denominator)', 'default' => new Scale(1, 1), 'help_name' => 'SCALE', 'action' => 'Scale'));
$parser->addOption('tilesize', array('long_name' => '--tilesize', 'description' => 'Tile Size', 'action' => 'StoreInt', 'default' => 256, 'help_name' => 'SIZE'));
$parser->addOption('append', array('long_name' => '--append', 'short_name' => '-a', 'description' => 'Append a new layer to,instead of overwriting the map in OUTPUTDIR', 'action' => 'StoreTrue'));
$parser->addArgument('inputmap', array('description' => 'The input map file to scale/split', 'help_name' => 'INPUTFILE'));
$parser->addArgument('outputdir', array('description' => 'The output directory for the generated map', 'optional' => true, 'help_name' => 'OUTPUTDIR'));
try {
$args = $parser->parse();
} catch (Exception $ex) {
$parser->displayError($ex->getMessage());
}
class Rect
{
public $left, $top, $right, $bottom;
public $width, $height;
public function __construct($point = null)
{
if (!is_null($point)) {
$p = Rect::getXY($point);
$this->left = $p->x;
示例14: array
#!/usr/bin/env php
<?php
namespace phinde;
require_once __DIR__ . '/../src/init.php';
$cc = new \Console_CommandLine();
$cc->description = 'phinde URL processor';
$cc->version = '0.0.1';
$cc->addOption('force', array('short_name' => '-f', 'long_name' => '--force', 'description' => 'Always process URL, even when it did not change', 'action' => 'StoreTrue', 'default' => false));
$cc->addOption('showLinksOnly', array('short_name' => '-s', 'long_name' => '--show-links', 'description' => 'Only show which URLs were found', 'action' => 'StoreTrue', 'default' => false));
$cc->addArgument('url', array('description' => 'URL to process', 'multiple' => false));
$cc->addArgument('actions', array('description' => 'Actions to take', 'multiple' => true, 'optional' => true, 'choices' => array('index', 'crawl'), 'default' => array('index', 'crawl')));
try {
$res = $cc->parse();
} catch (\Exception $e) {
$cc->displayError($e->getMessage());
}
$url = $res->args['url'];
$url = Helper::addSchema($url);
$urlObj = new \Net_URL2($url);
$url = $urlObj->getNormalizedURL();
if (!Helper::isUrlAllowed($url)) {
Log::error("Domain is not allowed; not crawling");
exit(2);
}
try {
$actions = array();
foreach ($res->args['actions'] as $action) {
if ($action == 'crawl') {
$crawler = new Crawler();
$crawler->setShowLinksOnly($res->options['showLinksOnly']);
示例15: array
#!/usr/bin/env php
<?php
/**
* Extract contents of a phar archive to a given directory
*
* This file is part of the PharUtil library.
* @author Krzysztof Kotowicz <kkotowicz at gmail dot com>
* @package PharUtil
*/
// Include the Console_CommandLine package.
require_once 'Console/CommandLine.php';
// create the parser
$parser = new Console_CommandLine(array('description' => 'Extract contents of a phar archive to a given directory', 'version' => '@package_version@', 'name' => 'phar-extract'));
$parser->addOption('public', array('short_name' => '-P', 'long_name' => '--public', 'action' => 'StoreString', 'description' => "Public key file (PEM) to verify signature.\nIf not given, <pharfilename.phar>.pubkey will be used."));
$parser->addOption('list', array('short_name' => '-l', 'long_name' => '--list', 'action' => 'StoreTrue', 'description' => "Only list the files, don't extract them."));
$parser->addArgument('phar', array('action' => 'StoreString', 'description' => "Input Phar archive filename e.g. phar.phar"));
$parser->addArgument('destination', array('action' => 'StoreString', 'description' => "Destination directory", 'optional' => true));
// run the parser
try {
$result = $parser->parse();
$options = $result->options;
$args = $result->args;
if ($options['list'] !== true && !isset($args['destination'])) {
throw Console_CommandLine_Exception::factory('ARGUMENT_REQUIRED', array('argnum' => 2, 'plural' => 's'), $parser, $parser->messages);
}
} catch (Exception $exc) {
$parser->displayError($exc->getMessage());
}
echo $parser->name . ' ' . $parser->version . PHP_EOL . PHP_EOL;
// validate parameters
if (substr($args['phar'], -5) !== '.phar') {