Example #1
0
/**
 * Print the usage message
 *
 * @param \Zend\Console\Getopt $options options to get the usage message from
 */
function printUsageMessage(\Zend\Console\Getopt $options)
{
    $usage = $options->getUsageMessage();
    list($firstLine, $usage) = explode(PHP_EOL, $usage, 2);
    echo $firstLine . ' -o outputfile.pdf character-images [..]' . PHP_EOL;
    echo $usage;
}
Example #2
0
 /**
  * Calls all init functions of the WCF class.
  */
 public function __construct()
 {
     // add autoload directory
     self::$autoloadDirectories['wcf'] = WCF_DIR . 'lib/';
     // define tmp directory
     if (!defined('TMP_DIR')) {
         define('TMP_DIR', FileUtil::getTempFolder());
     }
     // register additional autoloaders
     require_once WCF_DIR . 'lib/system/api/phpline/phpline.phar';
     require_once WCF_DIR . 'lib/system/api/zend/Loader/StandardAutoloader.php';
     $zendLoader = new ZendLoader(array(ZendLoader::AUTOREGISTER_ZF => true));
     $zendLoader->register();
     $argv = new ArgvParser(array('packageID=i' => ''));
     $argv->setOption(ArgvParser::CONFIG_FREEFORM_FLAGS, true);
     $argv->parse();
     define('PACKAGE_ID', $argv->packageID ?: 1);
     // disable benchmark
     define('ENABLE_BENCHMARK', 0);
     // start initialization
     $this->initDB();
     $this->loadOptions();
     $this->initSession();
     $this->initLanguage();
     $this->initTPL();
     $this->initCoreObjects();
     $this->initApplications();
     // the destructor registered in core.functions.php will only call the destructor of the parent class
     register_shutdown_function(array('wcf\\system\\CLIWCF', 'destruct'));
     $this->initArgv();
     $this->initPHPLine();
     $this->initAuth();
     $this->checkForUpdates();
     $this->initCommands();
 }
 /**
  * Get argument on command line
  * @return Getopt 
  */
 public function getGetopt()
 {
     if (!$this->getopt) {
         $this->getopt = @new Getopt($this->config, null, array(Getopt::CONFIG_FREEFORM_FLAGS => true));
         // let use of more argument
         $this->getopt->parse();
     }
     return $this->getopt;
 }
 /**
  * Harvest a single repository.
  *
  * @param string $target   Name of repo (used for target directory)
  * @param array  $settings Settings for the harvester.
  *
  * @return void
  * @throws \Exception
  */
 protected function harvestSingleRepository($target, $settings)
 {
     $settings['from'] = $this->opts->getOption('from');
     $settings['until'] = $this->opts->getOption('until');
     $settings['silent'] = false;
     $harvest = $this->factory->getHarvester($target, $this->getHarvestRoot(), $this->getHttpClient(), $settings);
     $harvest->launch();
 }
Example #5
0
// Setup autoloading
$loader = new Zend\Loader\StandardAutoloader();
$loader->register();

$rules = array(
    'help|h'        => 'Get usage message',
    'class|c=s'     => 'Class for which to create a docbook skeleton',
    'output|o-s'    => 'Where to write skeleton file; if not provided, assumes documentation/manual/en/module_specs/<class id>.xml"',
);

$docbookPath = __DIR__ . '/../documentation/manual/en/module_specs';
$docbookFile = false;

// Parse options
try {
    $opts = new Zend\Console\Getopt($rules);
    $opts->parse();
} catch (Zend\Console\Getopt\Exception $e) {
    // Error creating or parsing options; show usage message
    echo $e->getUsageMessage();
    exit(2);
}

// Help requested
if ($opts->getOption('h')) {
    echo $opts->getUsageMessage();
    exit();
}

// Were we provided a class name?
if (!isset($opts->c)) {
Example #6
0
    public function testGetoptRaiseExceptionForNumericOptionsIfAneHandlerIsSpecified()
    {
        $opts = new Getopt(
            array('lines=s' => 'Lines-option'),
            array('other', 'arguments', '-5'),
            array(Getopt::CONFIG_NUMERIC_FLAGS => true)
        );

        $this->setExpectedException('\Zend\Console\Exception\RuntimeException');
        $opts->parse();
    }
Example #7
0
 /**
  * @param array $argv
  * @throws \Zend\Console\Exception\RuntimeException
  */
 public function parseGetOpt(array $argv)
 {
     $rules = array('h|help' => 'show this help', 'l|lines=i' => 'output the last N lines of a stacktrace. Default: 100', 'line-length=i' => 'maximum length of a line. Default 512', 'process-name=s' => 'name of running php processes. Default: autodetect', 'live' => 'search while running for new upcoming pid\'s', 'o|output=s' => 'output log to file');
     $opts = new Console\Getopt($rules, $argv);
     $opts->parse();
     if ($opts->help) {
         throw new Console\Exception\RuntimeException('', $opts->getUsageMessage());
     }
     if ($opts->getOption('lines')) {
         $this->getStrace()->setLines(min(1000, max(1, $opts->getOption('lines'))));
     }
     if ($opts->getOption('line-length')) {
         $this->getStrace()->setLineLength(min(1 * 1024 * 1024, max(10, $opts->getOption('line-length'))));
     }
     if ($opts->getOption('process-name')) {
         $this->getProcessStatus()->setProcessName($opts->getOption('process-name'));
     }
     if ($opts->getOption('output')) {
         $fileOutput = new FileOutput($opts->getOption('output'));
         $this->getCommandLine()->attachObserver($fileOutput, 'stdout');
         $this->getCommandLine()->attachObserver($fileOutput, 'stderr');
     }
     if ($opts->getOption('live')) {
         $this->setLive(true);
     }
 }
 /**
  * @see	\wcf\system\cli\command\ICLICommand::getUsage()
  */
 public function getUsage()
 {
     return str_replace($_SERVER['argv'][0] . ' [ options ]', 'package [ options ] <install|uninstall> <package>', $this->argv->getUsageMessage());
 }
Example #9
0
 /**
  * @expectedException \Zend\Console\Exception\RuntimeException
  * @expectedExceptionMessage The option x is invalid. See usage.
  */
 public function testOptionCallbackReturnsFallsAndThrowException()
 {
     $opts = new Getopt('x', array('-x'));
     $opts->setOptionCallback('x', function () {
         return false;
     });
     $opts->parse();
 }
Example #10
0
 * @author   Demian Katz <*****@*****.**>
 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
 * @link     http://vufind.org/wiki/vufind2:installation_notes Wiki
 */
require_once __DIR__ . '/vendor/autoload.php';
use Zend\Console\Getopt;
define('MULTISITE_NONE', 0);
define('MULTISITE_DIR_BASED', 1);
define('MULTISITE_HOST_BASED', 2);
$baseDir = str_replace('\\', '/', dirname(__FILE__));
$overrideDir = $baseDir . '/local';
$host = $module = '';
$multisiteMode = MULTISITE_NONE;
$basePath = '/vufind';
try {
    $opts = new Getopt(array('use-defaults' => 'Use VuFind Defaults to Configure (ignores any other arguments passed)', 'overridedir=s' => "Where would you like to store your local settings? [{$baseDir}/local]", 'module-name=s' => 'What module name would you like to use? Use disabled, to not use', 'basepath=s' => 'What base path should be used in VuFind\'s URL? [/vufind]', 'multisite-w' => 'Specify we are going to setup a multisite. Options: directory and host', 'hostname=s' => 'Specify the hostname for the VuFind Site, When multisite=host', 'non-interactive' => 'Use settings if provided via arguments, otherwise use defaults'));
    $opts->parse();
} catch (Exception $e) {
    echo $e->getUsageMessage();
    exit;
}
echo "VuFind has been found in {$baseDir}.\n\n";
// Are we allowing user interaction?
$interactive = !$opts->getOption('non-interactive');
$userInputNeeded = array();
// Load user settings if we are not forcing defaults:
if (!$opts->getOption('use-defaults')) {
    if ($opts->getOption('overridedir')) {
        $overrideDir = $opts->getOption('overridedir');
    } else {
        if ($interactive) {
Example #11
0
 } catch (ConsoleException $e) {
     //echo "Could not get console adapter - most likely we are not running inside a console window.";
 }
 if (version_compare(PHP_VERSION, '5.4.0', '<')) {
     $phpooleConsole->wlError('PHP 5.4+ required (your version: ' . PHP_VERSION . ')');
     exit(2);
 }
 define('DS', DIRECTORY_SEPARATOR);
 define('PHPOOLE_DIRNAME', '_phpoole');
 $websitePath = '';
 //getcwd();
 // Defines rules
 $rules = array('help|h' => 'Get PHPoole usage message', 'init|i-s' => 'Build a new PHPoole website (<force>)', 'generate|g' => 'Generate static files', 'serve|s' => 'Start built-in web server', 'deploy|d' => 'Deploy static files', 'list|l' => 'Lists content');
 // Get and parse console options
 try {
     $opts = new Getopt($rules);
     $opts->parse();
 } catch (ConsoleException $e) {
     echo $e->getUsageMessage();
     exit(2);
 }
 // help option
 if ($opts->getOption('help') || count($opts->getOptions()) == 0) {
     echo $opts->getUsageMessage();
     exit(0);
 }
 // Get provided directory if exist
 if (!isset($opts->getRemainingArgs()[0])) {
     $path = '.';
 } else {
     $path = $opts->getRemainingArgs()[0];
Example #12
0
if (!is_dir($libPath)) {
    // Try to load StandardAutoloader from include_path
    if (false === (include 'Zend/Loader/StandardAutoloader.php')) {
        echo "Unable to locate autoloader via include_path; aborting" . PHP_EOL;
        exit(2);
    }
} elseif (false === (include $libPath . '/Zend/Loader/StandardAutoloader.php')) {
    echo "Unable to locate autoloader via library; aborting" . PHP_EOL;
    exit(2);
}
// Setup autoloading
$loader = new StandardAutoloader(array('autoregister_zf' => true));
$loader->register();
$rules = array('help|h' => 'Get usage message', 'docbook|d-s' => 'Docbook file to convert', 'output|o-s' => 'Output file in reStructuredText format; By default assumes <docbook>.rst"');
try {
    $opts = new Console\Getopt($rules);
    $opts->parse();
} catch (Console\Exception\RuntimeException $e) {
    echo $e->getUsageMessage();
    exit(2);
}
if (!$opts->getOptions() || $opts->getOption('h')) {
    echo $opts->getUsageMessage();
    exit(0);
}
$docbook = $opts->getOption('d');
if (!file_exists($docbook)) {
    echo "Error: the docbook file {$docbook} doesn't exist." . PHP_EOL;
    exit(2);
}
$rstFile = $opts->getOption('o');
Example #13
0
        exit(2);
    }
} else {
    // Try to load StandardAutoloader from include_path
    if (false === (include 'Zend/Loader/StandardAutoloader.php')) {
        echo 'Unable to locate autoloader via include_path; aborting' . PHP_EOL;
        exit(2);
    }
}
$libraryPath = getcwd();
// Setup autoloading
$loader = new StandardAutoloader(array('autoregister_zf' => true));
$loader->register();
$rules = array('help|h' => 'Get usage message', 'library|l-s' => 'Library to parse; if none provided, assumes current directory', 'output|o-s' => 'Where to write autoload file; if not provided, assumes "autoload_classmap.php" in library directory', 'append|a' => 'Append to autoload file if it exists', 'overwrite|w' => 'Whether or not to overwrite existing autoload file', 'ignore|i-s' => 'Comma-separated namespaces to ignore', 'sort|s' => 'Alphabetically sort classes');
try {
    $opts = new Console\Getopt($rules);
    $opts->parse();
} catch (Console\Exception\RuntimeException $e) {
    echo $e->getUsageMessage();
    exit(2);
}
if ($opts->getOption('h')) {
    echo $opts->getUsageMessage();
    exit(0);
}
$ignoreNamespaces = array();
if (isset($opts->i)) {
    $ignoreNamespaces = explode(',', $opts->i);
}
$relativePathForClassmap = '';
if (isset($opts->l)) {
Example #14
0
 /**
  * @see	\wcf\system\cli\command\ICLICommand::getUsage()
  */
 public function getUsage()
 {
     return str_replace($_SERVER['argv'][0] . ' [ options ]', 'worker [ options ] <worker>', $this->argv->getUsageMessage());
 }
 protected function _createGetopt()
 {
     $opts = new Getopt(array('config|c=s' => 'configuration file', 'manager|m=s' => 'the remote manager to be used, such as "usersManager", "groupsManager" etc.', 'function|f=s' => 'the function of the remote manager to be called', 'args|a=s' => 'function arguments - key/value comma separated, for example: key1=value1,key2=value2, ...', 'args-file|x=s' => 'file with function arguments (key=value) each on a separate line - alternative way for setting function arguments', 'filter|F=s' => 'filter attributes', 'entity|e' => 'return result as entity'));
     $opts->setOptions(array(Getopt::CONFIG_PARAMETER_SEPARATOR => ','));
     return $opts;
 }
 /**
  * @see	\wcf\system\cli\command\ICLICommand::getUsage()
  */
 public function getUsage()
 {
     return str_replace($_SERVER['argv'][0] . ' [ options ]', 'cronjob [ options ] execute', $this->argv->getUsageMessage());
 }
Example #17
0
use Zend\Console\Console;
use Zend\Console\Getopt;
function title()
{
    echo 'Testdox html to markdown converter' . PHP_EOL;
}
function exitWithMessage($msg, $help, $code)
{
    title();
    echo $msg . PHP_EOL;
    echo $help;
    exit($code);
}
$rules = array('help|h' => 'Get usage message', 'title|t-s' => 'Document title: default = "Foo"');
try {
    $opts = new Getopt($rules);
    $opts->parse();
} catch (Console\Exception\RuntimeException $e) {
    exitWithMessage($e->getMessage(), $e->getUsageMessage(), 1);
}
if ($opts->getOption('h')) {
    exitWithMessage('tdconv <testdox.html.file.name> <output.file.name>', $opts->getUsageMessage(), 0);
}
$title = false;
$args = $opts->getArguments();
if ($opts->getOption('t')) {
    $title = $opts->getOption('t');
    unset($args['title']);
}
if (count($args) !== 2) {
    exitWithMessage('Expected exactly two arguments, got ' . count($args), $opts->getUsageMessage(), 1000);
Example #18
0
 /**
  * @group ZF-5345
  */
 public function testUsingDashWithoutOptionNotAsLastArgumentThrowsException()
 {
     $opts = new Getopt("abp:", array("-", "file1"));
     $this->setExpectedException('\\Zend\\Console\\Exception\\RuntimeException');
     $opts->parse();
 }
<?php

use Zend\Console\Getopt;
use Zend\Console\Console;
use Zend\Console\ColorInterface as Color;
use Aws\Ec2\Ec2Client;
use CbAws\Ec2\Ec2ClientHelper;
require __DIR__ . '/vendor/autoload.php';
$console = Console::getInstance();
$opt = new Getopt(array('key|O-s' => 'AWS access key', 'secret|W-s' => 'AWS secret key', 'instance|i-s' => 'Instance to backup', 'region|r-s' => 'Region of host', 'age|t-s' => 'Max age, in seconds (default = 1 week)', 'dry-run|d' => 'Dry run, do not delete anything'));
$opt->parse();
try {
    $key = empty($opt->key) ? getenv('AWS_ACCESS_KEY') : $opt->key;
    $secret = empty($opt->secret) ? getenv('AWS_SECRET_KEY') : $opt->secret;
    $region = empty($opt->region) ? getenv('AWS_REGION') : $opt->region;
    $instanceId = $opt->instance;
    $age = empty($opt->age) ? 86400 * 7 : (int) $opt->age;
    $dryRun = (bool) $opt->{'dry-run'};
    if ($age <= 0) {
        $console->writeLine('Invalid age parameter', Color::RED);
        echo $opt->getUsageMessage();
        exit(1);
    }
    $maxAge = new DateTime();
    $maxAge->sub(new DateInterval('PT' . $age . 'S'));
    $client = Ec2Client::factory(array('key' => $key, 'secret' => $secret, 'region' => $region));
    $clientHelper = new Ec2ClientHelper($client);
    if (empty($instanceId)) {
        $hostname = gethostname() . '.';
        $instance = $clientHelper->getInstanceByHostname($hostname);
        $instanceId = $instance['InstanceId'];
Example #20
0
 public function run()
 {
     switch ($this->mainArgv) {
         case 'generate':
             $gen = new Generators\Generator($this);
             $gen->parseCmd();
             break;
         case 'assets':
             $rules = ['assets' => '', 'action' => ''];
             $opts = new Zend\Console\Getopt($rules);
             $argv = $opts->getArguments();
             if (empty($argv[1])) {
                 $this->terminate("Missing argument 2");
             }
             \Rails::resetConfig('production');
             switch ($argv[1]) {
                 case 'compile:all':
                     \Rails::assets()->setConsole($this);
                     \Rails::assets()->compileAll();
                     break;
                 case strpos($argv[1], 'compile:') === 0:
                     $parts = explode(':', $argv[1]);
                     if (empty($parts[1])) {
                         $this->terminate("Missing asset name to compile");
                     }
                     \Rails::assets()->setConsole($this);
                     \Rails::assets()->compileFile($parts[1]);
                     break;
                 default:
                     $this->terminate("Unknown action for assets");
                     break;
             }
             break;
         case 'routes':
             $routes = $this->createRoutes();
             $rules = ['routes' => '', 'f-s' => ''];
             $opts = new Zend\Console\Getopt($rules);
             if ($filename = $opts->getOption('f')) {
                 if (true === $filename) {
                     $logFile = \Rails::config()->paths->log->concat('routes.log');
                 } else {
                     $logFile = \Rails::root() . '/' . $filename;
                 }
                 file_put_contents($logFile, $routes);
             }
             $this->write($routes);
             break;
             /**
              * Install database.
              */
         /**
          * Install database.
          */
         case 'db:create':
             $m = new \Rails\ActiveRecord\Migration\Migrator();
             $m->loadSchema();
             break;
             /**
              * Run all/pending migrations.
              * Creates migrations table as well.
              */
         /**
          * Run all/pending migrations.
          * Creates migrations table as well.
          */
         case 'db:migrate':
             $m = new \Rails\ActiveRecord\Migration\Migrator();
             $m->run();
             break;
             /**
              * Runs seeds.
              */
         /**
          * Runs seeds.
          */
         case 'db:seed':
             $m = new \Rails\ActiveRecord\Migration\Migrator();
             $m->runSeeds();
             break;
         case 'db:schema:dump':
             $dumper = new \Rails\ActiveRecord\Schema\Dumper(\Rails\ActiveRecord\ActiveRecord::connection());
             $dumper->export(\Rails::root() . '/db/schema.sql');
             break;
     }
 }
<?php

use Zend\Console\Getopt;
use Zend\Console\Console;
use Zend\Console\ColorInterface as Color;
use Aws\Ec2\Ec2Client;
use CbAws\Ec2\Ec2ClientHelper;
require __DIR__ . '/vendor/autoload.php';
$console = Console::getInstance();
$opt = new Getopt(array('key|O-s' => 'AWS access key', 'secret|W-s' => 'AWS secret key', 'instance|i-s' => 'Instance to backup', 'region|r-s' => 'Region of instance', 'exclude|e-s' => 'Exclude volumes/devices, comma delimited', 'dry-run|d' => 'Dry run, do not delete anything'));
$opt->parse();
try {
    $key = empty($opt->key) ? getenv('AWS_ACCESS_KEY') : $opt->key;
    $secret = empty($opt->secret) ? getenv('AWS_SECRET_KEY') : $opt->secret;
    $region = empty($opt->region) ? getenv('AWS_REGION') : $opt->region;
    $instanceId = $opt->instance;
    $exclusions = empty($opt->exclude) ? array() : array_map('trim', explode(',', $opt->exclude));
    $dryRun = (bool) $opt->{'dry-run'};
    $client = Ec2Client::factory(array('key' => $key, 'secret' => $secret, 'region' => $region));
    $clientHelper = new Ec2ClientHelper($client);
    if (empty($instanceId)) {
        $hostname = gethostname() . '.';
        $instance = $clientHelper->getInstanceByHostname($hostname);
        $instanceId = $instance['InstanceId'];
    } else {
        $instance = $clientHelper->getInstanceById($instanceId);
    }
    $instanceName = $clientHelper->resolveInstanceName($instance);
    $console->writeLine("Creating snapshots of {$instanceName}");
    $volumes = $clientHelper->getVolumesByInstance($instanceId);
    if (count($volumes) === 0) {
        echo "Unable to locate autoloader via include_path; aborting" . PHP_EOL;
        exit(2);
    }
} else {
    // Try to load StandardAutoloader from library
    if (false === (include $libPath . '/Zend/Loader/StandardAutoloader.php')) {
        echo "Unable to locate autoloader via library; aborting" . PHP_EOL;
        exit(2);
    }
}
// Setup autoloading
$loader = new StandardAutoloader(array('autoregister_zf' => true));
$loader->register();
$rules = array('help|h' => 'Get usage message', 'library|l-s' => 'Library to parse; if none provided, assumes current directory', 'output|o-s' => 'Where to write plugin map file; if not provided, assumes "plugin_classmap.php" in library directory', 'append|a' => 'Append to plugin map file if it exists', 'overwrite|w' => 'Whether or not to overwrite existing autoload file');
try {
    $opts = new Console\Getopt($rules);
    $opts->parse();
} catch (Console\Exception\RuntimeException $e) {
    echo $e->getUsageMessage();
    exit(2);
}
if ($opts->getOption('h')) {
    echo $opts->getUsageMessage();
    exit;
}
$path = $libPath;
if (array_key_exists('PWD', $_SERVER)) {
    $path = $_SERVER['PWD'];
}
if (isset($opts->l)) {
    $libraryPath = $opts->l;
Example #23
0
 /**
  * @see	\wcf\system\cli\command\ICLICommand::getUsage()
  */
 public function getUsage()
 {
     return str_replace($_SERVER['argv'][0] . ' [ options ]', 'help [ options ] <command>', $this->argv->getUsageMessage());
 }