Пример #1
1
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     list($value, $reflector) = $this->getTargetAndReflector($input->getArgument('value'));
     $doc = $this->getManualDoc($reflector) ?: DocblockFormatter::format($reflector);
     $output->page(function ($output) use($reflector, $doc) {
         $output->writeln(SignatureFormatter::format($reflector));
         if (empty($doc) && !$this->getApplication()->getManualDb()) {
             $output->writeln('');
             $output->writeln('<warning>PHP manual not found</warning>');
             $output->writeln('    To document core PHP functionality, download the PHP reference manual:');
             $output->writeln('    https://github.com/bobthecow/psysh#downloading-the-manual');
         } else {
             $output->writeln('');
             $output->writeln($doc);
         }
     });
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($this->command !== null) {
         // help for an individual command
         $output->page($this->command->asText());
         $this->command = null;
     } elseif ($name = $input->getArgument('command_name')) {
         // help for an individual command
         $output->page($this->getApplication()->get($name)->asText());
     } else {
         // list available commands
         $commands = $this->getApplication()->all();
         $table = $this->getTable($output);
         foreach ($commands as $name => $command) {
             if ($name !== $command->getName()) {
                 continue;
             }
             if ($command->getAliases()) {
                 $aliases = sprintf('<comment>Aliases:</comment> %s', implode(', ', $command->getAliases()));
             } else {
                 $aliases = '';
             }
             $table->addRow(array(sprintf('<info>%s</info>', $name), $command->getDescription(), $aliases));
         }
         $output->startPaging();
         if ($table instanceof TableHelper) {
             $table->render($output);
         } else {
             $table->render();
         }
         $output->stopPaging();
     }
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($this->command !== NULL) {
         // Help for an individual command.
         $output->page($this->command->asText());
         $this->command = NULL;
     } elseif ($name = $input->getArgument('command_name')) {
         // Help for an individual command.
         $output->page($this->getApplication()->get($name)->asText());
     } else {
         $categories = [];
         // List available commands.
         $commands = $this->getApplication()->all();
         // Find the alignment width.
         $width = 0;
         foreach ($commands as $command) {
             $width = strlen($command->getName()) > $width ? strlen($command->getName()) : $width;
         }
         $width += 2;
         foreach ($commands as $name => $command) {
             if ($name !== $command->getName()) {
                 continue;
             }
             if ($command->getAliases()) {
                 $aliases = sprintf('  <comment>Aliases:</comment> %s', implode(', ', $command->getAliases()));
             } else {
                 $aliases = '';
             }
             if ($command instanceof DrushCommand) {
                 $category = (string) $command->getCategory();
             } else {
                 $category = static::PSYSH_CATEGORY;
             }
             if (!isset($categories[$category])) {
                 $categories[$category] = [];
             }
             $categories[$category][] = sprintf("    <info>%-{$width}s</info> %s%s", $name, $command->getDescription(), $aliases);
         }
         $messages = [];
         foreach ($categories as $name => $category) {
             $messages[] = '';
             $messages[] = sprintf('<comment>%s</comment>', OutputFormatter::escape($name));
             foreach ($category as $message) {
                 $messages[] = $message;
             }
         }
         $output->page($messages);
     }
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     list($value, $reflector) = $this->getTargetAndReflector($input->getArgument('value'));
     $output->page(function (ShellOutput $output) use($reflector) {
         $output->writeln(SignatureFormatter::format($reflector));
         $output->writeln(CodeFormatter::format($reflector), ShellOutput::OUTPUT_RAW);
     });
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $incredulity = $input->getArgument('incredulity');
     if (strlen(preg_replace('/[\\?!]/', '', $incredulity))) {
         throw new \InvalidArgumentException('Incredulity must include only "?" and "!".');
     }
     $count = $input->getOption('verbose') ? PHP_INT_MAX : pow(2, max(0, strlen($incredulity) - 1));
     $output->page($this->getBacktrace($this->context->getLastException(), $count), ShellOutput::NUMBER_LINES | ShellOutput::OUTPUT_RAW);
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $info = $this->fileInfo();
     $num = $input->getOption('num');
     $colors = new ConsoleColor();
     $colors->addTheme('line_number', array('blue'));
     $highlighter = new Highlighter($colors);
     $contents = file_get_contents($info['file']);
     $output->page($highlighter->getCodeSnippet($contents, $info['line'], $num, $num), ShellOutput::OUTPUT_RAW);
 }
Пример #7
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $code = $input->getArgument('code');
     if (strpos('<?', $code) === false) {
         $code = '<?php ' . $code;
     }
     $depth = $input->getOption('depth');
     $nodes = $this->parse($code);
     $output->page($this->presenter->present($nodes, $depth));
 }
Пример #8
0
 /**
  *
  * {@inheritdoc}
  *
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     list($value, $reflector) = $this->getTargetAndReflector($input->getArgument('value'));
     try {
         $output->page(CodeFormatter::format($reflector), ShellOutput::OUTPUT_RAW);
     } catch (RuntimeException $e) {
         $output->writeln(SignatureFormatter::format($reflector));
         throw $e;
     }
 }
Пример #9
0
 /**
  * @param InputInterface $input
  * @param OutputInterface|\Psy\Output\ShellOutput $output
  *
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var \eZ\Publish\API\Repository\LocationService $locationService */
     $locationService = $this->getScopeVariable('locationService');
     $id = $input->getArgument('id');
     if ($input->getOption('remote-id')) {
         $location = $locationService->loadLocationByRemoteId($id);
     } else {
         $location = $locationService->loadLocation($id);
     }
     $output->page($this->presenter->present($location, 10, true, Presenter::VERBOSE));
 }
Пример #10
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $code = $input->getArgument('code');
     if (strpos('<?', $code) === false) {
         $code = '<?php ' . $code;
     }
     $walker = $this->getWalker();
     $nodes = $this->parse($code);
     $depth = $input->getOption('depth');
     $output->page(function (ShellOutput $output) use(&$walker, $nodes, $depth) {
         $out = Inspector::export($nodes, $depth);
         $walker($output, $out);
     });
 }
Пример #11
0
 /**
  * @param InputInterface $input
  * @param OutputInterface|\Psy\Output\ShellOutput $output
  *
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var \eZ\Publish\API\Repository\Repository $repository */
     $repository = $this->getScopeVariable('repository');
     $contentService = $repository->getContentService();
     $id = $input->getArgument('id');
     if ($input->getOption('remote-id')) {
         $method = $input->getOption('all') ? 'loadContentByRemoteId' : 'loadContentInfoByRemoteId';
         $content = $contentService->{$method}($id);
     } else {
         $method = $input->getOption('all') ? 'loadContent' : 'loadContentInfo';
         $content = $contentService->{$method}($id);
     }
     $output->page($this->presenter->present($content, 10, true, Presenter::VERBOSE));
 }
Пример #12
0
 /**
  *
  * {@inheritdoc}
  *
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->validateOnlyOne($input, array('show', 'head', 'tail'));
     $this->validateOnlyOne($input, array('save', 'replay', 'clear'));
     $history = $this->getHistorySlice($input->getOption('show'), $input->getOption('head'), $input->getOption('tail'));
     $highlighted = false;
     $invert = $input->getOption('invert');
     $insensitive = $input->getOption('insensitive');
     if ($pattern = $input->getOption('grep')) {
         if (substr($pattern, 0, 1) !== '/' || substr($pattern, -1) !== '/' || strlen($pattern) < 3) {
             $pattern = '/' . preg_quote($pattern, '/') . '/';
         }
         if ($insensitive) {
             $pattern .= 'i';
         }
         $this->validateRegex($pattern);
         $matches = array();
         $highlighted = array();
         foreach ($history as $i => $line) {
             if (preg_match($pattern, $line, $matches) xor $invert) {
                 if (!$invert) {
                     $chunks = explode($matches[0], $history[$i]);
                     $chunks = array_map(array(__CLASS__, 'escape'), $chunks);
                     $glue = sprintf('<urgent>%s</urgent>', self::escape($matches[0]));
                     $highlighted[$i] = implode($glue, $chunks);
                 }
             } else {
                 unset($history[$i]);
             }
         }
     } elseif ($invert) {
         throw new \InvalidArgumentException('Cannot use -v without --grep.');
     } elseif ($insensitive) {
         throw new \InvalidArgumentException('Cannot use -i without --grep.');
     }
     if ($save = $input->getOption('save')) {
         $output->writeln(sprintf('Saving history in %s...', $save));
         file_put_contents($save, implode(PHP_EOL, $history) . PHP_EOL);
         $output->writeln('<info>History saved.</info>');
     } elseif ($input->getOption('replay')) {
         if (!($input->getOption('show') || $input->getOption('head') || $input->getOption('tail'))) {
             throw new \InvalidArgumentException('You must limit history via --head, --tail or --show before replaying.');
         }
         $count = count($history);
         $output->writeln(sprintf('Replaying %d line%s of history', $count, $count !== 1 ? 's' : ''));
         $this->getApplication()->addInput($history);
     } elseif ($input->getOption('clear')) {
         $this->clearHistory();
         $output->writeln('<info>History cleared.</info>');
     } else {
         $type = $input->getOption('no-numbers') ? 0 : ShellOutput::NUMBER_LINES;
         if (!$highlighted) {
             $type = $type | ShellOutput::OUTPUT_RAW;
         }
         $output->page($highlighted ?: $history, $type);
     }
 }
Пример #13
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $incredulity = implode('', $input->getArgument('incredulity'));
     if (strlen(preg_replace('/[\\?!]/', '', $incredulity))) {
         throw new \InvalidArgumentException('Incredulity must include only "?" and "!".');
     }
     $exception = $this->context->getLastException();
     $count = $input->getOption('verbose') ? PHP_INT_MAX : pow(2, max(0, strlen($incredulity) - 1));
     $trace = $this->getBacktrace($exception, $count);
     $shell = $this->getApplication();
     $output->page(function ($output) use($exception, $trace, $shell) {
         $shell->renderException($exception, $output);
         $output->writeln('--');
         $output->write($trace, true, ShellOutput::NUMBER_LINES);
     });
 }
Пример #14
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $trace = $this->getBacktrace(new \Exception(), $input->getOption('num'), $input->getOption('include-psy'));
     $output->page($trace, ShellOutput::NUMBER_LINES);
 }
Пример #15
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $args = $input->getArguments();
     $first = array_shift($args);
     // If the first argument is an alias, assign the next argument as the
     // command.
     if (strpos($first, '@') === 0) {
         $alias = $first;
         $command = array_shift($args);
     } else {
         $alias = '@self';
         $command = $first;
     }
     $options = $input->getOptions();
     // Force the 'backend' option to TRUE.
     $options['backend'] = TRUE;
     $return = drush_invoke_process($alias, $command, array_values($args), $options, ['interactive' => TRUE]);
     if ($return['error_status'] > 0) {
         foreach ($return['error_log'] as $error_type => $errors) {
             $output->write($errors);
         }
         // Add a newline after so the shell returns on a new line.
         $output->writeln('');
     } else {
         $output->page(drush_backend_get_result());
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $info = $this->fileInfo();
     $num = $input->getOption('num');
     $factory = new ConsoleColorFactory($this->colorMode);
     $colors = $factory->getConsoleColor();
     $highlighter = new Highlighter($colors);
     $contents = file_get_contents($info['file']);
     $output->page($highlighter->getCodeSnippet($contents, $info['line'], $num, $num), ShellOutput::OUTPUT_RAW);
 }
Пример #17
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $depth = $input->getOption('depth');
     $target = $this->resolveTarget($input->getArgument('target'));
     $output->page($this->presenter->present($target, $depth, $input->getOption('all') ? Presenter::VERBOSE : 0));
 }
Пример #18
-1
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($this->command !== null) {
         // help for an individual command
         $output->page($this->command->asText());
         $this->command = null;
     } elseif ($name = $input->getArgument('command_name')) {
         // help for an individual command
         $output->page($this->getApplication()->get($name)->asText());
     } else {
         // list available commands
         $commands = $this->getApplication()->all();
         $width = 0;
         foreach ($commands as $command) {
             $width = strlen($command->getName()) > $width ? strlen($command->getName()) : $width;
         }
         $width += 2;
         foreach ($commands as $name => $command) {
             if ($name !== $command->getName()) {
                 continue;
             }
             if ($command->getAliases()) {
                 $aliases = sprintf('  <comment>Aliases:</comment> %s', implode(', ', $command->getAliases()));
             } else {
                 $aliases = '';
             }
             $messages[] = sprintf("  <info>%-{$width}s</info> %s%s", $name, $command->getDescription(), $aliases);
         }
         $output->page($messages);
     }
 }