-
-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathDownloadDocsCommand.php
More file actions
63 lines (49 loc) · 1.95 KB
/
DownloadDocsCommand.php
File metadata and controls
63 lines (49 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
declare(strict_types=1);
namespace Safe\Commands;
use Safe\Filesystem\PathHelper;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressIndicator;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\Process;
final class DownloadDocsCommand extends Command
{
private SymfonyStyle $io;
private Filesystem $filesystem;
protected function configure(): void
{
$this
->setName('download-docs')
->setDescription('Download the recent version of the PHP documentation')
;
}
protected function initialize(InputInterface $input, OutputInterface $output): void
{
$this->io = new SymfonyStyle($input, $output);
$this->filesystem = new Filesystem();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->io->title($this->getDescription());
// Clean up before cloning.
$this->filesystem->remove(PathHelper::docsDirectory());
$this->filesystem->mkdir(PathHelper::docsDirectory());
$this->clone($output, 'php/doc-base');
$this->clone($output, 'php/doc-en');
return self::SUCCESS;
}
private function clone(OutputInterface $output, string $repository): void
{
$progressIndicator = new ProgressIndicator($output);
$progressIndicator->start(\sprintf('Cloning <info>%s</info>', $repository));
$process = new Process(['git', 'clone', \sprintf('https://github.com/%s', $repository), \sprintf('%s/%s', PathHelper::docsDirectory(), $repository)]);
$process->start();
while ($process->isRunning()) {
$progressIndicator->advance();
}
$progressIndicator->finish(\sprintf('Downloaded <info>%s</info>', $repository));
}
}