feat(self-update): resolve latest via Forgejo/gitea releases API
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Toolbox\Commands;
|
||||
|
||||
use Toolbox\Config;
|
||||
use Toolbox\SelfUpdater;
|
||||
use Toolbox\Semver;
|
||||
use Toolbox\ToolboxException;
|
||||
|
||||
final class SelfUpdateCommand extends Command
|
||||
@@ -19,14 +20,24 @@ final class SelfUpdateCommand extends Command
|
||||
$from = $this->option($parsed['options'], 'from', Config::updateUrl());
|
||||
$target = $this->option($parsed['options'], 'target', Config::binPath());
|
||||
$temp = $this->option($parsed['options'], 'temp', sys_get_temp_dir());
|
||||
$force = $this->flag($parsed['options'], 'force');
|
||||
|
||||
if ($from === null || $target === null) {
|
||||
$this->console->error('Faltan --from o --target.');
|
||||
return 1;
|
||||
}
|
||||
|
||||
$updater = new SelfUpdater($this->console);
|
||||
|
||||
try {
|
||||
(new SelfUpdater($this->console))->update($from, $target, $temp);
|
||||
if ($this->flag($parsed['options'], 'check')) {
|
||||
$tag = $updater->available($from);
|
||||
$this->console->out(' actual: v' . Config::VERSION);
|
||||
$this->console->out(' disponible: ' . ($tag !== null ? 'v' . ltrim($tag, 'vV') : '(desconocido)'));
|
||||
return $tag === null || Semver::compare(Config::VERSION, ltrim($tag, 'vV')) >= 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
$updater->update($from, $target, $temp, $force);
|
||||
} catch (ToolboxException $e) {
|
||||
$this->console->error($e->getMessage());
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user