Files
cell/fetch.ce
2026-01-16 18:15:29 -06:00

90 lines
2.6 KiB
Plaintext

// cell fetch - Fetch package zips from remote sources
//
// This command ensures that the zip files on disk match what's in the lock file.
// For local packages, this is a no-op.
// For remote packages, downloads the zip if not present or hash mismatch.
//
// Usage:
// cell fetch - Fetch all packages
// cell fetch <package> - Fetch a specific package
var shop = use('internal/shop')
// Parse arguments
var target_pkg = null
for (var i = 0; i < args.length; i++) {
if (args[i] == '--help' || args[i] == '-h') {
log.console("Usage: cell fetch [package]")
log.console("Fetch package zips from remote sources.")
log.console("")
log.console("Arguments:")
log.console(" package Optional package name to fetch. If omitted, fetches all.")
log.console("")
log.console("This command ensures that the zip files on disk match what's in")
log.console("the lock file. For local packages, this is a no-op.")
$stop()
} else if (!starts_with(args[i], '-')) {
target_pkg = args[i]
}
}
var all_packages = shop.list_packages()
var lock = shop.load_lock()
var packages_to_fetch = []
if (target_pkg) {
// Fetch specific package
if (find(all_packages, target_pkg) == null) {
log.error("Package not found: " + target_pkg)
$stop()
}
packages_to_fetch.push(target_pkg)
} else {
// Fetch all packages
packages_to_fetch = all_packages
}
var remote_count = 0
for (var pkg of packages_to_fetch) {
var entry = lock[pkg]
if (pkg != 'core' && (!entry || entry.type != 'local'))
remote_count++
}
if (remote_count > 0)
log.console(`Fetching ${text(remote_count)} remote package(s)...`)
var downloaded_count = 0
var cached_count = 0
var fail_count = 0
for (var pkg of packages_to_fetch) {
// Skip core (handled separately)
if (pkg == 'core') continue
var result = shop.fetch(pkg)
if (result.status == 'local') {
// Local packages are just symlinks, nothing to fetch
continue
} else if (result.status == 'cached') {
cached_count++
} else if (result.status == 'downloaded') {
log.console(" Downloaded: " + pkg)
downloaded_count++
} else if (result.status == 'error') {
log.error(" Failed: " + pkg + (result.message ? " - " + result.message : ""))
fail_count++
}
}
log.console("")
var parts = []
if (downloaded_count > 0) parts.push(`${text(downloaded_count)} downloaded`)
if (cached_count > 0) parts.push(`${text(cached_count)} cached`)
if (fail_count > 0) parts.push(`${text(fail_count)} failed`)
if (parts.length == 0) parts.push("nothing to fetch")
log.console("Fetch complete: " + text(parts, ", "))
$stop()