From f5ea9996224d9e1e47c666f24f9755bc1af40d12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=8F=92=E1=8F=8A=E1=8F=80=E1=8F=8B=E1=8F=92=20=E1=8F=95?= =?UTF-8?q?=CE=BE=E1=8F=90?= Date: Tue, 8 Oct 2019 20:47:49 -0300 Subject: [PATCH] New option added: --diff-cached --- CHANGELOG.md | 6 ++++++ src/Main.php | 10 ++++++++-- src/Util.php | 6 ++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59a8e7f..fa286fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Changelog @author ᏒᏊᏀᏋᏒ ᏕξᏐ +## [0.4.0] - 2019-10-08 +### Added +- New option added: --diff-cached. An useful option to check for staged git files. + + +# ## [0.3.1] - 2019-09-30 ### Fixed - PHPCS path for phar fixed diff --git a/src/Main.php b/src/Main.php index c7288ea..dcb8e89 100644 --- a/src/Main.php +++ b/src/Main.php @@ -311,6 +311,8 @@ public function run(array $options = null): void if ($this->errorFound === true) { echo PHP_EOL; exit(1); + } else { + exit(0); } } @@ -387,6 +389,10 @@ private function validateOptions(): void $this->options['type'] = 'diff'; } + if (isset($this->options['diff-cached']) === true) { + $this->options['type'] = 'diff --cached'; + } + if (isset($this->options['warnings']) === true) { $this->options['warnings'] = '--warning-severity=5'; } else { @@ -436,10 +442,10 @@ private function validateOptions(): void $error .= "Available commits:\n\n$result"; $this->exit($error); } - } elseif ($this->options['type'] === 'diff') { + } elseif ($this->options['type'] === 'diff' || $this->options['type'] === 'diff --cached') { $this->options['commit'] = ($this->options['commit'] ?? ''); } else { - $this->exit('Invalid value for ``--type``.'); + $this->exit('Invalid value for --type.'); } } else { $this->options['commit'] = ($this->options['commit'] ?? ''); diff --git a/src/Util.php b/src/Util.php index dc3472a..a5207ec 100644 --- a/src/Util.php +++ b/src/Util.php @@ -40,6 +40,7 @@ public function parseArgs(): array 'all', 'verbose::', 'diff', + 'diff-cached', 'file:', 'php::', 'php-version::', @@ -69,17 +70,18 @@ public function printUsage(): void $options = [ 'standard' => 'The name or path of the coding standard to use', 'diff' => 'Validate changes on the current repository, between commits or branches', + 'diff-cached' => 'Check changes on staged files, alongside with --diff', 'all' => 'Performs a full check and not only the changed lines', 'repo' => 'Indicates the git working directory. Defaults to current cwd', 'phpcs' => 'Indicates the php binary. Defaults to ENV', - 'php-version' => 'allows to specify a PHP version to check the code accordingly', + 'php-version' => 'Checks the code accordingly to a specified PHP version', 'type' => 'The type of check. Defaults to "show" changes of a given commit. ', 'help' => 'Print this help', 'verbose' => 'Prints additional information', 'warnings' => 'Also displays warnings', ]; foreach ($options as $name => $description) { - echo str_pad("\033[1;31m --$name ", 22, ' ', STR_PAD_RIGHT) . + echo str_pad("\033[1;31m --$name ", 24, ' ', STR_PAD_RIGHT) . "\033[1;37m" . $description . "\033[0m" . PHP_EOL; }