С версии: 1.0
Автор: Bernhard Schussek (bschussek@gmail.com)
Пример #1
0
 /**
  * @param Application       $application
  * @param RawArgs           $args
  * @param InputStream|null  $inputStream
  * @param OutputStream|null $outputStream
  * @param OutputStream|null $errorStream
  *
  * @return ConsoleIO
  */
 public function createIO(Application $application, RawArgs $args, InputStream $inputStream = null, OutputStream $outputStream = null, OutputStream $errorStream = null)
 {
     $inputStream = $inputStream ?: new StandardInputStream();
     $outputStream = $outputStream ?: new StandardOutputStream();
     $errorStream = $errorStream ?: new ErrorOutputStream();
     $styleSet = $application->getConfig()->getStyleSet();
     if ($args->hasToken('--no-ansi')) {
         $outputFormatter = $errorFormatter = new PlainFormatter($styleSet);
     } elseif ($args->hasToken('--ansi')) {
         $outputFormatter = $errorFormatter = new AnsiFormatter($styleSet);
     } else {
         $outputFormatter = $outputStream->supportsAnsi() ? new AnsiFormatter($styleSet) : new PlainFormatter($styleSet);
         $errorFormatter = $errorStream->supportsAnsi() ? new AnsiFormatter($styleSet) : new PlainFormatter($styleSet);
     }
     $io = new ConsoleIO(new Input($inputStream), new Output($outputStream, $outputFormatter), new Output($errorStream, $errorFormatter));
     if ($args->hasToken('-vvv') || $this->isDebug()) {
         $io->setVerbosity(IO::DEBUG);
     } elseif ($args->hasToken('-vv')) {
         $io->setVerbosity(IO::VERY_VERBOSE);
     } elseif ($args->hasToken('-v')) {
         $io->setVerbosity(IO::VERBOSE);
     }
     if ($args->hasToken('--quiet') || $args->hasToken('-q')) {
         $io->setQuiet(true);
     }
     if ($args->hasToken('--no-interaction') || $args->hasToken('-n')) {
         $io->setInteractive(false);
     }
     return $io;
 }
Пример #2
0
 public static function setUpBeforeClass()
 {
     while (false === @mkdir(self::$tempDir = sys_get_temp_dir() . '/puli-cli/AbstractCommandHandlerTest' . rand(10000, 99999), 0777, true)) {
     }
     self::$application = new ConsoleApplication(new PuliApplicationConfig(new Puli(self::$tempDir)));
     self::$formatter = new PlainFormatter(self::$application->getConfig()->getStyleSet());
 }
Пример #3
0
 protected function setUp()
 {
     $config = DefaultApplicationConfig::create()->setDisplayName('The Application')->setVersion('1.2.3')->beginCommand('the-command')->end();
     $this->application = new ConsoleApplication($config);
     $this->command = $this->application->getCommand('the-command');
     $this->helpCommand = $this->application->getCommand('help');
     $this->io = new BufferedIO();
     $this->handler = new HelpXmlHandler();
 }
Пример #4
0
 protected function setUp()
 {
     $config = DefaultApplicationConfig::create()->beginCommand('the-command')->end();
     $this->application = new ConsoleApplication($config);
     $this->command = $this->application->getCommand('the-command');
     $this->helpCommand = $this->application->getCommand('help');
     $this->io = new BufferedIO();
     $this->handler = new HelpJsonHandler();
 }
 public static function setUpBeforeClass()
 {
     while (false === @mkdir(self::$tempDir = sys_get_temp_dir() . '/puli-web-plugin/AbstractCommandHandlerTest' . rand(10000, 99999), 0777, true)) {
     }
     $puli = new Puli(self::$tempDir);
     $config = new PuliApplicationConfig($puli);
     $plugin = new AssetPlugin();
     $plugin->activate($puli);
     self::$application = new ConsoleApplication($config);
     self::$formatter = new PlainFormatter(self::$application->getConfig()->getStyleSet());
 }
Пример #6
0
 protected function setUp()
 {
     $config = DefaultApplicationConfig::create()->setName('the-app')->setDisplayName('The Application')->setVersion('1.2.3')->beginCommand('the-command')->end();
     $this->manDir = __DIR__ . '/Fixtures/man';
     $this->asciiDocDir = __DIR__ . '/Fixtures/ascii-doc';
     $this->application = new ConsoleApplication($config);
     $this->command = $this->application->getCommand('the-command');
     $this->helpCommand = $this->application->getCommand('help');
     $this->io = new BufferedIO();
     $this->executableFinder = $this->getMockBuilder('Symfony\\Component\\Process\\ExecutableFinder')->disableOriginalConstructor()->getMock();
     $this->processLauncher = $this->getMockBuilder('Webmozart\\Console\\Process\\ProcessLauncher')->disableOriginalConstructor()->getMock();
     $this->handler = new HelpHandler($this->executableFinder, $this->processLauncher);
     $this->handler->setManDir($this->manDir);
     $this->handler->setAsciiDocDir($this->asciiDocDir);
 }
Пример #7
0
 /**
  * Renders the "Usage" section.
  *
  * @param BlockLayout $layout      The layout.
  * @param Application $application The application to describe.
  * @param ArgsFormat  $argsFormat  The format of the console arguments.
  */
 protected function renderUsage(BlockLayout $layout, Application $application, ArgsFormat $argsFormat)
 {
     $appName = $application->getConfig()->getName();
     $layout->add(new Paragraph('<b>USAGE</b>'));
     $layout->beginBlock();
     $this->renderSynopsis($layout, $argsFormat, $appName);
     $layout->endBlock();
     $layout->add(new EmptyLine());
 }
Пример #8
0
 /**
  * Returns the inherited arguments format of the command.
  *
  * @return ArgsFormat The inherited format.
  *
  * @see CommandConfig::buildArgsFormat()
  */
 private function getBaseFormat()
 {
     if ($this->parentCommand) {
         return $this->parentCommand->getArgsFormat();
     }
     if ($this->application) {
         return $this->application->getGlobalArgsFormat();
     }
     return null;
 }
Пример #9
0
 /**
  * {@inheritdoc}
  */
 public function resolveCommand(RawArgs $args, Application $application)
 {
     $tokens = $args->getTokens();
     $namedCommands = $application->getNamedCommands();
     $argumentsToTest = $this->getArgumentsToTest($tokens);
     $optionsToTest = $this->getOptionsToTest($tokens);
     // Try to find a command for the passed arguments and options.
     if ($result = $this->processArguments($args, $namedCommands, $argumentsToTest, $optionsToTest)) {
         return $this->createResolvedCommand($result);
     }
     // If arguments were passed, we did not find the matching command.
     if ($argumentsToTest) {
         throw CannotResolveCommandException::nameNotFound(reset($argumentsToTest), $namedCommands);
     }
     // If no arguments were passed, run the application's default command.
     if ($result = $this->processDefaultCommands($args, $application->getDefaultCommands())) {
         return $this->createResolvedCommand($result);
     }
     // No default command is configured.
     throw CannotResolveCommandException::noDefaultCommand();
 }
Пример #10
0
 public function testHandleDispatchesEvent()
 {
     $args = new Args(new ArgsFormat());
     $io = $this->getMockBuilder('Webmozart\\Console\\Api\\IO\\IO')->disableOriginalConstructor()->getMock();
     $handler = $this->getMock('stdClass', array('handle'));
     $this->application->getConfig()->addEventListener(ConsoleEvents::PRE_HANDLE, function (PreHandleEvent $event) {
         $event->setHandled(true);
         $event->setStatusCode(123);
     });
     $config = new CommandConfig('command');
     $config->setHandler($handler);
     $command = new Command($config, $this->application);
     $handler->expects($this->never())->method('handle');
     $this->assertSame(123, $command->handle($args, $io));
 }
Пример #11
0
 /**
  * {@inheritdoc}
  */
 protected function getDefaultHelperSet()
 {
     return $this->adaptedApplication->getConfig()->getHelperSet();
 }
Пример #12
0
 private function getPageName(Application $application, Args $args)
 {
     if ($args->isArgumentSet('command')) {
         $command = $application->getCommand($args->getArgument('command'));
         return $this->commandPagePrefix . $command->getName();
     }
     if ($this->applicationPage) {
         return $this->applicationPage;
     }
     return $application->getConfig()->getName();
 }