Skip to content

Commit 8e195f9

Browse files
Add run config and custom settings
Fixes issue #301
1 parent 89a2ebc commit 8e195f9

3 files changed

Lines changed: 114 additions & 4 deletions

File tree

src/Runner/Config/Reader.php

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ private function displaySettings(): void
143143
$this->io->write(' - <fg=cyan>Git directory:</fg=cyan> ' . $this->config->getGitDirectory());
144144
$this->io->write(' - <fg=cyan>Bootstrap file:</fg=cyan> ' . $this->config->getBootstrap());
145145
$this->io->write(' - <fg=cyan>Install mode:</fg=cyan> ' . $this->config->getRunConfig()->getMode());
146+
147+
$this->displayCustomSettings();
148+
$this->displayRunSettings();
149+
$this->displayPluginSettings();
146150
}
147151

148152
/**
@@ -207,10 +211,11 @@ private function displayAction(Config\Action $action): void
207211
/**
208212
* Display all options
209213
*
210-
* @param \CaptainHook\App\Config\Options $options
214+
* @param \CaptainHook\App\Config\Options $options
215+
* @param string $prefix
211216
* @return void
212217
*/
213-
private function displayOptions(Config\Options $options): void
218+
private function displayOptions(Config\Options $options, string $prefix = ''): void
214219
{
215220
if (empty($options->getAll())) {
216221
return;
@@ -219,9 +224,9 @@ private function displayOptions(Config\Options $options): void
219224
return;
220225
}
221226

222-
$this->io->write(' <comment>Options:</comment>');
227+
$this->io->write($prefix . ' <comment>Options:</comment>');
223228
foreach ($options->getAll() as $key => $value) {
224-
$this->displayOption($key, $value);
229+
$this->displayOption($key, $value, $prefix);
225230
}
226231
}
227232

@@ -357,4 +362,54 @@ private function yesOrNo(bool $bool): string
357362
{
358363
return $bool ? '' : '';
359364
}
365+
366+
/**
367+
* Display custom config settings
368+
*
369+
* @return void
370+
*/
371+
private function displayCustomSettings(): void
372+
{
373+
if (count($this->config->getCustomSettings()) === 0) {
374+
return;
375+
}
376+
377+
$this->io->write(' <fg=yellow>Custom Settings:</>');
378+
foreach ($this->config->getCustomSettings() as $key => $value) {
379+
$this->io->write(' - <fg=cyan>' . $key . '</>: ' . $value);
380+
}
381+
}
382+
383+
/**
384+
* Display run config settings
385+
*
386+
* @return void
387+
*/
388+
private function displayRunSettings(): void
389+
{
390+
$runConfig = $this->config->getRunConfig();
391+
$this->io->write(' <fg=yellow>Run Settings:</>');
392+
$this->io->write(' - <fg=cyan>mode</>: ' . $runConfig->getMode());
393+
$this->io->write(' - <fg=cyan>docker-command</>: ' . $runConfig->getDockerCommand());
394+
$this->io->write(' - <fg=cyan>path-captain</>: ' . $runConfig->getCaptainsPath());
395+
$this->io->write(' - <fg=cyan>path-git</>: ' . $runConfig->getGitPath());
396+
}
397+
398+
/**
399+
* Display plugin settings
400+
*
401+
* @return void
402+
*/
403+
private function displayPluginSettings(): void
404+
{
405+
$plugins = $this->config->getPlugins();
406+
if (count($plugins) === 0) {
407+
return;
408+
}
409+
$this->io->write(' <fg=magenta>Plugins:</>');
410+
foreach ($plugins as $plugin) {
411+
$this->io->write(' - <fg=cyan>' . $plugin->getPlugin() . '</>');
412+
$this->displayOptions($plugin->getOptions(), ' ');
413+
}
414+
}
360415
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"config": {
3+
"plugins": [
4+
{
5+
"plugin": "\\CaptainHook\\App\\Plugin\\DummyPlugin",
6+
"options": {"foo": "bar"}
7+
}
8+
],
9+
"custom": {
10+
"foo": "bar",
11+
"fiz": "baz"
12+
}
13+
},
14+
"prepare-commit-msg": {
15+
"enabled": true,
16+
"actions": []
17+
},
18+
"commit-msg": {
19+
"enabled": true,
20+
"actions": []
21+
},
22+
"pre-commit": {
23+
"enabled": true,
24+
"actions": [
25+
{
26+
"action": "phpunit --configuration=build/phpunit-hook.xml",
27+
"config": {
28+
"label": "PHPUnit",
29+
"allow-failure": true
30+
},
31+
"options": {}
32+
}
33+
]
34+
},
35+
"pre-push": {
36+
"enabled": false,
37+
"actions": []
38+
}
39+
}

tests/unit/Runner/Config/ReaderTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@ public function testDoesNotAllowInvalidHookNames(): void
5151
->run();
5252
}
5353

54+
public function testItDisplaysApplicationConfig(): void
55+
{
56+
$path = realpath(CH_PATH_FILES . '/config/valid-with-plugins.json');
57+
$config = Config\Factory::create($path);
58+
$io = $this->createIOMock();
59+
$repo = $this->createRepositoryMock();
60+
61+
$io->expects($this->atLeast(2))->method('write');
62+
63+
$runner = new Reader($io, $config, $repo);
64+
$runner->setHook('pre-commit')
65+
->display(Reader::OPT_ACTIONS, true)
66+
->display(Reader::OPT_SETTINGS, true)
67+
->run();
68+
}
69+
5470
public function testItDisplaysActionConfig(): void
5571
{
5672
$path = realpath(CH_PATH_FILES . '/config/valid.json');

0 commit comments

Comments
 (0)