Skip to content
This repository has been archived by the owner on Jul 17, 2021. It is now read-only.

Commit

Permalink
output branding
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-feek committed Sep 18, 2017
1 parent f54bbe6 commit 17803c1
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 26 deletions.
27 changes: 27 additions & 0 deletions src/Commands/BaseCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Feek\LaravelGitHooks\Commands;

use Illuminate\Console\Command;

class BaseCommand extends Command
{
/**
* Write a string as standard output.
*
* @param string $string
* @param string $style
* @param null|int|string $verbosity
* @param bool $prefix
*
* @return void
*/
public function line($string, $style = null, $verbosity = null, $prefix = true)
{
if ($prefix) {
$string = '[LARAVEL GIT HOOKS] ' . $string;
}

parent::line($string, $style, $verbosity);
}
}
24 changes: 19 additions & 5 deletions src/Commands/CommitHooks/CommitHookCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace Feek\LaravelGitHooks\Commands\CommitHooks;

use Illuminate\Console\Command;
use Feek\LaravelGitHooks\Commands\BaseCommand;
use Illuminate\Support\Str;
use Symfony\Component\Console\Terminal;

abstract class CommitHookCommand extends Command
abstract class CommitHookCommand extends BaseCommand
{
/**
* Execute the console command.
Expand All @@ -14,6 +15,19 @@ abstract class CommitHookCommand extends Command
*/
public function handle()
{
$terminal = new Terminal();
$width = $terminal->getWidth();


if ($width >= 80) {
$this->line(<<<EOT
__ ___ __ ___ __ __ __
| /\ |__) /\ \ / |__ | / _` | | |__| / \ / \ |__/ /__`
|___ /~~\ | \ /~~\ \/ |___ |___ \__> | | | | \__/ \__/ | \ .__/
EOT
, null, null, false);
}

$commands = config($this->getConfigKey());

if ($commands) {
Expand All @@ -25,18 +39,18 @@ public function handle()

$formattedArguments = $this->buildArgumentArrayFromArgumentString($commandName, $arguments);

$this->line('git hook invoking: ' . $commandName . ' ' . implode($arguments, ' '));
$this->line('invoking: ' . $commandName . ' ' . implode($arguments, ' '));

$statusCode = $this->call($commandName, $formattedArguments);

if ($statusCode !== 0) {
$this->error('git hook check failed');
$this->error('check failed');
return $statusCode;
}
}
}

$this->info('git hook checks passed!');
$this->info('all checks passed!');

return 0;
}
Expand Down
16 changes: 1 addition & 15 deletions src/Commands/InstallHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

namespace Feek\LaravelGitHooks\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
use PHPUnit\TextUI\TestRunner;

class InstallHooks extends Command
class InstallHooks extends BaseCommand
{
/**
* The name and signature of the console command.
Expand All @@ -22,16 +18,6 @@ class InstallHooks extends Command
*/
protected $description = 'Installs all laravel-git-hooks to the local .git hooks folder';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
Expand Down
8 changes: 4 additions & 4 deletions src/Commands/PhpUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Feek\LaravelGitHooks\Commands;

use Illuminate\Console\Command;
use PHPUnit\TextUI\Command;
use PHPUnit\TextUI\TestRunner;

class PhpUnit extends Command
class PhpUnit extends BaseCommand
{
/**
* The name and signature of the console command.
Expand Down Expand Up @@ -38,11 +38,11 @@ public function __construct()
*/
public function handle()
{
$this->info('running test suite...');
$this->line('running test suite...');

ob_start();

$result = (new \PHPUnit\TextUI\Command())->run([
$result = (new Command())->run([
'--disallow-test-output',
'--stop-on-failure'
], false);
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/SnifferCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;

abstract class SnifferCommand extends Command
abstract class SnifferCommand extends BaseCommand
{
/**
* @return string
Expand Down Expand Up @@ -76,7 +76,7 @@ public function handle()
$filesToCheck = implode($filesToCheck, ' ');

if (!$filesToCheck) {
$this->warn('skipping check because no files have been passed');
$this->warn('did not find any files to sniff');
return 0;
}
}
Expand Down

0 comments on commit 17803c1

Please sign in to comment.