Skip to content

Commit

Permalink
New option added: --diff-cached
Browse files Browse the repository at this point in the history
  • Loading branch information
ᏒᏊᏀᏋᏒ ᏕξᏐ committed Oct 8, 2019
1 parent b2ff428 commit f5ea999
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 8 additions & 2 deletions src/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ public function run(array $options = null): void
if ($this->errorFound === true) {
echo PHP_EOL;
exit(1);
} else {
exit(0);
}
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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'] ?? '');
Expand Down
6 changes: 4 additions & 2 deletions src/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function parseArgs(): array
'all',
'verbose::',
'diff',
'diff-cached',
'file:',
'php::',
'php-version::',
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit f5ea999

Please sign in to comment.