-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} | ||
]; |