1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Code-Insight library. |
4
|
|
|
* For the full copyright and license information, please view |
5
|
|
|
* the LICENSE file that was distributed with this source code. |
6
|
|
|
* |
7
|
|
|
* @copyright Alexander Obuhovich <[email protected]> |
8
|
|
|
* @link https://github.com/console-helpers/code-insight |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace ConsoleHelpers\CodeInsight\Command; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use ConsoleHelpers\CodeInsight\KnowledgeBase\KnowledgeBaseFactory; |
15
|
|
|
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; |
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
18
|
|
|
use Symfony\Component\Console\Input\InputOption; |
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
20
|
|
|
|
21
|
|
|
class SyncCommand extends AbstractCommand |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Knowledge base factory. |
26
|
|
|
* |
27
|
|
|
* @var KnowledgeBaseFactory |
28
|
|
|
*/ |
29
|
|
|
private $_knowledgeBaseFactory; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
protected function configure() |
35
|
|
|
{ |
36
|
|
|
$this |
37
|
|
|
->setName('sync') |
38
|
|
|
->setDescription('Synchronizes collected information about code with actual code') |
39
|
|
|
->addArgument( |
40
|
|
|
'project-path', |
41
|
|
|
InputArgument::OPTIONAL, |
42
|
|
|
'Path to project root folder (where <comment>.code-insight.json</comment> is located)', |
43
|
|
|
'.' |
44
|
|
|
) |
45
|
|
|
->addOption( |
46
|
|
|
'project-fork', |
47
|
|
|
null, |
48
|
|
|
InputOption::VALUE_REQUIRED, |
49
|
|
|
'Project fork name' |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Prepare dependencies. |
55
|
|
|
* |
56
|
|
|
* @return void |
57
|
|
|
*/ |
58
|
|
|
protected function prepareDependencies() |
59
|
|
|
{ |
60
|
|
|
parent::prepareDependencies(); |
61
|
|
|
|
62
|
|
|
$container = $this->getContainer(); |
63
|
|
|
|
64
|
|
|
$this->_knowledgeBaseFactory = $container['knowledge_base_factory']; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Return possible values for the named option |
69
|
|
|
* |
70
|
|
|
* @param string $optionName Option name. |
71
|
|
|
* @param CompletionContext $context Completion context. |
72
|
|
|
* |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
|
|
public function completeOptionValues($optionName, CompletionContext $context) |
76
|
|
|
{ |
77
|
|
|
$ret = parent::completeOptionValues($optionName, $context); |
78
|
|
|
|
79
|
|
|
if ( $optionName === 'project-fork' ) { |
80
|
|
|
$input = $this->getInputFromCompletionContext($context); |
81
|
|
|
|
82
|
|
|
return $this->_knowledgeBaseFactory->getForks( |
83
|
|
|
$this->getPath($input->getArgument('project-path')) |
|
|
|
|
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return $ret; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* {@inheritdoc} |
92
|
|
|
*/ |
93
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
94
|
|
|
{ |
95
|
|
|
$knowledge_base = $this->_knowledgeBaseFactory->getKnowledgeBase( |
96
|
|
|
$this->getPath($this->io->getArgument('project-path')), |
|
|
|
|
97
|
|
|
$this->io->getOption('project-fork'), |
|
|
|
|
98
|
|
|
$this->io |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
$knowledge_base->refresh(); |
102
|
|
|
|
103
|
|
|
$this->io->writeln('Done.'); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
} |
107
|
|
|
|