Skip to content

Commit d166689

Browse files
committed
Add some color
1 parent f02236f commit d166689

8 files changed

+34
-27
lines changed

cghooks

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
#!/usr/bin/env php
22
<?php
3-
if (file_exists(__DIR__ . '/../../autoload.php')) {
4-
require __DIR__ . '/../../autoload.php';
3+
4+
if (is_file($autoload = __DIR__ . '/vendor/autoload.php')) {
5+
require $autoload;
6+
} elseif (is_file($autoload = __DIR__ . '/../../autoload.php')) {
7+
require $autoload;
58
} else {
6-
require __DIR__ . '/vendor/autoload.php';
9+
fwrite(STDERR,
10+
'You must set up the project dependencies, run the following commands:' . PHP_EOL .
11+
'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
12+
'php composer.phar install' . PHP_EOL
13+
);
14+
exit(1);
715
}
816

9-
1017
use BrainMaestro\GitHooks\Hook;
1118
use BrainMaestro\GitHooks\Commands\AddCommand;
1219
use BrainMaestro\GitHooks\Commands\UpdateCommand;
@@ -15,7 +22,7 @@ use BrainMaestro\GitHooks\Commands\ListCommand;
1522
use BrainMaestro\GitHooks\Commands\HookCommand;
1623
use Symfony\Component\Console\Application;
1724

18-
$application = new Application('Composer Git Hooks', 'v2.0.1');
25+
$application = new Application('Composer Git Hooks', 'v2.2.0');
1926

2027
$hooks = Hook::getValidHooks();
2128
$application->add(new AddCommand($hooks));

src/Commands/AddCommand.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,29 @@ protected function execute(InputInterface $input, OutputInterface $output)
4545
$filename = "{$gitDir}/hooks/{$hook}";
4646

4747
if (file_exists($filename)) {
48-
$output->writeln("'{$hook}' already exists");
48+
$output->writeln("<comment>{$hook} already exists</comment>");
4949
} else {
5050
file_put_contents($filename, $script);
5151
chmod($filename, 0755);
52-
$output->writeln("Added '{$hook}' hook");
52+
$output->writeln("Added <info>{$hook}</info> hook");
5353
$addedHooks[] = $hook;
5454
}
5555
}
5656

5757
if (! count($addedHooks)) {
58-
$output->writeln('No hooks were added. Try updating');
58+
$output->writeln('<error>No hooks were added. Try updating</error>');
5959
return;
6060
}
6161

6262
if ($input->getOption('no-lock')) {
63-
$output->writeln('Skipped creating a '. Hook::LOCK_FILE . ' file');
63+
$output->writeln('<comment>Skipped creating a '. Hook::LOCK_FILE . ' file</comment?');
6464
return;
6565
}
6666

6767
$this->addLockFile($addedHooks, $output);
6868

6969
if (! $input->getOption('ignore-lock')) {
70-
$output->writeln('Skipped adding '. Hook::LOCK_FILE . ' to .gitignore');
70+
$output->writeln('<comment>Skipped adding '. Hook::LOCK_FILE . ' to .gitignore</comment>');
7171
return;
7272
}
7373

@@ -77,15 +77,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
7777
private function addLockFile($hooks, $output)
7878
{
7979
file_put_contents(Hook::LOCK_FILE, json_encode($hooks));
80-
$output->writeln('Created ' . Hook::LOCK_FILE . ' file');
80+
$output->writeln('<comment>Created ' . Hook::LOCK_FILE . ' file</comment>');
8181
}
8282

8383
private function ignoreLockFile($output)
8484
{
8585
passthru('grep -q ' . Hook::LOCK_FILE . ' .gitignore', $return);
8686
if ($return !== 0) {
8787
passthru('echo ' . Hook::LOCK_FILE . ' >> .gitignore');
88-
$output->writeln('Added ' . Hook::LOCK_FILE . ' to .gitignore');
88+
$output->writeln('<comment>Added ' . Hook::LOCK_FILE . ' to .gitignore</comment>');
8989
}
9090
}
9191
}

src/Commands/ListCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
3636
$filename = "{$gitDir}/hooks/{$hook}";
3737

3838
if (is_file($filename)) {
39-
$output->writeln($hook);
39+
$output->writeln("<info>{$hook}</info>");
4040
}
4141
}
4242
}

src/Commands/RemoveCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
5252
$filename = "{$gitDir}/hooks/{$hook}";
5353

5454
if (! array_key_exists($hook, $lockFileHooks) && ! $input->getOption('force')) {
55-
$output->writeln("Skipped '{$hook}' hook - not present in lock file");
55+
$output->writeln("<comment>Skipped {$hook} hook - not present in lock file</comment>");
5656
continue;
5757
}
5858

5959
if (array_key_exists($hook, $this->hooks) && is_file($filename)) {
6060
unlink($filename);
61-
$output->writeln("Removed '{$hook}' hook");
61+
$output->writeln("Removed <info>{$hook}</info> hook");
6262
unset($lockFileHooks[$hook]);
6363
} else {
64-
$output->writeln("'{$hook}' hook does not exist");
64+
$output->writeln("<error>{$hook} hook does not exist</error>");
6565
}
6666
}
6767

src/Commands/UpdateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
4343
$operation = file_exists($filename) ? 'Updated' : 'Added';
4444
file_put_contents($filename, $script);
4545
chmod($filename, 0755);
46-
$output->writeln("{$operation} '{$hook}' hook");
46+
$output->writeln("{$operation} <info>{$hook}</info> hook");
4747
}
4848
}
4949
}

tests/AddCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function it_adds_hooks_that_do_not_already_exist()
2828
$this->commandTester->execute([]);
2929

3030
foreach (array_keys(self::$hooks) as $hook) {
31-
$this->assertContains("Added '{$hook}' hook", $this->commandTester->getDisplay());
31+
$this->assertContains("Added {$hook} hook", $this->commandTester->getDisplay());
3232
}
3333
}
3434

@@ -41,7 +41,7 @@ public function it_does_not_add_hooks_that_already_exist()
4141
$this->commandTester->execute([]);
4242

4343
foreach (array_keys(self::$hooks) as $hook) {
44-
$this->assertContains("'{$hook}' already exists", $this->commandTester->getDisplay());
44+
$this->assertContains("{$hook} already exists", $this->commandTester->getDisplay());
4545
}
4646
}
4747

tests/RemoveCommandTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function it_removes_hooks_that_were_added()
3030
$this->commandTester->execute([]);
3131

3232
foreach (array_keys(self::$hooks) as $hook) {
33-
$this->assertContains("Removed '{$hook}' hook", $this->commandTester->getDisplay());
33+
$this->assertContains("Removed {$hook} hook", $this->commandTester->getDisplay());
3434
}
3535
}
3636

@@ -41,7 +41,7 @@ public function it_removes_removed_hooks_from_the_lock_file()
4141
$this->assertEquals(0, $return);
4242

4343
$this->commandTester->execute(['hooks' => [$hook]]);
44-
$this->assertContains("Removed '{$hook}' hook", $this->commandTester->getDisplay());
44+
$this->assertContains("Removed {$hook} hook", $this->commandTester->getDisplay());
4545

4646
passthru("grep -q {$hook} " . Hook::LOCK_FILE, $return);
4747
$this->assertEquals(1, $return);
@@ -55,7 +55,7 @@ public function it_removes_individual_hooks()
5555
{
5656
foreach (array_keys(self::$hooks) as $hook) {
5757
$this->commandTester->execute(['hooks' => [$hook]]);
58-
$this->assertContains("Removed '{$hook}' hook", $this->commandTester->getDisplay());
58+
$this->assertContains("Removed {$hook} hook", $this->commandTester->getDisplay());
5959
}
6060
}
6161

@@ -66,7 +66,7 @@ public function it_does_not_remove_hooks_not_present_in_the_lock_file()
6666
{
6767
$hook = 'test-hook';
6868
$this->commandTester->execute(['hooks' => [$hook]]);
69-
$this->assertContains("Skipped '{$hook}' hook - not present in lock file", $this->commandTester->getDisplay());
69+
$this->assertContains("Skipped {$hook} hook - not present in lock file", $this->commandTester->getDisplay());
7070
}
7171

7272
/**
@@ -80,7 +80,7 @@ public function it_removes_hooks_not_present_in_the_lock_file_if_forced_to()
8080
$this->commandTester = new CommandTester($command);
8181

8282
$this->commandTester->execute(['hooks' => [$hook], '--force' => true]);
83-
$this->assertContains("Removed '{$hook}' hook", $this->commandTester->getDisplay());
83+
$this->assertContains("Removed {$hook} hook", $this->commandTester->getDisplay());
8484
}
8585

8686
/**
@@ -96,7 +96,7 @@ public function it_uses_a_different_git_path_if_specified()
9696
$this->commandTester->execute(['--git-dir' => $gitDir]);
9797

9898
foreach (array_keys(self::$hooks) as $hook) {
99-
$this->assertContains("Removed '{$hook}' hook", $this->commandTester->getDisplay());
99+
$this->assertContains("Removed {$hook} hook", $this->commandTester->getDisplay());
100100
}
101101

102102
$this->assertTrue(self::isDirEmpty("{$gitDir}/hooks"));

tests/UpdateCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function it_adds_hooks_that_do_not_already_exist()
2828
$this->commandTester->execute([]);
2929

3030
foreach (array_keys(self::$hooks) as $hook) {
31-
$this->assertContains("Added '{$hook}' hook", $this->commandTester->getDisplay());
31+
$this->assertContains("Added {$hook} hook", $this->commandTester->getDisplay());
3232
}
3333
}
3434

@@ -41,7 +41,7 @@ public function it_updates_hooks_that_already_exist()
4141
$this->commandTester->execute([]);
4242

4343
foreach (array_keys(self::$hooks) as $hook) {
44-
$this->assertContains("Updated '{$hook}' hook", $this->commandTester->getDisplay());
44+
$this->assertContains("Updated {$hook} hook", $this->commandTester->getDisplay());
4545
}
4646
}
4747

0 commit comments

Comments
 (0)