Ejemplo n.º 1
0
 /**
  * This method acts as a controller which dispatches the request to the
  * correct command/method.
  *
  * <code>
  * $cli = \PEAR2\Pyrus\ScriptFrontend\Commands();
  * $cli->run($args = array (0 => 'install',
  *                          1 => 'PEAR2/Pyrus_Developer/package.xml'));
  * </code>
  *
  * The above code will dispatch to the install command
  *
  * @param array $args An array of command line arguments.
  *
  * @return void
  */
 function run($args)
 {
     try {
         $sig = \PEAR2\Pyrus\Main::getSignature();
         if ($sig) {
             echo "Pyrus version ", \PEAR2\Pyrus\Main::VERSION, ' ', $sig['hash_type'], ': ', $sig['hash'], "\n";
         }
         $this->_findPEAR($args);
         $this->verbose = \PEAR2\Pyrus\Config::current()->verbose;
         // scan for custom commands/roles/tasks
         \PEAR2\Pyrus\Config::current()->pluginregistry->scan();
         if (!isset(static::$commandParser->commands['make'])) {
             $this->addDeveloperCommands('developer');
         }
         if (!isset(static::$commandParser->commands['scs-update'])) {
             $this->addDeveloperCommands('scs');
         }
         $result = static::$commandParser->parse(count($args) + 1, array_merge(array('cruft'), $args));
         if ($result->options['verbose']) {
             $this->verbose = $result->options['verbose'];
         }
         if ($result->options['paranoid']) {
             \PEAR2\Pyrus\Main::$paranoid = $result->options['paranoid'];
         }
         if ($info = \PEAR2\Pyrus\PluginRegistry::getCommandInfo($result->command_name)) {
             if ($this instanceof $info['class']) {
                 if ($info['function'] == 'dummyStub' || $info['function'] == 'scsDummyStub') {
                     $this->{$info['function']}($result);
                 } else {
                     $this->{$info['function']}($result->command->args, $result->command->options);
                 }
             } else {
                 $class = new $info['class']();
                 $class->{$info['function']}($this, $result->command->args, $result->command->options);
             }
         } else {
             $this->help(array('command' => isset($args[0]) ? $args[0] : null));
         }
     } catch (\PEAR2\Console\CommandLine\Exception $e) {
         static::$commandParser->displayError($e->getMessage(), false);
         static::$commandParser->displayUsage(false);
     }
 }