|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Padawan\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Padawan\Domain\Project; |
|
6
|
|
|
use Padawan\Domain\ProjectRepository; |
|
7
|
|
|
use Padawan\Framework\Utils\PathResolver; |
|
8
|
|
|
use Padawan\Domain\Generator\IndexGenerator; |
|
9
|
|
|
use Padawan\Framework\Domain\Project\Persister; |
|
10
|
|
|
use Padawan\Framework\Domain\Project\InMemoryIndex; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
14
|
|
|
|
|
15
|
|
|
class GenerateCommand extends CliCommand |
|
16
|
|
|
{ |
|
17
|
|
|
protected function configure() |
|
18
|
|
|
{ |
|
19
|
|
|
$this->setName("generate") |
|
20
|
|
|
->setDescription("Generates new index for the project") |
|
21
|
|
|
->addArgument( |
|
22
|
|
|
"path", |
|
23
|
|
|
InputArgument::OPTIONAL, |
|
24
|
|
|
"Path to the project root. Default: current directory" |
|
25
|
|
|
); |
|
26
|
|
|
} |
|
27
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
28
|
|
|
{ |
|
29
|
|
|
$path = $input->getArgument("path"); |
|
30
|
|
|
/** @var PathResolver $pathResolver */ |
|
31
|
|
|
$pathResolver = $this->getContainer()->get(PathResolver::class); |
|
32
|
|
|
if (empty($path)) { |
|
33
|
|
|
$path = $pathResolver->getWorkingDirectory(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$projectRepository = $this->getContainer()->get(ProjectRepository::class); |
|
37
|
|
|
$project = $projectRepository->findByPath($path); |
|
38
|
|
|
$generator = $this->getContainer()->get(IndexGenerator::class); |
|
39
|
|
|
|
|
40
|
|
|
$generator->generateProjectIndex($project); |
|
41
|
|
|
$persister = $this->getContainer()->get(Persister::class); |
|
42
|
|
|
|
|
43
|
|
|
$persister->save($project); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|