Skip to content

Commit

Permalink
Improve output format
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianfeldmann committed Dec 13, 2023
1 parent 3749630 commit 03e27d7
Showing 1 changed file with 27 additions and 33 deletions.
60 changes: 27 additions & 33 deletions src/ComposerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
*/
class ComposerPlugin implements PluginInterface, EventSubscriberInterface
{
private const COMMAND_CONFIGURE = 'configure';
private const COMMAND_INSTALL = 'install';

/**
* Composer instance
*
Expand Down Expand Up @@ -112,8 +109,6 @@ public function uninstall(Composer $composer, IOInterface $io)
// Do nothing currently
}



/**
* Make sure the installer is executed after the autoloader is created
*
Expand Down Expand Up @@ -144,14 +139,14 @@ public function installHooks(Event $event): void
}

if (getenv('CI') === 'true') {
$this->io->write(' <comment>disabling plugin due to CI-environment</comment>');
$this->io->write(' <comment>disabling plugin due to CI-environment</comment>');
return;
}

$this->detectConfiguration();
$this->detectGitDir();
if ($this->isWorktree) {
$this->io->write(' <comment>ARRRRR! We ARRR in a worktree, install is skipped!</comment>');
$this->io->write(' <comment>ARRRRR! We ARRR in a worktree, install is skipped!</comment>');
return;
}
$this->detectCaptainExecutable();
Expand Down Expand Up @@ -263,17 +258,6 @@ private function detectGitDir(): void
throw new RuntimeException($this->pluginErrorMessage('git directory not found'));
}

/**
* Creates a nice formatted error message
*
* @param string $reason
* @return string
*/
private function pluginErrorMessage(string $reason): string
{
return 'Shiver me timbers! CaptainHook could not install yer git hooks! (' . $reason . ')';
}

/**
* Try to find the captainhook executable
*
Expand Down Expand Up @@ -320,21 +304,21 @@ private function isForceInstall(): bool
private function writeNoExecutableHelp(): void
{
$this->io->write(
'<comment>CaptainHook executable not found</comment>' . PHP_EOL .
' <comment>CaptainHook executable not found</comment>' . PHP_EOL .
PHP_EOL .
'Make sure you have installed <info>CaptainHook</info> .' . PHP_EOL .
'If you installed the Cap\'n to a custom location you have to configure the path ' .PHP_EOL .
'to your CaptainHook executable using Composers \'extra\' config. e.g.' . PHP_EOL .
' Make sure you have installed <info>CaptainHook</info> .' . PHP_EOL .
' If you installed the Cap\'n to a custom location you have to configure the path ' .PHP_EOL .
' to your CaptainHook executable using Composers \'extra\' config. e.g.' . PHP_EOL .
PHP_EOL . '<comment>' .
' "extra": {' . PHP_EOL .
' "captainhook": {' . PHP_EOL .
' "exec": "tools/captainhook.phar' . PHP_EOL .
' }' . PHP_EOL .
' }' . PHP_EOL .
'</comment>' . PHP_EOL .
'If you are uninstalling CaptainHook, we are sad seeing you go, ' .
'but we would appreciate your feedback on your experience.' . PHP_EOL .
'Just go to https://github.com/captainhookphp/captainhook/issues to leave your feedback' . PHP_EOL .
' If you are uninstalling CaptainHook, we are sad seeing you go, ' .
' but we would appreciate your feedback on your experience.' . PHP_EOL .
' Just go to https://github.com/captainhookphp/captainhook/issues to leave your feedback' . PHP_EOL .
PHP_EOL
);
}
Expand All @@ -347,19 +331,29 @@ private function writeNoExecutableHelp(): void
private function writeNoConfigHelp(): void
{
$this->io->write(
'<comment>CaptainHook configuration not found</comment>' . PHP_EOL .
' <comment>CaptainHook configuration not found</comment>' . PHP_EOL .
PHP_EOL .
'If your CaptainHook configuration is not named <info>captainhook.json</info> or is not' . PHP_EOL .
'located in your repository root you have to configure the path to your' .PHP_EOL .
'CaptainHook configuration using Composers \'extra\' config. e.g.' . PHP_EOL .
PHP_EOL . '<comment>' .
' "extra": {' . PHP_EOL .
' If your CaptainHook configuration is not named <info>captainhook.json</info> or is not' . PHP_EOL .
' located in your repository root you have to configure the path to your' .PHP_EOL .
' CaptainHook configuration using Composers \'extra\' config. e.g.' . PHP_EOL .
PHP_EOL .
' <comment>"extra": {' . PHP_EOL .
' "captainhook": {' . PHP_EOL .
' "config": "config/hooks.json' . PHP_EOL .
' }' . PHP_EOL .
' }' . PHP_EOL .
'</comment>' . PHP_EOL .
' }</comment>' . PHP_EOL .
PHP_EOL
);
}

/**
* Creates a nice formatted error message
*
* @param string $reason
* @return string
*/
private function pluginErrorMessage(string $reason): string
{
return 'Shiver me timbers! CaptainHook could not install yer git hooks! (' . $reason . ')';
}
}

0 comments on commit 03e27d7

Please sign in to comment.