Skip to content

Commit

Permalink
--version option added
Browse files Browse the repository at this point in the history
  • Loading branch information
ᏒᏊᏀᏋᏒ ᏕξᏐ committed Oct 9, 2019
1 parent f5ea999 commit 77a7ec9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 30 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
5 changes: 0 additions & 5 deletions bin/super-giggle
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
71 changes: 47 additions & 24 deletions src/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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::',
];

Expand All @@ -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) .
Expand All @@ -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);
}


Expand Down

0 comments on commit 77a7ec9

Please sign in to comment.