From ca1f092d273c2fa023e03e325a6a347de2dc95ba Mon Sep 17 00:00:00 2001 From: Erika Heidi Date: Wed, 28 Sep 2022 18:05:15 +0200 Subject: [PATCH] Updating to Minicli 3 --- bin/command/Generate/CoverController.php | 16 +++++++-------- bin/command/Generate/DefaultController.php | 2 +- bin/command/Help/DefaultController.php | 4 ++-- bin/command/Resize/CropController.php | 22 +++++++++------------ bin/command/Resize/DefaultController.php | 2 +- bin/gdaisy | 11 ++++++++--- composer.json | 2 +- composer.lock | 23 ++++++++++------------ 8 files changed, 39 insertions(+), 43 deletions(-) diff --git a/bin/command/Generate/CoverController.php b/bin/command/Generate/CoverController.php index 6c875f2..55f92ae 100644 --- a/bin/command/Generate/CoverController.php +++ b/bin/command/Generate/CoverController.php @@ -8,7 +8,10 @@ class CoverController extends CommandController { - public function handle() + /** + * @throws \Exception + */ + public function handle(): void { $template_file = $this->getApp()->config->default_template; @@ -17,18 +20,15 @@ public function handle() } if (!is_file($template_file)) { - $this->getPrinter()->error("Template not found."); - return 1; + throw new \Exception("Template file not found."); } if (!isset($this->getArgs()[3])) { - $this->getPrinter()->error("You must provide the URL as second parameter."); - return 1; + throw new \Exception("You must provide the URL as second parameter."); } if (!isset($this->getArgs()[4])) { - $this->getPrinter()->error("You must provide the Output location as third parameter."); - return 1; + throw new \Exception("You must provide the Output location as third parameter."); } $template = Template::create($template_file); @@ -57,8 +57,6 @@ public function handle() $template->write($dest); $this->getPrinter()->info("Image saved to $dest."); - - return 0; } function get_page_title(string $url) { diff --git a/bin/command/Generate/DefaultController.php b/bin/command/Generate/DefaultController.php index d3ca990..43b1baf 100644 --- a/bin/command/Generate/DefaultController.php +++ b/bin/command/Generate/DefaultController.php @@ -6,7 +6,7 @@ class DefaultController extends CommandController { - public function handle() + public function handle(): void { $this->getPrinter()->out("To generate a new cover based on the default template:"); $this->getPrinter()->info("gdaisy generate cover [cover-url] [output-path]"); diff --git a/bin/command/Help/DefaultController.php b/bin/command/Help/DefaultController.php index b6fd729..4ac8353 100644 --- a/bin/command/Help/DefaultController.php +++ b/bin/command/Help/DefaultController.php @@ -10,13 +10,13 @@ class DefaultController extends CommandController /** @var array */ protected $command_map = []; - public function boot(App $app) + public function boot(App $app): void { parent::boot($app); $this->command_map = $app->command_registry->getCommandMap(); } - public function handle() + public function handle(): void { $this->getPrinter()->info('Available Commands'); diff --git a/bin/command/Resize/CropController.php b/bin/command/Resize/CropController.php index 695f12a..f76ff3f 100644 --- a/bin/command/Resize/CropController.php +++ b/bin/command/Resize/CropController.php @@ -8,35 +8,33 @@ class CropController extends CommandController { - public function handle() + /** + * @throws \Exception + */ + public function handle(): void { if (!$this->hasParam('size')) { - $this->getPrinter()->error("You must provide a valid 'size' argument such as size=square."); - return 1; + throw new \Exception("You must provide a valid 'size' argument such as size=square."); } $template_file = dirname(__DIR__,3) . '/resources/templates/resize-' . $this->getParam('size') . '.json'; if (!is_file($template_file)) { - $this->getPrinter()->error("Invalid Size/Template not found."); - return 1; + throw new \Exception("Invalid Size/Template not found."); } if (!$this->hasParam('input')) { - $this->getPrinter()->error("You must provide an input image as input=full/path/to/image.png"); - return 1; + throw new \Exception("You must provide an input image as input=full/path/to/image.png"); } $input_file = $this->getParam('input'); if (!is_file($input_file)) { - $this->getPrinter()->error("Input file not found."); - return 1; + throw new \Exception("Input file not found."); } if (!$this->hasParam('output')) { - $this->getPrinter()->error("You must provide an output image as output=full/path/to/output.png"); - return 1; + throw new \Exception("You must provide an output image as output=full/path/to/output.png"); } @@ -48,7 +46,5 @@ public function handle() $template->write($this->getParam('output')); $this->getPrinter()->info("Image saved to " . $this->getParam('output')); - - return 0; } } \ No newline at end of file diff --git a/bin/command/Resize/DefaultController.php b/bin/command/Resize/DefaultController.php index 5875f3b..34a069d 100644 --- a/bin/command/Resize/DefaultController.php +++ b/bin/command/Resize/DefaultController.php @@ -6,7 +6,7 @@ class DefaultController extends CommandController { - public function handle() + public function handle(): void { $this->getPrinter()->out("To create a cropped thumbnail:"); $this->getPrinter()->info("gdaisy resize crop size=[format] input=[input-path] output=[output-path]"); diff --git a/bin/gdaisy b/bin/gdaisy index 0aaef7d..f16c45d 100755 --- a/bin/gdaisy +++ b/bin/gdaisy @@ -40,8 +40,13 @@ $gdaisy->setSignature($signature); try { $gdaisy->runCommand($argv); - return 0; -} catch (CommandNotFoundException $e) { - $gdaisy->getPrinter()->error("Command not found."); +} catch (CommandNotFoundException $notFoundException) { + $gdaisy->getPrinter()->error("Command Not Found."); + return 1; +} catch (Exception $exception) { + if ($gdaisy->config->debug) { + $gdaisy->getPrinter()->error("An error occurred:"); + $gdaisy->getPrinter()->error($exception->getMessage()); + } return 1; } \ No newline at end of file diff --git a/composer.json b/composer.json index e2239ce..7becb75 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "php": "^8.1", "ext-gd": "*", "ext-json": "*", - "minicli/minicli": "^2.2" + "minicli/minicli": "^3.2" }, "require-dev": { "pestphp/pest": "^1.0" diff --git a/composer.lock b/composer.lock index 5bb966f..5920183 100644 --- a/composer.lock +++ b/composer.lock @@ -4,37 +4,34 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "09b1782ba08db51a1a93e70715fc41cc", + "content-hash": "331f064eaf6787b29a9bb12ba9e17f22", "packages": [ { "name": "minicli/minicli", - "version": "2.2.2", + "version": "3.2.1", "source": { "type": "git", "url": "https://github.com/minicli/minicli.git", - "reference": "7a136614949b47d716769a037a1107e414bc4f38" + "reference": "2d31b303461d0ec1f8c6d0be00f8b26be8766fbe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/minicli/minicli/zipball/7a136614949b47d716769a037a1107e414bc4f38", - "reference": "7a136614949b47d716769a037a1107e414bc4f38", + "url": "https://api.github.com/repos/minicli/minicli/zipball/2d31b303461d0ec1f8c6d0be00f8b26be8766fbe", + "reference": "2d31b303461d0ec1f8c6d0be00f8b26be8766fbe", "shasum": "" }, "require": { - "php": ">=7.3" + "ext-readline": "*", + "php": ">=8" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^2.16", + "friendsofphp/php-cs-fixer": "^3.5", "pestphp/pest": "^1.0", "phpunit/phpunit": "^9.0" }, - "suggest": { - "ext-readline": "For obtaining user input" - }, "type": "library", "autoload": { "psr-4": { - "Assets\\": "tests/Assets", "Minicli\\": "src/" } }, @@ -50,7 +47,7 @@ ], "support": { "issues": "https://github.com/minicli/minicli/issues", - "source": "https://github.com/minicli/minicli/tree/2.2.2" + "source": "https://github.com/minicli/minicli/tree/3.2.1" }, "funding": [ { @@ -58,7 +55,7 @@ "type": "github" } ], - "time": "2021-10-30T07:30:03+00:00" + "time": "2022-09-23T09:04:22+00:00" } ], "packages-dev": [