/** * 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); } }
/** * 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; }
/** * 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; }
* 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
/** * 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;
* * @category Console * @package Console_CommandLine * @author David JEAN LOUIS <*****@*****.**> * @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()); }
- 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;
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())) {
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);
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); }
<?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;
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); }
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;
#!/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']);
#!/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') {
/** * Load parameters for the CLI option parser. * * @return \Console_CommandLine CLI option parser */ protected function loadOptionParser() { $parser = new \Console_CommandLine(); $parser->description = 'php-sqllint'; $parser->version = 'dev'; $parser->avoid_reading_stdin = true; $versionFile = __DIR__ . '/../../VERSION'; if (file_exists($versionFile)) { $parser->version = trim(file_get_contents($versionFile)); } $parser->addOption('format', array('short_name' => '-f', 'long_name' => '--format', 'description' => 'Reformat SQL instead of checking', 'action' => 'StoreTrue', 'default' => false)); $parser->addOption('highlight', array('short_name' => '-h', 'long_name' => '--highlight', 'description' => 'Highlighting mode (when using --format)', 'action' => 'StoreString', 'choices' => array('none', 'ansi', 'html', 'auto'), 'default' => 'auto', 'add_list_option' => true)); $parser->addOption('renderer', array('short_name' => '-r', 'long_name' => '--renderer', 'description' => 'Output mode', 'action' => 'StoreString', 'choices' => array('emacs', 'text'), 'default' => 'text', 'add_list_option' => true)); $parser->addArgument('sql_files', array('description' => 'SQL files, "-" for stdin', 'multiple' => true)); return $parser; }
* @since 2015-10-15 * @author Alban * @license GPL v2 */ // Load bootstrap for autoload and logger set_include_path(".:" . get_include_path()); require_once "bootstrap.php"; // Instanciate export service $service = new Alternc_Tools_Mailbox_Import(array("db" => $db)); // Instanciate command line parser $consoleParser = new Console_CommandLine(array("description" => "Synchronizes mailboxes using an old => new mapper.")); // Configure command line parser $consoleParser->add_version_option = false; $consoleParser->addOption("input_file", array("help_name" => "/tmp/rsyncData.json", "short_name" => "-i", "long_name" => "--input-file", "description" => "Input file name and path", 'default' => $service->default_output)); $consoleParser->addOption("rsync_log", array("help_name" => "/tmp/rsyncLog.json", "short_name" => "-l", "long_name" => "--rsync-log", "description" => "Rsync log files", 'default' => $service->default_rsync_log)); $consoleParser->addArgument("source", array("help_name" => "source.server.fqdn", "description" => "Origin/Source server, IP or FQDN")); // Run the command line parser try { $commandLineResult = $consoleParser->parse(); // Run the service if (!($result = $service->rsync($commandLineResult))) { throw new \Exception("Import process failed"); } $message = $result["message"]; $logger->logMessage(Logger\AbstractLogger::INFO, $message); echo $message . "\n"; // Boom goes your request } catch (\Exception $exc) { $message = $exc->getMessage(); $logger->logMessage(Logger\AbstractLogger::CRITICAL, $message); $consoleParser->displayError($message);
public static function parseArguments() { $main = new \Console_CommandLine(); $main->addOption('out', array('short_name' => '-o', 'long_name' => '--out', 'action' => 'StoreString', 'description' => 'destination directory for generated files', 'default' => './')); $main->addOption('include', array('short_name' => '-i', 'long_name' => '--include', 'action' => 'StoreArray', 'description' => 'define an include path (can be repeated)', 'multiple' => true)); $main->addOption('json', array('short_name' => '-j', 'long_name' => '--json', 'action' => 'StoreTrue', 'description' => 'turn on ProtoJson Javascript file generation')); $main->addOption('protoc', array('long_name' => '--protoc', 'action' => 'StoreString', 'default' => 'protoc', 'description' => 'protoc compiler executable path')); $main->addOption('skipImported', array('long_name' => '--skip-imported', 'action' => 'StoreTrue', 'default' => false, 'description' => 'do not generate imported proto files')); $main->addOption('comments', array('long_name' => '--comments', 'action' => 'StoreTrue', 'description' => 'port .proto comments to generated code')); $main->addOption('insertions', array('long_name' => '--insertions', 'action' => 'StoreTrue', 'description' => 'generate @@protoc insertion points')); $main->addOption('define', array('short_name' => '-D', 'long_name' => '--define', 'action' => 'StoreArray', 'multiple' => true, 'description' => 'define a generator option (ie: -Dmultifile -Dsuffix=pb.php)')); $main->addOption('verbose', array('short_name' => '-v', 'long_name' => '--verbose', 'action' => 'StoreTrue', 'description' => 'turn on verbose output')); $main->addArgument('protos', array('multiple' => true, 'description' => 'proto files')); try { echo 'Protobuf-PHP ' . Protobuf::VERSION . ' by Ivan -StudyDrSlump- Montes' . PHP_EOL . PHP_EOL; $result = $main->parse(); return $result; } catch (\Exception $e) { $main->displayError($e->getMessage()); exit(1); } }
* * * See the "license.txt" file for details of the Plancake license. * **********************************************************************************/ include_once dirname(__FILE__) . '/lib/Nextgen/Core/Engine.php'; $nextGen = new Nextgen_Core_Engine(); // create the parser $parser = new Console_CommandLine(array('description' => 'NextGen is an advanced MySQL diff tool.', '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')); $parser->addOption('ignore_tables_regexp', array('short_name' => '-i', 'long_name' => '--ignore-tables-regexp', 'description' => 'specify a regular expression for tables you want to ignore', 'action' => 'StoreString', 'default' => '')); $parser->addOption('disable_user_interaction', array('short_name' => '-u', 'long_name' => '--disable-user-interaction', 'description' => 'disable the user interaction', 'action' => 'StoreTrue', 'default' => '')); $parser->addOption('answers', array('short_name' => '-a', 'long_name' => '--answers', 'description' => 'the list of answers for the user interaction - they must be comma-separated, ie: 2,0,3', 'action' => 'StoreString', 'default' => '')); $parser->addOption('enable_log', array('short_name' => '-e', 'long_name' => '--enable-log', 'description' => 'whether to enable log (if you enable it, you need to pass the parser as well)', 'action' => 'StoreTrue', 'default' => '')); $parser->addOption('logger', array('short_name' => '-l', 'long_name' => '--logger', 'description' => 'the logger to use', 'action' => 'StoreString', 'default' => '')); // add the files argument, the user can specify one or several files $parser->addArgument('input_handler_1', array('description' => 'The handler to use for the first input')); $parser->addArgument('input_resource_1', array('description' => 'The string to identify the first input (the format depends on the handler)')); $parser->addArgument('input_handler_2', array('description' => 'The handler to use for the second input')); $parser->addArgument('input_resource_2', array('description' => 'The string to identify the second input (the format depends on the handler)')); $parser->addArgument('output_generator', array('description' => 'The generator for the output the output')); $parser->addArgument('output_resource', array('description' => 'The string to identify where to place the output, usually a file name (depends on the handler)')); // run the parser try { $result = $parser->parse(); $options = $result->options; $args = $result->args; $config = array('input_handler_1' => $args['input_handler_1'], 'input_resource_1' => $args['input_resource_1'], 'input_handler_2' => $args['input_handler_2'], 'input_resource_2' => $args['input_resource_2'], 'output_generator' => $args['output_generator'], 'output_resource' => $args['output_resource'], 'ignore_tables_regexp' => $options['ignore_tables_regexp'], 'disable_user_interaction' => $options['disable_user_interaction'], 'answers' => $options['answers'], 'enable_log' => $options['enable_log'], 'logger' => $options['logger']); $nextGenConfig = new Nextgen_Core_Configuration($config); $nextGen->setConfiguration($nextGenConfig); $nextGen->doDiff(); } catch (Exception $exc) {