DocsPublishCommand.php 1.44 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
<?php

namespace AppBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

11
class DocsPublishCommand extends ContainerAwareCommand {
12

13 14 15
  protected function configure() {
    $this
      ->setName('docs:publish')
16
      ->setDescription('Publish one or more books')
17
      ->addArgument(
18
          'identifiers',
19
          InputArgument::IS_ARRAY,
20 21 22 23 24
          'One or more book identifiers (e.g. "user/en/master"). Partial '
          . 'identifiers are acceptable (e.g. "user/en" will publish all '
          . 'English versions of the User Guide. If no identifiers are '
          . 'specified, then all versions of all languages in all books will '
          . 'be published.');
25
  }
26

27 28 29
  protected function execute(InputInterface $input, OutputInterface $output) {
    /** @var \AppBundle\Utils\Publisher $publisher */
    $publisher = $this->getContainer()->get('publisher');
30
    $identifiers = $input->getArgument('identifiers');
31 32 33
    if ($identifiers) {
      foreach ($identifiers as $identifier) {
        $publisher->publish($identifier);
34
      }
35 36 37 38 39 40
    }
    else {
      $publisher->publish();
    }
    foreach ($publisher->getMessages() as $message) {
      $output->writeln($message['label'] . ': ' . $message['content']);
41
    }
42
  }
43 44

}