From 5648681ecc1d6eb0f778bce08a860c58dbf563de Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 30 Mar 2025 15:17:09 +0800 Subject: [PATCH] Adjust console output and PHPDoc --- src/SPC/command/DownloadCommand.php | 8 +++---- src/SPC/store/Downloader.php | 37 +++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/SPC/command/DownloadCommand.php b/src/SPC/command/DownloadCommand.php index 7bf82ebb..6286969a 100644 --- a/src/SPC/command/DownloadCommand.php +++ b/src/SPC/command/DownloadCommand.php @@ -212,7 +212,7 @@ class DownloadCommand extends BaseCommand if (isset($config['filename'])) { $new_config['filename'] = $config['filename']; } - logger()->info("Fetching source {$source} from custom url [{$ni}/{$cnt}]"); + logger()->info("[{$ni}/{$cnt}] Downloading source {$source} from custom url: {$new_config['url']}"); Downloader::downloadSource($source, $new_config, true); } elseif (isset($custom_gits[$source])) { $config = Config::getSource($source); @@ -224,7 +224,7 @@ class DownloadCommand extends BaseCommand if (isset($config['path'])) { $new_config['path'] = $config['path']; } - logger()->info("Fetching source {$source} from custom git [{$ni}/{$cnt}]"); + logger()->info("[{$ni}/{$cnt}] Downloading source {$source} from custom git: {$new_config['url']}"); Downloader::downloadSource($source, $new_config, true); } else { $config = Config::getSource($source); @@ -234,13 +234,13 @@ class DownloadCommand extends BaseCommand $find = str_replace(['{name}', '{arch}', '{os}'], [$source, arch2gnu(php_uname('m')), strtolower(PHP_OS_FAMILY)], Config::getPreBuilt('match-pattern')); // find filename in asset list if (($url = $this->findPreBuilt($pre_built_libs, $find)) !== null) { - logger()->info("Fetching pre-built content {$source} [{$ni}/{$cnt}]"); + logger()->info("[{$ni}/{$cnt}] Downloading pre-built content {$source}"); Downloader::downloadSource($source, ['type' => 'url', 'url' => $url], $force_all || in_array($source, $force_list), SPC_LOCK_PRE_BUILT); continue; } logger()->warning("Pre-built content not found for {$source}, fallback to source download"); } - logger()->info("Fetching source {$source} [{$ni}/{$cnt}]"); + logger()->info("[{$ni}/{$cnt}] Downloading source {$source}"); Downloader::downloadSource($source, $config, $force_all || in_array($source, $force_list)); } } diff --git a/src/SPC/store/Downloader.php b/src/SPC/store/Downloader.php index 5d91f2cd..6ac272e4 100644 --- a/src/SPC/store/Downloader.php +++ b/src/SPC/store/Downloader.php @@ -284,8 +284,22 @@ class Downloader } /** + * @param string $name Package name + * @param null|array{ + * type: string, + * repo: ?string, + * url: ?string, + * rev: ?string, + * path: ?string, + * filename: ?string, + * match: ?string, + * prefer-stable: ?bool, + * extract-files: ?array + * } $pkg Package config + * @param bool $force Download all the time even if it exists * @throws DownloaderException * @throws FileSystemException + * @throws WrongUsageException */ public static function downloadPackage(string $name, ?array $pkg = null, bool $force = false): void { @@ -383,8 +397,23 @@ class Downloader /** * Download source by name and meta. * - * @param string $name source name - * @param null|array $source source meta info: [type, path, rev, url, filename, regex, license] + * @param string $name source name + * @param null|array{ + * type: string, + * repo: ?string, + * url: ?string, + * rev: ?string, + * path: ?string, + * filename: ?string, + * match: ?string, + * prefer-stable: ?bool, + * provide-pre-built: ?bool, + * license: array{ + * type: string, + * path: ?string, + * text: ?string + * } + * } $source source meta info: [type, path, rev, url, filename, regex, license] * @param bool $force Whether to force download (default: false) * @param int $lock_as Lock source type (default: SPC_LOCK_SOURCE) * @throws DownloaderException @@ -415,11 +444,11 @@ class Downloader // If lock file exists, skip downloading if (isset($lock[$name]) && !$force && ($lock[$name]['lock_as'] ?? SPC_LOCK_SOURCE) === $lock_as) { if ($lock[$name]['source_type'] === 'archive' && file_exists(DOWNLOAD_PATH . '/' . $lock[$name]['filename'])) { - logger()->notice("source [{$name}] already downloaded: " . $lock[$name]['filename']); + logger()->notice("Source [{$name}] already downloaded: " . $lock[$name]['filename']); return; } if ($lock[$name]['source_type'] === 'dir' && is_dir(DOWNLOAD_PATH . '/' . $lock[$name]['dirname'])) { - logger()->notice("source [{$name}] already downloaded: " . $lock[$name]['dirname']); + logger()->notice("Source [{$name}] already downloaded: " . $lock[$name]['dirname']); return; } }