diff --git a/CHANGELOG.md b/CHANGELOG.md index fa286fb..4959ade 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog @author ᏒᏊᏀᏋᏒ ᏕξᏐ -## [0.4.0] - 2019-10-08 +## [0.4.1] - 2019-10-08 ### Added - New option added: --diff-cached. An useful option to check for staged git files. diff --git a/bin/super-giggle b/bin/super-giggle index fe46a72..395022b 100755 --- a/bin/super-giggle +++ b/bin/super-giggle @@ -21,11 +21,6 @@ use SuperGiggle\{Main, Util, Os}; $util = new Util; $util->setOs(new Os()); $opts = $util->parseArgs(); -if (isset($opts['help'])) { - $util->printUsage(); -} - - $sg = new Main(); $sg->setUtil($util); diff --git a/src/Main.php b/src/Main.php index dcb8e89..fca224e 100644 --- a/src/Main.php +++ b/src/Main.php @@ -328,6 +328,12 @@ private function validateOptions(): void // TODO: Move this validation to a separated class. $base = dirname(__DIR__); + if (isset($this->options['help']) === true) { + $this->util->printUsage(); + } elseif (isset($this->options['version']) === true) { + $this->util->printVersion(); + } + // First, we check for basic system requirements. if ($this->isPhar === true) { if (isset($this->options['phpcs']) === true) { diff --git a/src/Util.php b/src/Util.php index a5207ec..6bedd41 100644 --- a/src/Util.php +++ b/src/Util.php @@ -26,6 +26,30 @@ class Util */ public $os; + /** + * The current version. + * + * @var string + */ + const VERSION = '0.4.1'; + + + /** + * Get phpcs binary + * + * @return string + */ + public function getPhpCsBinary(): string + { + $path = __DIR__ . '/../vendor/bin/phpcs'; + + if ($this->os->isWindows() === true) { + $path = str_replace('\\', '/', __DIR__ . '/../vendor/bin/phpcs.bat'); + } + + return $path; + } + /** * Parse args and return in a friendly format @@ -35,18 +59,19 @@ class Util public function parseArgs(): array { $alloweds = [ - 'commit:', - 'help', 'all', - 'verbose::', + 'commit:', 'diff', 'diff-cached', 'file:', + 'help', 'php::', 'php-version::', 'phpcs:', 'repo:', 'standard:', + 'verbose::', + 'version', 'warnings::', ]; @@ -68,17 +93,20 @@ public function printUsage(): void { echo " Usage: \033[0;35msuper-giggle [--commit]\033[0m\n\n"; $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' => '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', + 'all' => 'Performs a full check and not only the changed lines.', + 'commit' => 'Checks agains a specifi commit.', + 'diff' => 'Validate changes on the current repository, between commits or branches.', + 'diff-cached' => 'Check changes on staged files, alongside with --diff.', + 'file' => 'Checks changes for the specific given file.', + 'help' => 'Print this help.', + 'phpcs' => 'Indicates the php binary. Defaults to ENV.', + 'php-version' => 'Checks the code accordingly to a specified PHP version.', + 'repo' => 'Indicates the git working directory. Defaults to current cwd.', + 'standard' => 'The name or path of the coding standard to use.', + 'type' => 'The type of check. Defaults to "show" changes of a given commit.', + 'verbose' => 'Prints additional information.', + 'version' => 'Displays current super-giggle version.', + 'warnings' => 'Also displays warnings.', ]; foreach ($options as $name => $description) { echo str_pad("\033[1;31m --$name ", 24, ' ', STR_PAD_RIGHT) . @@ -92,19 +120,14 @@ public function printUsage(): void /** - * Get phpcs binary + * Print current super-giggle version, as in Util::VERSION. * - * @return string + * @return void */ - public function getPhpCsBinary(): string + public function printVersion(): void { - $path = __DIR__ . '/../vendor/bin/phpcs'; - - if ($this->os->isWindows() === true) { - $path = str_replace('\\', '/', __DIR__ . '/../vendor/bin/phpcs.bat'); - } - - return $path; + echo ' super-giggle version ' . self::VERSION . " \n\n"; + exit(0); }