Author: Victor Puertas (vpgugr@gmail.com)
Inheritance: implements Yosymfony\Spress\Core\IO\IOInterface
Example #1
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new ConsoleIO($input, $output, $this->getHelperSet());
     $io->write(['', $this->getSpressAsciiArt(), '', 'Hola user and welcome!', '', 'More information at <comment>http://spress.yosymfony.com</comment> or <comment>@spress_cms</comment> on Twitter', '']);
     if ($this->isUnstableVersion()) {
         $io->write(['', '<error>Warning: this is a unstable version.</error>', ``]);
     }
     $command = $this->getApplication()->find('list');
     $arguments = new ArrayInput(['command' => 'list']);
     $command->run($arguments, $output);
 }
Example #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $path = $input->getArgument('path');
     $template = $input->getArgument('template');
     $force = $input->getOption('force');
     $completeScaffold = $input->getOption('all');
     $io = new ConsoleIO($input, $output, $this->getHelperSet());
     $app = new SpressCLI($io);
     $operation = new NewSite($app['spress.paths']['templates']);
     $operation->newSite($path, $template, $force, $completeScaffold);
     $io->write(sprintf('<comment>New site created at %s.</comment>', $path));
     if ('./' == $path) {
         $io->write('<comment>Edit composer.json file to add your theme data and plugins required.</comment>');
     } else {
         $io->write(sprintf('<comment>Go to %s folder and edit composer.json file to add your theme data and plugins required.</comment>', $path));
     }
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new ConsoleIO($input, $output);
     if ($this->isInstalledAsPhar() === false) {
         $io->error('Self-update is available only for PHAR version');
         return 1;
     }
     $manifest = $this->getManifestFile();
     $remoteVersion = $manifest['version'];
     $localVersion = $this->getApplication()->getVersion();
     if ($localVersion === $remoteVersion) {
         $io->success('Spress is already up to date');
         return;
     }
     $remoteFilename = $manifest['url'];
     $localFilename = $_SERVER['argv'][0];
     $tempFilename = basename($localFilename, '.phar') . '-tmp.phar';
     $io->newLine();
     $io->write('Downloading Spress...');
     $io->newLine();
     $this->downloadRemoteFilename($remoteFilename);
     try {
         copy($remoteFilename, $tempFilename);
         chmod($tempFilename, 0777 & ~umask());
         $phar = new \Phar($tempFilename);
         unset($phar);
         if (@rename($tempFilename, $localFilename) !== true) {
             $io->error(sprintf('Cannot rename "%s" to "%s" probably because permission denied.', $tempFilename, $localFilename));
             return 1;
         }
         $io->success(sprintf('Spress updated from %s to %s.', $localVersion, $remoteVersion));
         if (isset($manifest['changelog_url']) === true) {
             $io->write(sprintf('<comment>Go to <info>%s</info> for more details.</comment>', $manifest['changelog_url']));
         }
     } catch (\Exception $e) {
         if ($e instanceof \UnexpectedValueException === false && $e instanceof \PharException === false) {
             throw $e;
         }
         unlink($tempFilename);
         $io->error([sprintf('The download is corrupt (%s).', $e->getMessage()), 'Please re-run the self-update command to try again.']);
         return 1;
     }
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new ConsoleIO($input, $output, $this->getHelperSet());
     if ($this->isInstalledAsPhar() === false) {
         $io->write('<error>Self-update is available only for PHAR version.</error>');
         return 1;
     }
     $manifest = $this->getManifestFile();
     $remoteVersion = $manifest['version'];
     $localVersion = $this->getApplication()->getVersion();
     if ($localVersion === $remoteVersion) {
         $io->write('<info>Spress is already up to date.</info>');
         return;
     }
     $remoteFilename = $manifest['url'];
     $localFilename = $_SERVER['argv'][0];
     $tempFilename = basename($localFilename, '.phar') . '-tmp.phar';
     $this->downloadRemoteFilename($remoteFilename);
     try {
         copy($remoteFilename, $tempFilename);
         chmod($tempFilename, 0777 & ~umask());
         $phar = new \Phar($tempFilename);
         unset($phar);
         rename($tempFilename, $localFilename);
         $io->write(sprintf('<success>Spress updated from %s to %s.</success>', $localVersion, $remoteVersion));
         if (isset($manifest['changelog_url']) === true) {
             $io->write(sprintf('<info>Go to %s for more details.</info>', $manifest['changelog_url']));
         }
     } catch (\Exception $e) {
         if ($e instanceof \UnexpectedValueException === false && $e instanceof \PharException === false) {
             throw $e;
         }
         unlink($tempFilename);
         $io->write(sprintf('<error>The download is corrupt (%s).</error>', $e->getMessage()));
         $io->write('<error>Please re-run the self-update command to try again.</error>');
         return 1;
     }
 }
Example #5
0
 /**
  * Writes the result of a parsing a site.
  *
  * @param \Yosymfony\Spress\IO\ConsoleIO                    $io
  * @param \Yosymfony\Spress\Core\DataSource\ItemInterface[] $items
  */
 protected function resultMessage(ConsoleIO $io, array $items)
 {
     $io->write(sprintf('<info>Total items: %d.</info>', count($items)));
 }
Example #6
0
 /**
  * Write the result of rebuilding a site.
  *
  * @param Yosymfony\Spress\IO\ConsoleIO $io
  * @param array                         $newResources
  * @param array                         $updatedResources
  * @param array                         $deletedResources
  */
 protected function rebuildingSiteMessage(ConsoleIO $io, array $newResources, array $updatedResources, array $deletedResources)
 {
     $io->write(sprintf('<comment>Rebuilding site... (%s new, %s updated and %s deleted resources)</comment>', count($newResources), count($updatedResources), count($deletedResources)));
     $io->newLine();
 }
Example #7
0
 public function testAskAndValidate()
 {
     $inputMock = $this->getMockBuilder('Symfony\\Component\\Console\\Input\\InputInterface')->getMock();
     $outputMock = $this->getMockBuilder('Symfony\\Component\\Console\\Output\\OutputInterface')->getMock();
     $questionHelperMock = $this->getMockBuilder('Symfony\\Component\\Console\\Helper\\QuestionHelper')->getMock();
     $helperMock = $this->getMockBuilder('Symfony\\Component\\Console\\Helper\\HelperSet')->getMock();
     $question = new \Symfony\Component\Console\Question\Question('Is valid?', true);
     $question->setMaxAttempts(10);
     $question->setValidator(function ($answer) {
         return $answer;
     });
     $questionHelperMock->expects($this->once())->method('ask')->with($this->isInstanceOf('Symfony\\Component\\Console\\Input\\InputInterface'), $this->isInstanceOf('Symfony\\Component\\Console\\Output\\OutputInterface'), $question);
     $helperMock->expects($this->once())->method('get')->with($this->equalTo('question'))->will($this->returnValue($questionHelperMock));
     $consoleIO = new ConsoleIO($inputMock, $outputMock, $helperMock);
     $consoleIO->askAndValidate('Is valid?', function ($answer) {
         return $answer;
     }, 10, true);
 }
Example #8
0
 public function testAskAndValidate()
 {
     $inputMock = $this->getMock('Symfony\\Component\\Console\\Input\\InputInterface');
     $outputMock = $this->getMock('Symfony\\Component\\Console\\Output\\OutputInterface');
     $dialogMock = $this->getMock('Symfony\\Component\\Console\\Helper\\DialogHelper');
     $helperMock = $this->getMock('Symfony\\Component\\Console\\Helper\\HelperSet');
     $dialogMock->expects($this->once())->method('askAndValidate')->with($this->isInstanceOf('Symfony\\Component\\Console\\Output\\OutputInterface'), $this->equalTo('Is valid?'), $this->callback(function ($validator) {
         return 'validator' === $validator();
     }), $this->equalTo(10), $this->equalTo('default'));
     $helperMock->expects($this->once())->method('get')->with($this->equalTo('dialog'))->will($this->returnValue($dialogMock));
     $consoleIO = new ConsoleIO($inputMock, $outputMock, $helperMock);
     $consoleIO->askAndValidate('Is valid?', function () {
         return 'validator';
     }, 10, 'default');
 }
Example #9
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $timezone = $input->getOption('timezone');
     $drafts = $input->getOption('drafts');
     $safe = $input->getOption('safe');
     $env = $input->getOption('env');
     $io = new ConsoleIO($input, $output, $this->getHelperSet());
     $app = new SpressCLI($io);
     $config = $app['spress.config'];
     $envDefault = $config->getEnvironmentName();
     $io->write('<comment>Starting...</comment>');
     $io->write(sprintf('<comment>Environment: %s.</comment>', $env ? $env : $envDefault));
     if ($drafts) {
         $io->write('<comment>Posts drafts activated.</comment>');
     }
     if ($safe) {
         $io->write('<comment>Plugins disabled.</comment>');
     }
     $resultData = $app->parse($input->getOption('source'), $env, $timezone, $drafts, $safe);
     $io->write(sprintf('Total posts: %d', $resultData['total_post']));
     $io->write(sprintf('Processed posts: %d', $resultData['processed_post']));
     $io->write(sprintf('Drafts post: %d', $resultData['drafts_post']));
     $io->write(sprintf('Total pages: %d', $resultData['total_pages']));
     $io->write(sprintf('Processed pages: %d', $resultData['processed_pages']));
     $io->write(sprintf('Other resources: %d', $resultData['other_resources']));
 }
Example #10
0
 public function testNewLine()
 {
     $this->command->setCode(function (InputInterface $input, OutputInterface $output) use(&$isDecorated) {
         $io = new ConsoleIO($input, $output);
         $io->newLine();
     });
     $this->tester->execute([], ['interactive' => false, 'decorated' => false]);
     $this->assertEquals("\n", $this->tester->getDisplay(true));
 }