diff --git a/composer.json b/composer.json index 47bf0df40..aa815bbe5 100755 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ }, "require": { "php": "^7.1", - "phpoole/library": "2.2.2", + "phpoole/library": "2.3.0", "padraic/humbug_get_contents": "1.1.2", "padraic/phar-updater": "1.0.6", "symfony/filesystem": "4.1.2", diff --git a/composer.lock b/composer.lock index e91343a21..c35819dde 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1e5d69d05f505352d83eb18825dc4d5b", + "content-hash": "12d1a335272a1fe470535ba53a0b4a88", "packages": [ { "name": "cocur/slugify", @@ -613,11 +613,11 @@ }, { "name": "phpoole/library", - "version": "2.2.2", + "version": "2.3.0", "source": { "type": "git", "url": "https://github.com/PHPoole/library", - "reference": "7a4871f9366edda10899e354360f61e7211374d2" + "reference": "63b453ccf572663617113613ca30695832286807" }, "require": { "cocur/slugify": "3.1", @@ -699,7 +699,7 @@ "source": "https://github.com/PHPoole/library", "issues": "https://github.com/PHPoole/library/issues" }, - "time": "2018-08-09T13:51:45+00:00" + "time": "2018-08-12T20:13:40+00:00" }, { "name": "psr/container", @@ -2430,16 +2430,16 @@ }, { "name": "humbug/php-scoper", - "version": "0.9.1", + "version": "0.9.2", "source": { "type": "git", "url": "https://github.com/humbug/php-scoper.git", - "reference": "e7eb4b83ad8cf9aea45e5cb4d4d7742ee2d07648" + "reference": "f595614c73243fa084caa30a6e75f2442277e631" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/humbug/php-scoper/zipball/e7eb4b83ad8cf9aea45e5cb4d4d7742ee2d07648", - "reference": "e7eb4b83ad8cf9aea45e5cb4d4d7742ee2d07648", + "url": "https://api.github.com/repos/humbug/php-scoper/zipball/f595614c73243fa084caa30a6e75f2442277e631", + "reference": "f595614c73243fa084caa30a6e75f2442277e631", "shasum": "" }, "require": { @@ -2498,7 +2498,7 @@ } ], "description": "Prefixes all PHP namespaces in a file or directory.", - "time": "2018-08-06T18:04:52+00:00" + "time": "2018-08-10T11:35:57+00:00" }, { "name": "justinrainbow/json-schema", diff --git a/config/routes.php b/config/routes.php index fe91bd7e6..8e1242854 100755 --- a/config/routes.php +++ b/config/routes.php @@ -28,9 +28,10 @@ ], [ 'name' => 'build', - 'route' => '[] [--drafts|-d] [--baseurl=]', + 'route' => '[] [--drafts|-d] [--baseurl=] [--quiet|-q]', 'aliases' => [ 'd' => 'drafts', + 'q' => 'quiet', ], 'short_description' => 'Build the website', 'description' => 'Build the website.', @@ -38,6 +39,7 @@ '' => 'Website path', '--drafts|-d' => 'Include drafts', '--baseurl' => 'Base URL', + '--quiet|-q' => 'Not verbose messages', ], 'defaults' => [ 'path' => getcwd(), diff --git a/src/Command/AbstractCommand.php b/src/Command/AbstractCommand.php index e8a219c3d..e92828ae5 100755 --- a/src/Command/AbstractCommand.php +++ b/src/Command/AbstractCommand.php @@ -51,6 +51,14 @@ abstract class AbstractCommand * @var int */ protected $pbMax = 0; + /** + * @var bool + */ + protected $debug = false; + /** + * @var bool + */ + protected $quiet = false; /** * Start command processing. @@ -113,14 +121,16 @@ public function getPath() */ protected function newPB($start, $max) { - if ($this->progressBar == null || $max != $this->pbMax) { + if ($this->progressBar === null || $max != $this->pbMax) { $this->pbMax = $max; $adapter = new \Zend\ProgressBar\Adapter\Console([ 'elements' => [ \Zend\ProgressBar\Adapter\Console::ELEMENT_PERCENT, \Zend\ProgressBar\Adapter\Console::ELEMENT_BAR, \Zend\ProgressBar\Adapter\Console::ELEMENT_TEXT, - ], ]); + ], + 'textWidth' => 30, + ]); $this->progressBar = new ProgressBar($adapter, $start, $max); } @@ -142,11 +152,22 @@ protected function getPB() */ public function getPHPoole(array $options = []) { - $messageCallback = function ($code, $message = '', $itemsCount = 0, $itemsMax = 0, $verbose = false) { + // debug mode? + if (array_key_exists('debug', $options) && $options['debug']) { + $this->debug = true; + } + // quiet mode? + if (array_key_exists('quiet', $options) && $options['quiet']) { + $this->quiet = true; + } + + // CLI custom message callback function + $messageCallback = function ($code, $message = '', $itemsCount = 0, $itemsMax = 0) { switch ($code) { case 'CREATE': case 'CONVERT': case 'GENERATE': + case 'MENU': case 'COPY': case 'RENDER': case 'TIME': @@ -155,26 +176,42 @@ public function getPHPoole(array $options = []) case 'CREATE_PROGRESS': case 'CONVERT_PROGRESS': case 'GENERATE_PROGRESS': + case 'MENU_PROGRESS': case 'COPY_PROGRESS': case 'RENDER_PROGRESS': - if ($verbose) { - if ($itemsCount > 0 && $verbose !== false) { - $this->wlDone(sprintf("\r (%u/%u) %s", $itemsCount, $itemsMax, $message)); + if ($this->debug) { + if ($itemsCount > 0) { + $this->wlDone(sprintf('(%u/%u) %s', $itemsCount, $itemsMax, $message)); break; } - $this->wlDone(" $message"); + $this->wlDone("$message"); } else { - if ($itemsMax && $itemsCount) { - $this->newPB(1, $itemsMax); - $this->getPB()->update($itemsCount, "$message"); - } else { - $this->wl($message); + if (!$this->quiet) { + if ($itemsMax && $itemsCount) { + $this->newPB(1, $itemsMax); + $this->getPB()->update($itemsCount, "$message"); + if ($itemsCount == $itemsMax) { + $this->getPB()->update($itemsCount, "[$itemsCount/$itemsMax]"); + $this->getPB()->finish(); + } + } else { + $this->wl($message); + } } } break; + case 'CREATE_ERROR': + case 'CONVERT_ERROR': + case 'GENERATE_ERROR': + case 'MENU_ERROR': + case 'COPY_ERROR': + case 'RENDER_ERROR': + $this->wlError($message); + break; } }; + // instanciate PHPoole? if (!$this->phpoole instanceof PHPoole) { if (!file_exists($this->getPath().'/'.self::CONFIG_FILE)) { throw new \Exception(sprintf('Config file not found in "%s"!', $this->getPath())); @@ -231,7 +268,7 @@ public function wlAlert($text) } /** - * @param $text + * @param string $text */ public function wlError($text) { diff --git a/src/Command/Build.php b/src/Command/Build.php index 909a41ad3..b26058d64 100755 --- a/src/Command/Build.php +++ b/src/Command/Build.php @@ -20,11 +20,16 @@ class Build extends AbstractCommand * @var string */ protected $baseurl; + /** + * @var bool + */ + protected $quiet; public function processCommand() { $this->drafts = $this->route->getMatchedParam('drafts', false); $this->baseurl = $this->route->getMatchedParam('baseurl'); + $this->quiet = $this->route->getMatchedParam('quiet', false); $message = 'Building website%s...'; @@ -36,6 +41,9 @@ public function processCommand() if ($this->baseurl) { $options['site']['baseurl'] = $this->baseurl; } + if ($this->quiet) { + $options['quiet'] = true; + } $this->wl(sprintf($message, $messageOpt));