Skip to content

Commit 968ab4a

Browse files
Improved output
Especially for verbose and debug scenarios the output is now more readable.
1 parent 8a6139b commit 968ab4a

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

src/Console/Command/Hook.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,7 @@ private function handleBootstrap(Config $config): void
130130
*/
131131
private function handleError(OutputInterface $output, Exception $e): int
132132
{
133-
$header = PHP_EOL . IOUtil::getLineSeparator() . PHP_EOL
134-
. IOUtil::formatHeadline(get_class($e), 80, '>', '<') . PHP_EOL
135-
. IOUtil::getLineSeparator();
136-
137-
$output->writeLn($header, OutputInterface::VERBOSITY_VERBOSE);
138-
$output->writeLn(PHP_EOL . $e->getMessage());
139-
133+
$output->writeLn('<error>' . PHP_EOL . $e->getMessage() . '</error>');
140134
return 1;
141135
}
142136

src/Runner/Action/Cli.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function execute(Config $config, IO $io, Repository $repository, Config\A
4747
// if any placeholders got replaced display the finally executed command
4848
if ($cmdFormatted !== $cmdOriginal) {
4949
$io->write(
50-
PHP_EOL . ' - <comment>' . $cmdFormatted . '</comment>',
50+
' - <comment>' . $cmdFormatted . '</comment>',
5151
true,
5252
IO::VERBOSE
5353
);
@@ -70,7 +70,12 @@ public function execute(Config $config, IO $io, Repository $repository, Config\A
7070
}
7171

7272
$io->write(
73-
['', empty($output) ? '<info>command executed successfully</info>' : trim($output), ''],
73+
[
74+
' - <comment>command output</comment>',
75+
'',
76+
empty($output) ? '<info>command executed successfully</info>' : trim($output),
77+
'',
78+
],
7479
true,
7580
IO::VERBOSE
7681
);

src/Runner/Hook.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,28 @@ abstract class Hook extends RepositoryAware
4444
*
4545
* @var bool
4646
*/
47-
private $skipActions = false;
47+
private bool $skipActions = false;
4848

4949
/**
5050
* Event dispatcher
5151
*
5252
* @var \CaptainHook\App\Event\Dispatcher
5353
*/
54-
protected $dispatcher;
54+
protected Dispatcher $dispatcher;
5555

5656
/**
5757
* List of error messages to display after all action have finished
5858
*
5959
* @var array<\Exception>
6060
*/
61-
protected $errors = [];
61+
protected array $errors = [];
6262

6363
/**
6464
* Plugins to apply to this hook
6565
*
6666
* @var array<Plugin\Hook>|null
6767
*/
68-
private $hookPlugins = null;
68+
private ?array $hookPlugins = null;
6969

7070
public function __construct(IO $io, Config $config, Repository $repository)
7171
{
@@ -245,7 +245,6 @@ private function executeActions(array $actions): void
245245
} else {
246246
$this->executeFailAfterAllActions($actions);
247247
}
248-
$this->io->write($this->formatCollectedErrors());
249248
} catch (Exception $e) {
250249
$this->dispatcher->dispatch('onHookFailure');
251250
throw $e;
@@ -288,7 +287,7 @@ private function executeFailAfterAllActions(array $actions): void
288287

289288
if ($failedActions > 0) {
290289
throw new ActionFailed(
291-
'<error>' . $failedActions . ' action' . ($failedActions > 1 ? 's' : '') . ' failed</error>'
290+
$failedActions . ' action' . ($failedActions > 1 ? 's' : '') . ' failed'
292291
. PHP_EOL
293292
. $this->formatCollectedErrors()
294293
);
@@ -312,7 +311,10 @@ private function handleAction(Config\Action $action): void
312311
return;
313312
}
314313

315-
$this->io->write(' - <fg=blue>' . $this->formatActionOutput($action->getAction()) . '</> : ', false);
314+
$this->io->write(
315+
' - <fg=blue>' . $this->formatActionOutput($action->getAction()) . '</> : ',
316+
$this->io->isVerbose()
317+
);
316318

317319
if (!$this->doConditionsApply($action->getConditions())) {
318320
$this->io->write('<comment>skipped</comment>', true);
@@ -476,8 +478,7 @@ private function executeHookPluginsFor(string $method, ?Config\Action $action =
476478
$plugins = $this->getHookPlugins();
477479

478480
if (count($plugins) === 0) {
479-
$this->io->write(['', 'No plugins to execute for: <comment>' . $method . '</comment>'], true, IO::DEBUG);
480-
481+
$this->io->write(['No plugins to execute for: <comment>' . $method . '</comment>'], true, IO::DEBUG);
481482
return;
482483
}
483484

@@ -487,7 +488,7 @@ private function executeHookPluginsFor(string $method, ?Config\Action $action =
487488
$params[] = $action;
488489
}
489490

490-
$this->io->write(['', 'Executing plugins for: <comment>' . $method . '</comment>'], true, IO::DEBUG);
491+
$this->io->write(['Executing plugins for: <comment>' . $method . '</comment>'], true, IO::DEBUG);
491492

492493
foreach ($plugins as $plugin) {
493494
$this->io->write('<info>- Running ' . get_class($plugin) . '::' . $method . '</info>', true, IO::DEBUG);

tests/unit/Runner/HookTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ public function testRunHookWithPlugins(): void
167167
$pluginConfig5,
168168
]);
169169

170-
$io = $this->createIOMock();
171-
$repo = $this->createRepositoryMock();
172-
$hookConfig = $this->createHookConfigMock();
170+
$io = $this->createIOMock();
171+
$repo = $this->createRepositoryMock();
172+
$hookConfig = $this->createHookConfigMock();
173173
$actionConfig = $this->createActionConfigMock();
174174
$actionConfig->method('getAction')->willReturn(CH_PATH_FILES . '/bin/success');
175175
$hookConfig->expects($this->atLeastOnce())->method('isEnabled')->willReturn(true);

0 commit comments

Comments
 (0)