Exemplo n.º 1
0
 public function getApplicationDocument(Application $application, $namespace = null)
 {
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $dom->appendChild($rootXml = $dom->createElement('symfony'));
     if ($application->getName() !== 'UNKNOWN') {
         $rootXml->setAttribute('name', $application->getName());
         if ($application->getVersion() !== 'UNKNOWN') {
             $rootXml->setAttribute('version', $application->getVersion());
         }
     }
     $rootXml->appendChild($commandsXML = $dom->createElement('commands'));
     $description = new ApplicationDescription($application, $namespace);
     if ($namespace) {
         $commandsXML->setAttribute('namespace', $namespace);
     }
     foreach ($description->getCommands() as $command) {
         $this->appendDocument($commandsXML, $this->getCommandDocument($command));
     }
     if (!$namespace) {
         $rootXml->appendChild($namespacesXML = $dom->createElement('namespaces'));
         foreach ($description->getNamespaces() as $namespaceDescription) {
             $namespacesXML->appendChild($namespaceArrayXML = $dom->createElement('namespace'));
             $namespaceArrayXML->setAttribute('id', $namespaceDescription['id']);
             foreach ($namespaceDescription['commands'] as $name) {
                 $namespaceArrayXML->appendChild($commandXML = $dom->createElement('command'));
                 $commandXML->appendChild($dom->createTextNode($name));
             }
         }
     }
     return $dom;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $description = new ApplicationDescription($this->getApplication());
     $this->commandCollection->setItems($description->getCommands());
     $result = $this->bashCompletion->generateCompletionList($input->getArgument(self::INPUT_ARG_NAME));
     return $output->writeln($result);
 }
 /**
  * {@inheritdoc}
  */
 protected function describeApplication(Application $application, array $options = array())
 {
     $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
     $description = new ApplicationDescription($application, $describedNamespace);
     $commands = array();
     foreach ($description->getCommands() as $command) {
         $commands[] = $this->describeCommand($command, array('as_array' => true));
     }
     $data = $describedNamespace ? array('commands' => $commands, 'namespace' => $describedNamespace) : array('commands' => $commands, 'namespaces' => array_values($description->getNamespaces()));
     return $this->output($data, $options);
 }
 /**
  * @inheritdoc
  */
 protected function describeApplication(ConsoleApplication $application, array $options = array())
 {
     $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
     $description = new ApplicationDescription($application, $describedNamespace);
     if (isset($options['raw_text']) && $options['raw_text']) {
         $width = $this->getColumnWidth($description->getCommands());
         foreach ($description->getCommands() as $command) {
             $this->writeText(sprintf("%-{$width}s %s", $command->getName(), $command->getDescription()), $options);
             $this->writeText("\n");
         }
     } else {
         $width = $this->getColumnWidth($description->getCommands());
         $this->writeText($application->getHelp(), $options);
         $this->writeText("\n\n");
         if ($describedNamespace) {
             $this->writeText(sprintf("<comment>Available commands for the \"%s\" namespace:</comment>", $describedNamespace), $options);
         } else {
             $this->writeText('<comment>Available commands:</comment>', $options);
         }
         // add commands by namespace
         foreach ($description->getNamespaces() as $namespace) {
             if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
                 $this->writeText("\n");
                 $this->writeText('<comment>' . $namespace['id'] . '</comment>', $options);
             }
             foreach ($namespace['commands'] as $name) {
                 $command = $description->getCommand($name);
                 $aliases = $command->getAliases();
                 if ($aliases && in_array($name, $aliases)) {
                     // If the command is an alias, do not list it in the
                     // 'global' namespace. The aliases will be shown inline
                     // with the full command name.
                     continue;
                 }
                 if ($command instanceof PlatformCommand) {
                     $aliases = $command->getVisibleAliases();
                 }
                 // Colour local commands differently from remote ones.
                 $commandDescription = $command->getDescription();
                 if ($command instanceof PlatformCommand && !$command->isLocal()) {
                     $commandDescription = "<fg=cyan>{$commandDescription}</fg=cyan>";
                 }
                 $this->writeText("\n");
                 $this->writeText(sprintf("  %-{$width}s %s", "<info>{$name}</info>" . $this->formatAliases($aliases), $commandDescription), $options);
             }
         }
         $this->writeText("\n");
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function describeApplication(Application $application, array $options = array())
 {
     $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
     $description = new ApplicationDescription($application, $describedNamespace);
     $blocks = array($application->getName() . "\n" . str_repeat('=', strlen($application->getName())));
     foreach ($description->getNamespaces() as $namespace) {
         if (ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
             $blocks[] = '**' . $namespace['id'] . ':**';
         }
         $blocks[] = implode("\n", array_map(function ($commandName) {
             return '* ' . $commandName;
         }, $namespace['commands']));
     }
     foreach ($description->getCommands() as $command) {
         $blocks[] = $this->describeCommand($command);
     }
     return implode("\n\n", $blocks);
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 protected function describeApplication(Application $application, array $options = array())
 {
     $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
     $description = new ApplicationDescription($application, $describedNamespace);
     $commands = array();
     foreach ($description->getCommands() as $command) {
         $commands[] = $this->getCommandData($command);
     }
     $data = array();
     if ('UNKNOWN' !== $application->getName()) {
         $data['application']['name'] = $application->getName();
         if ('UNKNOWN' !== $application->getVersion()) {
             $data['application']['version'] = $application->getVersion();
         }
     }
     $data['commands'] = $commands;
     if ($describedNamespace) {
         $data['namespace'] = $describedNamespace;
     } else {
         $data['namespaces'] = array_values($description->getNamespaces());
     }
     $this->writeData($data, $options);
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 protected function describeApplication(Application $application, array $options = [])
 {
     $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
     $description = new ApplicationDescription($application, $describedNamespace);
     if (isset($options['raw_text']) && $options['raw_text']) {
         $width = $this->getColumnWidth($description->getCommands());
         foreach ($description->getCommands() as $command) {
             $this->writeText(sprintf("%-{$width}s %s", $command->getName(), $command->getDescription()), $options);
             $this->writeText("\n");
         }
     } else {
         if ('' != ($help = $application->getHelp())) {
             $this->writeText("{$help}\n\n", $options);
         }
         $this->writeText("<comment>Usage:</comment>\n", $options);
         $this->writeText("  command [options] [arguments]\n\n", $options);
         $this->describeInputDefinition(new InputDefinition($application->getDefinition()->getOptions()), $options);
         $this->writeText("\n");
         $this->writeText("\n");
         $width = $this->getColumnWidth($description->getCommands());
         if ($describedNamespace) {
             $this->writeText(sprintf('<comment>Available commands for the "%s" namespace:</comment>', $describedNamespace), $options);
         } else {
             $this->writeText('<comment>Available commands:</comment>', $options);
         }
         // add commands by namespace
         foreach ($description->getNamespaces() as $namespace) {
             if ($this->shouldListCommand($namespace['id']) === false) {
                 continue;
             }
             if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
                 $this->writeText("\n");
                 $this->writeText(' <comment>' . $namespace['id'] . '</comment>', $options);
             }
             foreach ($namespace['commands'] as $name) {
                 if ($this->shouldListCommand($namespace['id'], $name) === false) {
                     continue;
                 }
                 $this->writeText("\n");
                 $spacingWidth = $width - strlen($name);
                 $this->writeText(sprintf('  <info>%s</info>%s%s', $name, str_repeat(' ', $spacingWidth), $description->getCommand($name)->getDescription()), $options);
             }
         }
         $this->writeText("\n");
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function describeApplication(Application $application, array $options = array())
 {
     $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
     $description = new ApplicationDescription($application, $describedNamespace);
     if (isset($options['raw_text']) && $options['raw_text']) {
         $width = $this->getColumnWidth($description->getCommands());
         foreach ($description->getCommands() as $command) {
             $this->writeText(sprintf("%-{$width}s %s", $command->getName(), $command->getDescription()), $options);
             $this->writeText("\n");
         }
     } else {
         if ('' != ($help = $application->getHelp())) {
             $this->writeText("{$help}\n\n", $options);
         }
         $this->describeInputDefinition(new InputDefinition($application->getDefinition()->getOptions()), $options);
         $this->writeText("\n");
         $this->writeText("\n");
         $width = $this->getColumnWidth($description->getCommands());
         if ($describedNamespace) {
             $this->writeText(sprintf('<comment>Available commands for the "%s" namespace:</comment>', $describedNamespace), $options);
         } else {
             $this->writeText('<comment>Available commands:</comment>', $options);
         }
         // add commands by namespace
         foreach ($description->getNamespaces() as $namespace) {
             if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
                 $this->writeText("\n");
                 $this->writeText(' <comment>' . $namespace['id'] . '</comment>', $options);
             }
             foreach ($namespace['commands'] as $name) {
                 $command = $description->getCommand($name);
                 $aliases = $command->getAliases();
                 if ($aliases && in_array($name, $aliases)) {
                     // skip aliases
                     continue;
                 }
                 $this->writeText("\n");
                 $this->writeText(sprintf("  %-{$width}s %s", "<info>{$name}</info>" . $this->formatAliases($aliases), $command->getDescription()), $options);
             }
         }
         $this->writeText("\n");
     }
 }
Exemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 protected function describeApplication(Application $application, array $options = array())
 {
     $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
     $description = new ApplicationDescription($application, $describedNamespace);
     if (isset($options['raw_text']) && $options['raw_text']) {
         $width = $this->getColumnWidth($description->getCommands());
         foreach ($description->getCommands() as $command) {
             $this->writeText(sprintf("%-{$width}s %s", $command->getName(), $command->getDescription()), $options);
             $this->writeText("\n");
         }
     } else {
         if ('' != ($help = $application->getHelp())) {
             $this->writeText("{$help}\n\n", $options);
         }
         $this->writeText($application->trans('commands.list.messages.usage'), $options);
         $this->writeText($application->trans('commands.list.messages.usage_details'), $options);
         $options['application'] = $application;
         $this->describeInputDefinition(new InputDefinition($application->getDefinition()->getOptions()), $options);
         $this->writeText("\n");
         $this->writeText("\n");
         $width = $this->getColumnWidth($description->getCommands());
         if ($describedNamespace) {
             $this->writeText(sprintf($application->trans('commands.list.messages.comment'), $describedNamespace), $options);
         } else {
             $this->writeText($application->trans('commands.list.messages.available-commands'), $options);
         }
         // add commands by namespace
         foreach ($description->getNamespaces() as $namespace) {
             if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
                 $this->writeText("\n");
                 $this->writeText(' <comment>' . $namespace['id'] . '</comment>', $options);
             }
             foreach ($namespace['commands'] as $name) {
                 $this->writeText("\n");
                 $spacingWidth = $width - strlen($name);
                 $this->writeText(sprintf('  <info>%s</info>%s%s', $name, str_repeat(' ', $spacingWidth), $description->getCommand($name)->getDescription()), $options);
             }
         }
         $this->writeText("\n");
     }
 }
Exemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 protected function describeApplication(Application $application, array $options = array())
 {
     $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
     $description = new ApplicationDescription($application, $describedNamespace);
     if (isset($options['raw_text']) && $options['raw_text']) {
         $width = $this->getColumnWidth($description->getCommands());
         foreach ($description->getCommands() as $command) {
             $this->writeText(sprintf("%-{$width}s %s", $command->getName(), $command->getDescription()), $options);
             $this->writeText("\n");
         }
     } else {
         if ('' != ($help = $application->getHelp())) {
             $this->writeText("{$help}\n\n", $options);
         }
         $this->writeText("<comment>Usage:</comment>\n", $options);
         $this->writeText(" [options] command [arguments]\n\n", $options);
         $this->writeText('<comment>Options:</comment>', $options);
         $inputOptions = $application->getDefinition()->getOptions();
         $width = 0;
         foreach ($inputOptions as $option) {
             $nameLength = strlen($option->getName()) + 2;
             if ($option->getShortcut()) {
                 $nameLength += strlen($option->getShortcut()) + 3;
             }
             $width = max($width, $nameLength);
         }
         ++$width;
         foreach ($inputOptions as $option) {
             $this->writeText("\n", $options);
             $this->describeInputOption($option, array_merge($options, array('name_width' => $width)));
         }
         $this->writeText("\n\n", $options);
         $width = $this->getColumnWidth($description->getCommands());
         if ($describedNamespace) {
             $this->writeText(sprintf("<comment>Available commands for the \"%s\" namespace:</comment>", $describedNamespace), $options);
         } else {
             $this->writeText('<comment>Available commands:</comment>', $options);
         }
         // add commands by namespace
         foreach ($description->getNamespaces() as $namespace) {
             if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
                 $this->writeText("\n");
                 $this->writeText('<comment>' . $namespace['id'] . '</comment>', $options);
             }
             foreach ($namespace['commands'] as $name) {
                 $this->writeText("\n");
                 $this->writeText(sprintf(" <info>%-{$width}s</info> %s", $name, $description->getCommand($name)->getDescription()), $options);
             }
         }
         $this->writeText("\n");
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function describeApplication(Application $application, array $options = array())
 {
     $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
     $description = new ApplicationDescription($application, $describedNamespace);
     if (isset($options['raw_text']) && $options['raw_text']) {
         $width = $this->getColumnWidth($description->getCommands());
         foreach ($description->getCommands() as $command) {
             $this->writeText(sprintf("%-{$width}s %s", $command->getName(), $command->getDescription()), $options);
             $this->writeText("\n");
         }
     } else {
         $width = $this->getColumnWidth($description->getCommands());
         $this->writeText($application->getHelp(), $options);
         $this->writeText("\n\n");
         if ($describedNamespace) {
             $this->writeText(sprintf("<comment>Available commands for the \"%s\" namespace:</comment>", $describedNamespace), $options);
         } else {
             $this->writeText('<comment>Available commands:</comment>', $options);
         }
         // add commands by namespace
         foreach ($description->getNamespaces() as $namespace) {
             if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
                 $this->writeText("\n");
                 $this->writeText('<comment>' . $namespace['id'] . '</comment>', $options);
             }
             foreach ($namespace['commands'] as $name) {
                 $this->writeText("\n");
                 $this->writeText(sprintf("  <info>%-{$width}s</info> %s", $name, $description->getCommand($name)->getDescription()), $options);
             }
         }
         $this->writeText("\n");
     }
 }
Exemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 protected function describeApplication(Application $application, array $options = array())
 {
     $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
     $description = new ApplicationDescription($application, $describedNamespace);
     $messages = array();
     if (isset($options['raw_text']) && $options['raw_text']) {
         $width = $this->getColumnWidth($description->getCommands());
         foreach ($description->getCommands() as $command) {
             $messages[] = sprintf("%-{$width}s %s", $command->getName(), $command->getDescription());
         }
     } else {
         $width = $this->getColumnWidth($description->getCommands());
         $messages[] = $application->getHelp();
         $messages[] = '';
         if ($describedNamespace) {
             $messages[] = sprintf("<comment>Available commands for the \"%s\" namespace:</comment>", $describedNamespace);
         } else {
             $messages[] = '<comment>Available commands:</comment>';
         }
         // add commands by namespace
         foreach ($description->getNamespaces() as $namespace) {
             if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
                 $messages[] = '<comment>' . $namespace['id'] . '</comment>';
             }
             foreach ($namespace['commands'] as $name) {
                 $messages[] = sprintf("  <info>%-{$width}s</info> %s", $name, $description->getCommand($name)->getDescription());
             }
         }
     }
     $output = implode("\n", $messages);
     return isset($options['raw_text']) && $options['raw_text'] ? strip_tags($output) : $output;
 }
Exemplo n.º 13
0
 protected function describeApplication(Application $application, array $options = array())
 {
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $dom->appendChild($rootXml = $dom->createElement('symfony'));
     $rootXml->appendChild($commandsXML = $dom->createElement('commands'));
     $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
     $description = new ApplicationDescription($application, $describedNamespace);
     if ($describedNamespace) {
         $commandsXML->setAttribute('namespace', $describedNamespace);
     }
     foreach ($description->getCommands() as $command) {
         $this->appendDocument($commandsXML, $this->describeCommand($command, array('as_dom' => true)));
     }
     if (!$describedNamespace) {
         $rootXml->appendChild($namespacesXML = $dom->createElement('namespaces'));
         foreach ($description->getNamespaces() as $namespace) {
             $namespacesXML->appendChild($namespaceArrayXML = $dom->createElement('namespace'));
             $namespaceArrayXML->setAttribute('id', $namespace['id']);
             foreach ($namespace['commands'] as $name) {
                 $namespaceArrayXML->appendChild($commandXML = $dom->createElement('command'));
                 $commandXML->appendChild($dom->createTextNode($name));
             }
         }
     }
     return $this->output($dom, $options);
 }
 /**
  * @inheritdoc
  */
 protected function describeApplication(ConsoleApplication $application, array $options = [])
 {
     $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
     $description = new ApplicationDescription($application, $describedNamespace);
     if (isset($options['raw_text']) && $options['raw_text']) {
         $width = $this->getColumnWidth($description->getCommands());
         foreach ($description->getCommands() as $command) {
             $this->writeText(sprintf("%-{$width}s %s", $command->getName(), $command->getDescription()), $options);
             $this->writeText("\n");
         }
     } else {
         $width = $this->getColumnWidth($description->getCommands());
         $this->writeText($application->getHelp(), $options);
         $this->writeText("\n\n");
         if ($describedNamespace) {
             $this->writeText(sprintf("<comment>Available commands for the \"%s\" namespace:</comment>", $describedNamespace), $options);
         } else {
             $this->writeText('<comment>Available commands:</comment>', $options);
         }
         // Display commands grouped by namespace.
         foreach ($description->getNamespaces() as $namespace) {
             // Filter hidden commands in the namespace.
             /** @var Command[] $commands */
             $commands = [];
             foreach ($namespace['commands'] as $name) {
                 $command = $description->getCommand($name);
                 if (!$describedNamespace && $command instanceof CanHideInListInterface && $command->hideInList()) {
                     continue;
                 }
                 $commands[$name] = $command;
             }
             // Skip the namespace if it doesn't contain any commands.
             if (!count($commands)) {
                 continue;
             }
             // Display the namespace name.
             if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
                 $this->writeText("\n");
                 $this->writeText('<comment>' . $namespace['id'] . '</comment>', $options);
             }
             // Display each command.
             foreach ($commands as $name => $command) {
                 $aliases = $command->getAliases();
                 if ($aliases && in_array($name, $aliases)) {
                     // If the command is an alias, do not list it in the
                     // 'global' namespace. The aliases will be shown inline
                     // with the full command name.
                     continue;
                 }
                 if ($command instanceof CommandBase) {
                     $aliases = $command->getVisibleAliases();
                 }
                 // Colour local commands differently from remote ones.
                 $commandDescription = $command->getDescription();
                 if ($command instanceof CommandBase && !$command->isLocal()) {
                     $commandDescription = "<fg=cyan>{$commandDescription}</fg=cyan>";
                 }
                 $this->writeText("\n");
                 $this->writeText(sprintf("  %-{$width}s %s", "<info>{$name}</info>" . $this->formatAliases($aliases), $commandDescription), $options);
             }
         }
         $this->writeText("\n");
     }
 }
Exemplo n.º 15
0
 /**
  * {@inheritdoc}
  */
 protected function describeApplication(Application $application, array $options = array())
 {
     $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
     $description = new ApplicationDescription($application, $describedNamespace);
     $this->write($application->getLongVersion() . "\n" . str_repeat('=', strlen($application->getLongVersion())));
     foreach ($description->getNamespaces() as $namespace) {
         if (ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
             $this->write("\n\n");
             $this->write('**' . $namespace['id'] . ':**');
         }
         $this->write("\n\n");
         $this->write(implode("\n", array_map(function ($commandName) {
             return '* `' . $commandName . '`';
         }, $namespace['commands'])));
     }
     foreach ($description->getCommands() as $command) {
         $this->write("\n\n");
         $this->write($this->describeCommand($command));
     }
 }