|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package: chapi |
|
4
|
|
|
* |
|
5
|
|
|
* @author: msiebeneicher |
|
6
|
|
|
* @since: 2015-07-28 |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Chapi\Commands; |
|
11
|
|
|
|
|
12
|
|
|
use Chapi\BusinessCase\Comparison\JobComparisonInterface; |
|
13
|
|
|
use Chapi\Service\JobIndex\JobIndexServiceInterface; |
|
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
16
|
|
|
|
|
17
|
|
|
class StatusCommand extends AbstractCommand |
|
18
|
|
|
{ |
|
19
|
|
|
const LABEL_CHRONOS = 'chronos'; |
|
20
|
|
|
const LABEL_MARATHON = 'marathon'; |
|
21
|
|
|
|
|
22
|
|
|
/** @var JobIndexServiceInterface */ |
|
23
|
|
|
private $oJobIndexService; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Configures the current command. |
|
27
|
|
|
*/ |
|
28
|
|
|
protected function configure() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->setName('status') |
|
31
|
|
|
->setDescription('Show the working tree status') |
|
32
|
|
|
; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @inheritdoc |
|
37
|
|
|
*/ |
|
38
|
|
|
protected function initialize(InputInterface $oInput, OutputInterface $oOutput) |
|
39
|
|
|
{ |
|
40
|
|
|
parent::initialize($oInput, $oOutput); |
|
41
|
|
|
|
|
42
|
|
|
$this->oJobIndexService = $this->getContainer()->get(JobIndexServiceInterface::DIC_NAME); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return int |
|
47
|
|
|
*/ |
|
48
|
|
|
protected function process() |
|
49
|
|
|
{ |
|
50
|
|
|
$_aChangedJobs = $this->getChangedAppJobs(); |
|
51
|
|
|
|
|
52
|
|
|
// tracked jobs |
|
53
|
|
|
$this->oOutput->writeln("\nChanges to be committed"); |
|
54
|
|
|
$this->oOutput->writeln(" (use 'chapi reset <job>...' to unstage)"); |
|
55
|
|
|
$this->oOutput->writeln(''); |
|
56
|
|
|
|
|
57
|
|
|
$this->printStatusView($_aChangedJobs, true); |
|
58
|
|
|
|
|
59
|
|
|
// untracked jobs |
|
60
|
|
|
$this->oOutput->writeln("\nChanges not staged for commit"); |
|
61
|
|
|
$this->oOutput->writeln(" (use 'chapi add <job>...' to update what will be committed)"); |
|
62
|
|
|
$this->oOutput->writeln(" (use 'chapi checkout <job>...' to discard changes in local repository)"); |
|
63
|
|
|
$this->oOutput->writeln(''); |
|
64
|
|
|
|
|
65
|
|
|
$this->printStatusView($_aChangedJobs, false); |
|
66
|
|
|
|
|
67
|
|
|
return 0; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return array<string,array<string,array>> |
|
|
|
|
|
|
72
|
|
|
*/ |
|
73
|
|
|
private function getChangedAppJobs() |
|
74
|
|
|
{ |
|
75
|
|
|
/** @var JobComparisonInterface $_oJobComparisonBusinessCaseChronos */ |
|
76
|
|
|
/** @var JobComparisonInterface $_oJobComparisonBusinessCaseMarathon */ |
|
77
|
|
|
$_oJobComparisonBusinessCaseChronos = $this->getContainer()->get(JobComparisonInterface::DIC_NAME_CHRONOS); |
|
78
|
|
|
$_oJobComparisonBusinessCaseMarathon = $this->getContainer()->get(JobComparisonInterface::DIC_NAME_MARATHON); |
|
79
|
|
|
|
|
80
|
|
|
$_aResult = [ |
|
81
|
|
|
'new' => [ |
|
82
|
|
|
self::LABEL_CHRONOS => $_oJobComparisonBusinessCaseChronos->getRemoteMissingJobs(), |
|
83
|
|
|
self::LABEL_MARATHON => $_oJobComparisonBusinessCaseMarathon->getRemoteMissingJobs(), |
|
84
|
|
|
], |
|
85
|
|
|
'missing' => [ |
|
86
|
|
|
self::LABEL_CHRONOS => $_oJobComparisonBusinessCaseChronos->getLocalMissingJobs(), |
|
87
|
|
|
self::LABEL_MARATHON => $_oJobComparisonBusinessCaseMarathon->getLocalMissingJobs(), |
|
88
|
|
|
], |
|
89
|
|
|
'updates' => [ |
|
90
|
|
|
self::LABEL_CHRONOS => $_oJobComparisonBusinessCaseChronos->getLocalJobUpdates(), |
|
91
|
|
|
self::LABEL_MARATHON => $_oJobComparisonBusinessCaseMarathon->getLocalJobUpdates(), |
|
92
|
|
|
], |
|
93
|
|
|
]; |
|
94
|
|
|
|
|
95
|
|
|
return $_aResult; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @param array $aChangedJobs |
|
100
|
|
|
* @param bool $bFilterIsInIndex |
|
101
|
|
|
*/ |
|
102
|
|
|
private function printStatusView($aChangedJobs, $bFilterIsInIndex) |
|
103
|
|
|
{ |
|
104
|
|
|
$_aFormatMap = [ |
|
105
|
|
|
'new' => ['title' => 'New jobs in local repository', 'format' => "\t<comment>new %s job:\t%s</comment>"], |
|
106
|
|
|
'missing' => ['title' => 'Missing jobs in local repository', 'format' => "\t<fg=red>delete %s job:\t%s</>"], |
|
107
|
|
|
'updates' => ['title' => 'Updated jobs in local repository', 'format' => "\t<info>modified %s job:\t%s</info>"] |
|
108
|
|
|
]; |
|
109
|
|
|
|
|
110
|
|
|
foreach ($aChangedJobs as $_sJobStatus => $_aJobList) |
|
111
|
|
|
{ |
|
112
|
|
|
$_aFilteredJobList = $this->filterJobListWithIndex($_aJobList, $bFilterIsInIndex); |
|
113
|
|
|
if (!empty($_aFilteredJobList)) |
|
114
|
|
|
{ |
|
115
|
|
|
$this->printJobList($_aFormatMap[$_sJobStatus]['title'], $_aFilteredJobList, $_aFormatMap[$_sJobStatus]['format']); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @param array $aJobLists |
|
122
|
|
|
* @param bool $bFilterIsInIndex |
|
123
|
|
|
* @return array |
|
124
|
|
|
*/ |
|
125
|
|
|
private function filterJobListWithIndex($aJobLists, $bFilterIsInIndex) |
|
126
|
|
|
{ |
|
127
|
|
|
$_aFilteredJobList = []; |
|
128
|
|
|
|
|
129
|
|
|
foreach ($aJobLists as $sAppLabel => $aJobList) |
|
130
|
|
|
{ |
|
131
|
|
|
foreach ($aJobList as $_sJobName) |
|
132
|
|
|
{ |
|
133
|
|
|
if ($bFilterIsInIndex == $this->oJobIndexService->isJobInIndex($_sJobName)) |
|
134
|
|
|
{ |
|
135
|
|
|
$_aFilteredJobList[$sAppLabel][] = $_sJobName; |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
return $_aFilteredJobList; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* @param string $sTitle |
|
145
|
|
|
* @param array $aJobLists |
|
146
|
|
|
* @param string $sListFormat |
|
147
|
|
|
*/ |
|
148
|
|
|
private function printJobList($sTitle, $aJobLists, $sListFormat) |
|
149
|
|
|
{ |
|
150
|
|
|
$this->oOutput->writeln(sprintf(' %s:', $sTitle)); |
|
151
|
|
|
|
|
152
|
|
|
foreach ($aJobLists as $sLabel => $aJobList) |
|
153
|
|
|
{ |
|
154
|
|
|
foreach ($aJobList as $_sJobName) |
|
155
|
|
|
{ |
|
156
|
|
|
$this->oOutput->writeln( |
|
157
|
|
|
sprintf($sListFormat, $sLabel, $_sJobName) |
|
158
|
|
|
); |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
$this->oOutput->writeln("\n"); |
|
163
|
|
|
} |
|
164
|
|
|
} |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.