This class is used to execute "man" and "less".
Since: 1.0
Author: Bernhard Schussek (bschussek@gmail.com)
Example #1
0
 /**
  * {@inheritdoc}
  */
 public function handle()
 {
     if (!$this->processLauncher->isSupported()) {
         throw new RuntimeException('The ProcessLauncher must be supported for the man help to run.');
     }
     if (!$this->manBinary) {
         $this->manBinary = $this->executableFinder->find('man');
     }
     if (!$this->manBinary) {
         throw new RuntimeException('The "man" binary was not found.');
     }
     return $this->processLauncher->launchProcess(escapeshellcmd($this->manBinary) . ' -l %path%', array('path' => $this->path), false);
 }
 public function testLaunchWithError()
 {
     if (!$this->php) {
         $this->markTestSkipped('The "bash" binary is not available.');
         return;
     }
     if (!function_exists('proc_open')) {
         $this->markTestSkipped('The "proc_open" function is not available.');
         return;
     }
     $status = $this->launcher->launchProcess($this->php . ' -r %command%', array('command' => 'exit(123);'));
     $this->assertSame(123, $status);
 }
 /**
  * {@inheritdoc}
  */
 public function handle(Args $args, IO $io)
 {
     if ($this->processLauncher->isSupported()) {
         if (!$this->lessBinary) {
             $this->lessBinary = $this->executableFinder->find('less');
         }
         if ($this->lessBinary) {
             return $this->processLauncher->launchProcess(escapeshellcmd($this->lessBinary) . ' %path%', array('path' => $this->path), false);
         }
     }
     $io->write(file_get_contents($this->path));
     return 0;
 }
 public function testHandleWithCustomLessBinary()
 {
     $this->processLauncher->expects($this->once())->method('isSupported')->will($this->returnValue(true));
     $this->executableFinder->expects($this->never())->method('find');
     $this->processLauncher->expects($this->once())->method('launchProcess')->with('my-less %path%', array('path' => $this->path), false)->will($this->returnValue(123));
     $this->handler->setLessBinary('my-less');
     $status = $this->handler->handle($this->args, $this->io, $this->command);
     $this->assertSame(123, $status);
 }
Example #5
0
    public function testHelpPrintsTextIfAsciiDocNotFound()
    {
        $args = $this->helpCommand->parseArgs(new StringArgs('--help'));
        $this->processLauncher->expects($this->any())->method('isSupported')->will($this->returnValue(true));
        $this->executableFinder->expects($this->never())->method('find');
        $this->processLauncher->expects($this->never())->method('launchProcess');
        $this->handler->setApplicationPage('foobar');
        $status = $this->handler->handle($args, $this->io, $this->command);
        $expected = <<<'EOF'
The Application version 1.2.3

USAGE
  the-app
EOF;
        $this->assertStringStartsWith($expected, $this->io->fetchOutput());
        $this->assertSame(0, $status);
    }
Example #6
0
 /**
  * Callback for selecting the handler that should be run.
  *
  * @param Args    $args    The console arguments.
  * @param IO      $io      The I/O.
  * @param Command $command The handled command.
  *
  * @return string The name of the handler to run.
  */
 public function getHandlerToRun(Args $args, IO $io, Command $command)
 {
     $rawArgs = $args->getRawArgs();
     // The raw arguments should always be available, but check anyway
     if (!$rawArgs) {
         return 'text';
     }
     // If "-h" is given, always print the short text usage
     if ($rawArgs->hasToken('-h')) {
         return 'text';
     }
     // Check if any of the options is set
     foreach ($this->getRegisteredNames() as $handlerName) {
         if ($rawArgs->hasToken('--' . $handlerName)) {
             return $handlerName;
         }
     }
     // No format option is set, "-h" is not set
     // If a command is given or if "--help" is set, display the manual
     if ($rawArgs->hasToken('--help')) {
         // Return "man" if the binary is available and the man page exists
         // The process launcher must be supported on the system
         $manPage = $this->getManPage($command->getApplication(), $args);
         if (file_exists($manPage) && $this->processLauncher->isSupported()) {
             if (!$this->manBinary) {
                 $this->manBinary = $this->executableFinder->find('man');
             }
             if ($this->manBinary) {
                 return 'man';
             }
         }
         // Return "ascii-doc" if the AsciiDoc page exists
         $asciiDocPage = $this->getAsciiDocPage($command->getApplication(), $args);
         if (file_exists($asciiDocPage)) {
             return 'ascii-doc';
         }
     }
     // No command, no option -> display command list as text
     return 'text';
 }