Skip to content

Commit

Permalink
New plugin:upgrade command
Browse files Browse the repository at this point in the history
  • Loading branch information
afbora committed Feb 28, 2024
1 parent 3ce04ea commit f78b8f6
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions commands/plugin/upgrade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types = 1);

use Kirby\CLI\CLI;
use Kirby\Filesystem\Dir;

return [
'description' => 'Upgrades a kirby plugin',
'args' => [
'repo' => [
'description' => 'The Kirby plugin registry name (i.e. getkirby/kql)',
'required' => true
],
'version' => [
'description' => 'The version corresponding with the tag name in the repo',
'defaultValue' => 'latest'
]
],
'command' => static function (CLI $cli): void {
$repo = $cli->arg('repo');
$version = $cli->arg('version');

if ($plugin = $cli->kirby()->plugin($repo)) {
try {
// move plugin directory to prevent overwrite
Dir::move($plugin->root(), $plugin->root() . '.bak');
$cli->run('plugin:install', $repo, $version);
Dir::remove($plugin->root() . '.bak');
$cli->success('The ' . $repo . ' plugin has been updated to ' . $version . ' version');
} catch (Throwable) {
Dir::move($plugin->root() . '.bak', $plugin->root());
$cli->error('The ' . $repo . ' plugin could not updated');
}
} else {
$cli->error('The ' . $repo . ' plugin could not found');
}
}
];

0 comments on commit f78b8f6

Please sign in to comment.