Ejemplo n.º 1
0
 public function run($commandLine = null)
 {
     $this->parser = new nbCommandLineParser($this->arguments->getArguments(), $this->options->getOptions());
     $this->parser->parse($commandLine);
     if ($this->handleOptions($this->parser->getOptionValues())) {
         return;
     }
     $this->verifyOptionCommand();
     $commandName = 'list';
     if ($this->parser->hasArgumentValue('command')) {
         $commandName = $this->parser->getArgumentValue('command');
     } else {
         $commandLine = $commandName . ' ' . $commandLine;
     }
     if (!$this->getCommands()->hasCommand($commandName)) {
         return;
     }
     $command = $this->getCommands()->getCommand($commandName);
     $r = new ReflectionClass($command);
     if ($r->isSubclassOf('nbApplicationCommand')) {
         $command->setApplication($this);
     }
     try {
         $command->run($this->parser, $commandLine, $this->verbose);
     } catch (InvalidArgumentException $e) {
         $this->logger->logLine('');
         $helpCmd = new nbHelpCommand();
         $this->logger->log($helpCmd->formatHelp($command));
         $this->logger->logLine('');
         $this->logger->logLine($e->getMessage(), nbLogger::ERROR);
     } catch (Exception $e) {
         $this->logger->logLine($e->getMessage(), nbLogger::ERROR);
     }
 }
Ejemplo n.º 2
0
<?php

require_once dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new lime_test(3);
$output = new nbStreamOutput();
nbLogger::getInstance()->setOutput($output);
$application = new DummyApplication($serviceContainer);
$command = new nbHelpCommand();
$command->setApplication($application);
$serviceContainer->commandLoader->getCommands()->addCommand(new DummyCommand('dummy1'));
$serviceContainer->commandLoader->getCommands()->addCommand($command);
$t->comment('nbHelpCommandTest - Test get name');
$t->is($command->getName(), 'help', '->getName() is "help"');
//$t->comment('nbHelpCommandTest - Test print command help');
//$command->run(new nbCommandLineParser(), array('help'));
//$t->ok($application->executedFormatHelpString, '->run() called nbApplication::formatHelpString()');
//$application->executedFormatHelpString = false;
$t->comment('nbHelpCommandTest - Test unknown command');
try {
    $command->run(new nbCommandLineParser(), array('cmd'));
    $t->fail('->run() throws an Exception if command is not found');
} catch (Exception $e) {
    $t->pass('->run() throws an Exception if command is not found');
}
$t->ok(!$application->executedFormatHelpString, '->run() didn\'t call nbApplication::formatHelpString()');
//$t->comment('nbHelpCommandTest - Test existing command');
//$command->run(new nbCommandLineParser(), array('dummy1'));
//$t->ok($application->executedFormatHelpString, '->run() called nbApplication::formatHelpString()');