Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading to Minicli 3 #6

Merged
merged 1 commit into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions bin/command/Generate/CoverController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

class CoverController extends CommandController
{
public function handle()
/**
* @throws \Exception
*/
public function handle(): void
{
$template_file = $this->getApp()->config->default_template;

Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion bin/command/Generate/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]");
Expand Down
4 changes: 2 additions & 2 deletions bin/command/Help/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
22 changes: 9 additions & 13 deletions bin/command/Resize/CropController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}


Expand All @@ -48,7 +46,5 @@ public function handle()

$template->write($this->getParam('output'));
$this->getPrinter()->info("Image saved to " . $this->getParam('output'));

return 0;
}
}
2 changes: 1 addition & 1 deletion bin/command/Resize/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]");
Expand Down
11 changes: 8 additions & 3 deletions bin/gdaisy
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 10 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.