当前位置: 首页>>代码示例>>PHP>>正文


PHP Console_CommandLine::displayError方法代码示例

本文整理汇总了PHP中Console_CommandLine::displayError方法的典型用法代码示例。如果您正苦于以下问题:PHP Console_CommandLine::displayError方法的具体用法?PHP Console_CommandLine::displayError怎么用?PHP Console_CommandLine::displayError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Console_CommandLine的用法示例。


在下文中一共展示了Console_CommandLine::displayError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 /**
  * Process the request
  *
  * @param array $params Runner options
  *
  * @return void
  */
 public function run($params = null)
 {
     $this->parser = new Parser($this->paths);
     try {
         $argc = $params === null ? null : count($params);
         $this->result = $this->parser->parse($argc, $params);
     } catch (\Exception $e) {
         $this->parser->displayError($e->getMessage());
     }
     $this->parse();
 }
开发者ID:negativespace,项目名称:phrozn,代码行数:18,代码来源:CommandLine.php

示例2: run

	/**
	 * Run tasks (basically, try to parse a command line)
	 */
	public function run() {
		// Parse the command line arguments
		try {
			$this->cli = $this->parser->parse();
		} catch (Exception $e) {
			$this->parser->displayError($e->getMessage());
			exit($e->getCode());
		}
	}
开发者ID:niieani,项目名称:nandu,代码行数:12,代码来源:Scripts.php

示例3: process

 /**
  * Process command
  *
  * @return  string
  */
 public function process()
 {
     try {
         $this->command = $this->parser->parse();
         if (empty($this->command->command_name)) {
             $this->parser->displayUsage();
             self::end(0);
         }
         $return = $this->controller->execute($this->command->command_name, $this->command->command->options, $this->command->command->args, $this->color, $this->logger, $this->tasks);
     } catch (ShellException $se) {
         $this->parser->displayError($this->color->convert("\n\n%R" . $se->getMessage() . "%n\n"));
         self::end(1);
     } catch (Exception $e) {
         $this->parser->displayError($this->color->convert("\n\n%r" . $e->getMessage() . "%n\n"));
         self::end(1);
     }
     echo "\n" . $return . "\n\n";
     self::end(0);
 }
开发者ID:comodojo,项目名称:extender.framework,代码行数:24,代码来源:Econtrol.php

示例4: array

$consoleParser->addOption("restrict_input_file", array("help_name" => "/tmp/missing.txt", "short_name" => "-r", "long_name" => "--restrict-file", "description" => "Domain list, one per line. Others won't be imported.", 'default' => ""));
$consoleParser->addOption("force_uid", array("help_name" => "2001", "short_name" => "-u", "long_name" => "--force-uid", "description" => "Force the domain owner", 'default' => null));
// Run the command line parser
try {
    $commandLineResult = $consoleParser->parse();
    // Run the service
    if (!($result = $service->import($commandLineResult))) {
        throw new \Exception("Import process failed");
    }
    $message = "";
    $level = Logger\AbstractLogger::INFO;
    if (isset($result["message"])) {
        $message .= $result["message"] . "\n";
    }
    if (isset($result["successList"]) && count($result["successList"])) {
        $message .= "# Success\n";
        $message .= implode("\n", $result["successList"]) . "\n";
    }
    if (isset($result["errorsList"]) && count($result["errorsList"])) {
        $level = Logger\AbstractLogger::WARNING;
        $message .= "# Errors \n";
        $message .= implode("\n", $result["errorsList"]) . "\n";
    }
    echo $message . "\n";
    $logger->logMessage($level, $message);
    // Boom goes your request
} catch (\Exception $exc) {
    $message = $exc->getMessage();
    $logger->logMessage(Logger\AbstractLogger::CRITICAL, $message);
    $consoleParser->displayError($message);
}
开发者ID:AlternC,项目名称:alternc-tools,代码行数:31,代码来源:target_create_domains.php

示例5: array

 * @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;
    // no public key
}
if ($options['public']) {
    if (!file_exists($options['public']) || !is_readable($options['public'])) {
        $parser->displayError("Public key in '{$options['public']}' does not exist or is not readable.", 4);
开发者ID:richarrj,项目名称:phar-util,代码行数:31,代码来源:phar-verify.php

示例6: array

set_include_path(".:" . get_include_path());
require_once "bootstrap.php";
// Instanciate export service
$service = new Alternc_Tools_Mailbox_Export(array("db" => $db));
// Instanciate command line parser
$consoleParser = new Console_CommandLine(array("description" => "Exports Alternc mailboxes to a file for export."));
// Configure command line parser
$consoleParser->add_version_option = false;
$consoleParser->addOption("output_file", array("help_name" => "/tmp/out.json", "short_name" => "-o", "long_name" => "--output-file", "description" => "Export file name and path", 'default' => $service->default_output));
$consoleParser->addOption("single_domain", array("help_name" => "domain.com", "short_name" => "-d", "long_name" => "--single-domain", "description" => "A single domain to export"));
$consoleParser->addOption("single_account", array("help_name" => "foobar", "short_name" => "-a", "long_name" => "--single-account", "description" => "A single account name (i.e. AlternC login) to export\n"));
$consoleParser->addOption("exclude_mails", array("help_name" => "/tmp/mailboxes.txt", "long_name" => "--exclude-mails", "description" => "Path of a file containing mailboxes to exclude, separated by breaklines"));
$consoleParser->addOption("include_mails", array("help_name" => "/tmp/mailboxes.txt", "long_name" => "--include-mails", "description" => "Path of a file containing mailboxes to include, separated by breaklines"));
$consoleParser->addOption("exclude_domain", array("help_name" => "/tmp/domain.txt", "long_name" => "--exclude-domains", "description" => "Path of a file containing domains to include, separated by breaklines"));
$consoleParser->addOption("include_domains", array("help_name" => "/tmp/domain.txt", "long_name" => "--include-domains", "description" => "Path of a file containing domains to exclude, separated by breaklines"));
// Run the command line parser
try {
    $commandLineResult = $consoleParser->parse();
    // Run the service
    if (!($result = $service->run($commandLineResult))) {
        throw new \Exception("Export process failed");
    }
    $msg = $result["message"];
    $logger->logMessage(Logger\AbstractLogger::INFO, $msg);
    echo $msg . "\n";
    // Boom goes your request
} catch (\Exception $exc) {
    $msg = $exc->getMessage();
    $logger->logMessage(Logger\AbstractLogger::CRITICAL, $msg);
    $consoleParser->displayError($msg);
}
开发者ID:AlternC,项目名称:alternc-tools,代码行数:31,代码来源:source_create_export_file.php

示例7: run

 /**
  * Entry-point for Erebot.
  *
  * \return
  *      This method never returns.
  *      Instead, the program exits with an appropriate
  *      return code when Erebot is stopped.
  */
 public static function run()
 {
     // Apply patches.
     \Erebot\Patches::patch();
     // Load the configuration for the Dependency Injection Container.
     $dic = new \Symfony\Component\DependencyInjection\ContainerBuilder();
     $dic->setParameter('Erebot.src_dir', __DIR__);
     $loader = new \Symfony\Component\DependencyInjection\Loader\XmlFileLoader($dic, new \Symfony\Component\Config\FileLocator(getcwd()));
     $dicConfig = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'defaults.xml';
     $dicCwdConfig = getcwd() . DIRECTORY_SEPARATOR . 'defaults.xml';
     if (!strncasecmp(__FILE__, 'phar://', 7)) {
         if (!file_exists($dicCwdConfig)) {
             copy($dicConfig, $dicCwdConfig);
         }
         $dicConfig = $dicCwdConfig;
     } elseif (file_exists($dicCwdConfig)) {
         $dicConfig = $dicCwdConfig;
     }
     $loader->load($dicConfig);
     // Determine availability of PHP extensions
     // needed by some of the command-line options.
     $hasPosix = in_array('posix', get_loaded_extensions());
     $hasPcntl = in_array('pcntl', get_loaded_extensions());
     $logger = $dic->get('logging');
     $localeGetter = $dic->getParameter('i18n.default_getter');
     $coreTranslatorCls = $dic->getParameter('core.classes.i18n');
     $translator = new $coreTranslatorCls("Erebot\\Core");
     $categories = array('LC_MESSAGES', 'LC_MONETARY', 'LC_TIME', 'LC_NUMERIC');
     foreach ($categories as $category) {
         $locales = call_user_func($localeGetter);
         $locales = empty($locales) ? array() : array($locales);
         $localeSources = array('LANGUAGE' => true, 'LC_ALL' => false, $category => false, 'LANG' => false);
         foreach ($localeSources as $source => $multiple) {
             if (!isset($_SERVER[$source])) {
                 continue;
             }
             if ($multiple) {
                 $locales = explode(':', $_SERVER[$source]);
             } else {
                 $locales = array($_SERVER[$source]);
             }
             break;
         }
         $translator->setLocale($translator->nameToCategory($category), $locales);
     }
     // Also, include some information about the version
     // of currently loaded PHAR modules, if any.
     $version = 'dev-master';
     if (!strncmp(__FILE__, 'phar://', 7)) {
         $phar = new \Phar(\Phar::running(true));
         $md = $phar->getMetadata();
         $version = $md['version'];
     }
     if (defined('Erebot_PHARS')) {
         $phars = unserialize(Erebot_PHARS);
         ksort($phars);
         foreach ($phars as $module => $metadata) {
             if (strncasecmp($module, 'Erebot_Module_', 14)) {
                 continue;
             }
             $version .= "\n  with {$module} version {$metadata['version']}";
         }
     }
     \Console_CommandLine::registerAction('StoreProxy', '\\Erebot\\Console\\StoreProxyAction');
     $parser = new \Console_CommandLine(array('name' => 'Erebot', 'description' => $translator->gettext('A modular IRC bot written in PHP'), 'version' => $version, 'add_help_option' => true, 'add_version_option' => true, 'force_posix' => false));
     $parser->accept(new \Erebot\Console\MessageProvider());
     $parser->renderer->options_on_different_lines = true;
     $defaultConfigFile = getcwd() . DIRECTORY_SEPARATOR . 'Erebot.xml';
     $parser->addOption('config', array('short_name' => '-c', 'long_name' => '--config', 'description' => $translator->gettext('Path to the configuration file to use instead ' . 'of "Erebot.xml", relative to the current ' . 'directory.'), 'help_name' => 'FILE', 'action' => 'StoreString', 'default' => $defaultConfigFile));
     $parser->addOption('daemon', array('short_name' => '-d', 'long_name' => '--daemon', 'description' => $translator->gettext('Run the bot in the background (daemon).' . ' [requires the POSIX and pcntl extensions]'), 'action' => 'StoreTrue'));
     $noDaemon = new \Erebot\Console\ParallelOption('no_daemon', array('short_name' => '-n', 'long_name' => '--no-daemon', 'description' => $translator->gettext('Do not run the bot in the background. ' . 'This is the default, unless the -d option ' . 'is used or the bot is configured otherwise.'), 'action' => 'StoreProxy', 'action_params' => array('option' => 'daemon')));
     $parser->addOption($noDaemon);
     $parser->addOption('pidfile', array('short_name' => '-p', 'long_name' => '--pidfile', 'description' => $translator->gettext("Store the bot's PID in this file."), 'help_name' => 'FILE', 'action' => 'StoreString', 'default' => null));
     $parser->addOption('group', array('short_name' => '-g', 'long_name' => '--group', 'description' => $translator->gettext('Set group identity to this GID/group during ' . 'startup. The default is to NOT change group ' . 'identity, unless configured otherwise.' . ' [requires the POSIX extension]'), 'help_name' => 'GROUP/GID', 'action' => 'StoreString', 'default' => null));
     $parser->addOption('user', array('short_name' => '-u', 'long_name' => '--user', 'description' => $translator->gettext('Set user identity to this UID/username during ' . 'startup. The default is to NOT change user ' . 'identity, unless configured otherwise.' . ' [requires the POSIX extension]'), 'help_name' => 'USER/UID', 'action' => 'StoreString', 'default' => null));
     try {
         $parsed = $parser->parse();
     } catch (\Exception $exc) {
         $parser->displayError($exc->getMessage());
         exit(1);
     }
     // Parse the configuration file.
     $config = new \Erebot\Config\Main($parsed->options['config'], \Erebot\Config\Main::LOAD_FROM_FILE, $translator);
     $coreCls = $dic->getParameter('core.classes.core');
     $bot = new $coreCls($config, $translator);
     $dic->set('bot', $bot);
     // Use values from the XML configuration file
     // if there is no override from the command line.
     $overrides = array('daemon' => 'mustDaemonize', 'group' => 'getGroupIdentity', 'user' => 'getUserIdentity', 'pidfile' => 'getPidfile');
     foreach ($overrides as $option => $func) {
         if ($parsed->options[$option] === null) {
             $parsed->options[$option] = $config->{$func}();
//.........这里部分代码省略.........
开发者ID:erebot,项目名称:erebot,代码行数:101,代码来源:CLI.php

示例8: array

 */
require_once 'Console/CommandLine.php';
// create the parser
$parser = new Console_CommandLine(array('description' => 'Check to see if a PHAR archive rebuild is necessary.', 'version' => '@package_version@', 'name' => 'phar-file-checksums'));
$parser->addOption('src', array('short_name' => '-s', 'long_name' => '--src', 'action' => 'StoreString', 'default' => './src', 'description' => "Source files directory\n(./src)"));
$parser->addOption('exclude_files', array('short_name' => '-x', 'long_name' => '--exclude', 'action' => 'StoreString', 'default' => '~$', 'description' => "Space separated regular expressions of filenames that should be excluded\n(\"~\$\" by default)"));
$parser->addOption('exclude_dirs', array('short_name' => '-X', 'long_name' => '--exclude-dir', 'action' => 'StoreString', 'default' => '/\\.svn /\\.git', 'description' => "Space separated regular expressions of directories that should be excluded\n(\"/\\.svn /\\.git\" by default)"));
$parser->addOption('quiet', array('short_name' => '-q', 'long_name' => '--quiet', 'action' => 'StoreTrue', 'description' => 'Suppress most of the output statements.'));
$parser->addOption('verbose', array('short_name' => '-v', 'long_name' => '--verbose', 'action' => 'StoreTrue', 'description' => 'Outputs additional information to the console.'));
$parser->addOption('checksum_file', array('short_name' => '-c', 'long_name' => '--checksumfile', 'action' => 'StoreString', 'default' => './checksum-file.json', 'description' => "JSON file for storing source file checksums \n(./checksum-file.json)."));
$parser->addOption('nowrites_checksum', array('long_name' => '--no-save-checksums', 'action' => 'StoreTrue', 'description' => 'Do not save checksums obtained to the checksum file.'));
// run the parser
try {
    $result = $parser->parse();
} catch (Exception $exc) {
    $parser->displayError($exc->getMessage());
}
$options = $result->options;
// Use a constant to avoid globals.
define('QUIET_MODE', (bool) $options['quiet']);
define('VERBOSE_MODE', (bool) $options['verbose']);
if (!QUIET_MODE) {
    echo $parser->name . ' ' . $parser->version . PHP_EOL . PHP_EOL;
}
// validate parameters
if (!class_exists('Phar')) {
    $parser->displayError("No Phar support found, you need to build and enable Phar extension. Exiting...", 10);
}
if (!is_dir($options['src']) || !is_readable($options['src'])) {
    $parser->displayError("Source directory in '{$options['src']}' does not exist or is not readable.\n,", 5);
}
开发者ID:richarrj,项目名称:phar-util,代码行数:31,代码来源:phar-file-checksums.php

示例9: 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);
 }
开发者ID:hnw,项目名称:php425,代码行数:30,代码来源:php425.php

示例10: runUnsafe

 /**
  * Runs Chef given some command-line arguments.
  */
 public function runUnsafe($userArgc = null, $userArgv = null)
 {
     // Get the arguments.
     if ($userArgc == null || $userArgv == null) {
         $getopt = new \Console_Getopt();
         $userArgv = $getopt->readPHPArgv();
         // `readPHPArgv` returns a `PEAR_Error` (or something like it) if
         // it can't figure out the CLI arguments.
         if (!is_array($userArgv)) {
             throw new PieCrustException($userArgv->getMessage());
         }
         $userArgc = count($userArgv);
     }
     // Find whether the '--root' parameter was given.
     $rootDir = null;
     foreach ($userArgv as $arg) {
         if (substr($arg, 0, strlen('--root=')) == '--root=') {
             $rootDir = substr($arg, strlen('--root='));
             break;
         }
     }
     if ($rootDir == null) {
         // No root given. Find it ourselves.
         $rootDir = PathHelper::getAppRootDir(getcwd());
     } else {
         // The root was given.
         $rootDir = PathHelper::getAbsolutePath($rootDir);
         if (!is_dir($rootDir)) {
             throw new PieCrustException("The given root directory doesn't exist: " . $rootDir);
         }
     }
     // Build the appropriate app.
     if ($rootDir == null) {
         $pieCrust = new NullPieCrust();
     } else {
         $pieCrust = new PieCrust(array('root' => $rootDir, 'cache' => !in_array('--no-cache', $userArgv)));
     }
     // Set up the command line parser.
     $parser = new \Console_CommandLine(array('name' => 'chef', 'description' => 'The PieCrust chef manages your website.', 'version' => PieCrustDefaults::VERSION));
     // Sort commands by name.
     $sortedCommands = $pieCrust->getPluginLoader()->getCommands();
     usort($sortedCommands, function ($c1, $c2) {
         return strcmp($c1->getName(), $c2->getName());
     });
     // Add commands to the parser.
     foreach ($sortedCommands as $command) {
         $commandParser = $parser->addCommand($command->getName());
         $command->setupParser($commandParser, $pieCrust);
         $this->addCommonOptionsAndArguments($commandParser);
     }
     // Parse the command line.
     try {
         $result = $parser->parse($userArgc, $userArgv);
     } catch (Exception $e) {
         $parser->displayError($e->getMessage());
         return 1;
     }
     // If no command was given, use `help`.
     if (empty($result->command_name)) {
         $result = $parser->parse(2, array('chef', 'help'));
     }
     // Create the log.
     $debugMode = $result->command->options['debug'];
     $quietMode = $result->command->options['quiet'];
     if ($debugMode && $quietMode) {
         $parser->displayError("You can't specify both --debug and --quiet.");
         return 1;
     }
     $log = \Log::singleton('console', 'Chef', '', array('lineFormat' => '%{message}'));
     // Make the log available for debugging purposes.
     $GLOBALS['__CHEF_LOG'] = $log;
     // Handle deprecated stuff.
     if ($result->command->options['no_cache_old']) {
         $log->warning("The `--nocache` option has been renamed `--no-cache`.");
         $result->command->options['no_cache'] = true;
     }
     // Run the command.
     foreach ($pieCrust->getPluginLoader()->getCommands() as $command) {
         if ($command->getName() == $result->command_name) {
             try {
                 if ($rootDir == null && $command->requiresWebsite()) {
                     $cwd = getcwd();
                     throw new PieCrustException("No PieCrust website in '{$cwd}' ('_content/config.yml' not found!).");
                 }
                 $context = new ChefContext($pieCrust, $result, $log);
                 $context->setVerbosity($debugMode ? 'debug' : ($quietMode ? 'quiet' : 'default'));
                 $command->run($context);
                 return;
             } catch (Exception $e) {
                 $log->emerg(self::getErrorMessage($e, $debugMode));
                 return 1;
             }
         }
     }
 }
开发者ID:omnicolor,项目名称:bulletphp-site,代码行数:98,代码来源:Chef.php

示例11: application_path

}
define("CUPCAKE_PATH", $cupcake_path);
if (CUPCAKE_PATH === null) {
    echo "\nCupcake Not Found\nMake sure to set the include_path\n";
    exit;
}
# Load any commands extended by the application from /cli
if (file_exists("cli") && is_dir("cli")) {
    foreach (glob("cli/*.php") as $cli_file) {
        include_once $cli_file;
    }
}
try {
    $result = $command->parse();
} catch (Exception $exc) {
    $command->displayError($exc->getMessage());
    exit;
}
$options = $result->options;
foreach ($options as $k => $name) {
    if (!empty($name)) {
        $terminal = $command->options[$k];
        $callback = $terminal->callback;
        if (is_string($callback) && strlen($callback) > 0) {
            $callback($options, $terminal);
        }
    }
}
function application_path($opts = array())
{
    $path = empty($opts['path']) === true ? "." : $opts['path'];
开发者ID:ahmed555,项目名称:Cupcake,代码行数:31,代码来源:cupcake.php

示例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);
 }
开发者ID:hnw,项目名称:phpbugs,代码行数:31,代码来源:phpbugs.php

示例13: array

// create the parser
$parser = new Console_CommandLine(array('description' => 'Build a phar archive and sign it using a private key from a given file', 'version' => '@package_version@', 'name' => 'phar-build'));
$parser->addOption('src', array('short_name' => '-s', 'long_name' => '--src', 'action' => 'StoreString', 'default' => './src', 'description' => "Source files directory\n(./src)"));
$parser->addOption('stub', array('short_name' => '-S', 'long_name' => '--stub', 'action' => 'StoreString', 'default' => './stub.php', 'description' => "(optional) stub file for phar \n(./stub.php)\nIf stub file does not exist, default stub will be used."));
$parser->addOption('exclude_files', array('short_name' => '-x', 'long_name' => '--exclude', 'action' => 'StoreString', 'default' => '~$', 'description' => "Space separated regular expressions of filenames that should be excluded\n(\"~\$\" by default)"));
$parser->addOption('exclude_dirs', array('short_name' => '-X', 'long_name' => '--exclude-dir', 'action' => 'StoreString', 'default' => '/\\.svn /\\.git', 'description' => "Space separated regular expressions of directories that should be excluded\n(\"/\\.svn /\\.git\" by default)"));
$parser->addOption('private', array('short_name' => '-p', 'long_name' => '--private', 'action' => 'StoreString', 'default' => './cert/priv.pem', 'description' => "Private key file (PEM) to generate signature\n(./cert/priv.pem)"));
$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)"));
$parser->addOption('nosign', array('short_name' => '-n', 'long_name' => '--ns', 'action' => 'StoreTrue', 'description' => 'Don\'t sign the Phar archive'));
$parser->addOption('quiet', array('short_name' => '-q', 'long_name' => '--quiet', 'action' => 'StoreTrue', 'description' => 'Suppress most of the output statements.'));
$parser->addOption('phar', array('long_name' => '--phar', 'action' => 'StoreString', 'default' => './output.phar', 'description' => "Output Phar archive filename\n(./output.phar)"));
// run the parser
try {
    $result = $parser->parse();
} catch (Exception $exc) {
    $parser->displayError($exc->getMessage());
}
$options = $result->options;
// Use a constant to avoid globals.
define('QUIET_MODE', (bool) $options['quiet']);
if (!QUIET_MODE) {
    echo $parser->name . ' ' . $parser->version . PHP_EOL . PHP_EOL;
}
// validate parameters
if (!class_exists('Phar')) {
    $parser->displayError("No Phar support found, you need to build and enable Phar extension. Exiting...", 10);
}
if (!Phar::canWrite()) {
    $parser->displayError("Phar writing support is disabled in this PHP installation, set phar.readonly=0 in php.ini!", 10);
}
if (substr($options['phar'], -5) !== '.phar') {
开发者ID:holdensmagicalunicorn,项目名称:phar-util,代码行数:31,代码来源:phar-build.php

示例14: execute


//.........这里部分代码省略.........
     // parse
     $cli = $this->_config['cli'];
     $parser = new Console_CommandLine(array('name' => 'bear', 'description' => 'BEAR command line interface', 'version' => BEAR::VERSION, 'add_help_option' => true, 'add_version_option' => true));
     // create resource
     $subCmd = $parser->addCommand(self::CMD_CREATE, array('description' => 'create resource.'));
     $subCmd->addOption('file', array('short_name' => '-g', 'long_name' => '--file', 'action' => 'StoreString', 'description' => 'load arguments file.'));
     $subCmd->addOption('app', array('short_name' => '-a', 'long_name' => '--app', 'action' => 'StoreString', 'description' => 'specify application path. *Notice* use this on the end of line.'));
     $subCmd->addArgument('uri', array('description' => 'resource URI'));
     // read resource
     $subCmd = $parser->addCommand(self::CMD_READ, array('description' => 'show resource.'));
     $subCmd->addOption('file', array('short_name' => '-g', 'long_name' => '--file', 'action' => 'StoreString', 'description' => 'load arguments file.'));
     $subCmd->addOption('length', array('short_name' => '-l', 'long_name' => '--len', 'action' => 'StoreInt', 'description' => 'filter specific lenght each data.'));
     $subCmd->addOption('format', array('short_name' => '-f', 'long_name' => '--format', 'action' => 'StoreString', 'description' => 'default | table | php | json | csv | printa '));
     $subCmd->addOption('app', array('short_name' => '-a', 'long_name' => '--app', 'action' => 'StoreString', 'description' => 'specify application path. *Notice* use this on the end of line.'));
     $subCmd->addArgument('uri', array('description' => 'resource URI'));
     // update resource
     $subCmd = $parser->addCommand(self::CMD_UPDATE, array('description' => 'update resource.'));
     $subCmd->addOption('file', array('short_name' => '-g', 'long_name' => '--file', 'action' => 'StoreString', 'description' => 'load arguments file.'));
     $subCmd->addOption('app', array('short_name' => '-a', 'long_name' => '--app', 'action' => 'StoreString', 'description' => 'specify application path. *Notice* use this on the end of line.'));
     $subCmd->addArgument('uri', array('description' => 'resource URI'));
     // delete resource
     $subCmd = $parser->addCommand(self::CMD_DELETE, array('description' => 'delete resource.'));
     $subCmd->addOption('file', array('short_name' => '-a', 'long_name' => '--file', 'action' => 'StoreString', 'description' => 'load arguments file.'));
     $subCmd->addOption('app', array('short_name' => '-a', 'long_name' => '--app', 'action' => 'StoreString', 'description' => 'specify application path. *Notice* use this on the end of line.'));
     $subCmd->addArgument('uri', array('description' => 'resource URI'));
     // clear-cache
     $parser->addCommand('clear-cache', array('description' => 'clear all cache.'));
     // clear-log
     $parser->addCommand('clear-log', array('description' => 'clear all log.'));
     // clear-all
     $parser->addCommand('clear-all', array('description' => 'clear cache and log.'));
     if ($cli) {
         // create app
         $subCmd = $parser->addCommand(self::CMD_INIT_APP, array('description' => 'create new application.'));
         $subCmd->addArgument('path', array('description' => 'destination path. ex) /var/www/bear.test'));
         $subCmd->addOption('pearrc', array('short_name' => '-c', 'long_name' => '--pearrc', 'action' => 'StoreString', 'description' => 'find user configuration in `file`'));
         // set app
         $subCmd = $parser->addCommand(self::CMD_SET_APP, array('description' => 'set application path.'));
         $subCmd->addArgument('path', array('description' => 'application path. ex) /var/www/bear.test'));
         // show app
         $subCmd = $parser->addCommand(self::CMD_SHOW_APP, array('description' => 'show application path.'));
     }
     //exec
     try {
         ob_start();
         $this->_command = $parser->parse(count($argv), $argv);
         $buff = ob_get_clean();
         $commandName = $this->_command->command_name;
         switch ($this->_command->command_name) {
             case self::CMD_INIT_APP:
                 $path = $this->_command->command->args['path'];
                 $path = $this->_makeFullPath($path);
                 $pearrc = $this->_command->command->options['pearrc'];
                 $this->_initApp($path, $pearrc);
                 $this->_setApp($path);
                 break;
             case self::CMD_SET_APP:
                 $path = $this->_command->command->args['path'];
                 $path = $this->_makeFullPath($path);
                 $this->_setApp($path);
                 break;
             case self::CMD_SHOW_APP:
                 $this->_checkAppExists();
                 $this->_showApp();
                 break;
             case self::CMD_CLEAR_CACHE:
                 $this->_checkAppExists();
                 $this->clearCache();
                 break;
             case self::CMD_CLEAR_LOG:
                 $this->_checkAppExists();
                 $this->clearLog();
                 break;
             case self::CMD_CLEAR_ALL:
                 $this->_checkAppExists();
                 $this->clearCache();
                 $this->clearLog();
                 break;
             case self::CMD_CREATE:
             case self::CMD_READ:
             case self::CMD_UPDATE:
             case self::CMD_DELETE:
                 $this->_checkAppExists();
                 $uri = $this->_command->command->args['uri'];
                 $values = $this->_command->command->options['file'] ? BEAR::loadValues($this->_command->command->options['file']) : array();
                 $this->_result = $this->_request($commandName, $uri, $values)->getRo();
                 $this->_config['debug'] = true;
                 break;
             default:
                 if ($this->_config['cli']) {
                     $this->_result = "BEAR: {$argv[1]}: command not found, try 'bear --help'";
                 } else {
                     $this->_result = "BEAR: {$argv[1]}: command not found, try 'help'";
                 }
                 return;
         }
     } catch (Exception $e) {
         $parser->displayError($e->getMessage());
     }
 }
开发者ID:ryo88c,项目名称:BEAR.Saturday,代码行数:101,代码来源:Shell.php

示例15: 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']);
开发者ID:cweiske,项目名称:phinde,代码行数:31,代码来源:process.php


注:本文中的Console_CommandLine::displayError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。