clean up cmd line

This commit is contained in:
2026-01-09 05:37:37 -06:00
parent 8403883b9d
commit d044bde4f9
12 changed files with 1507 additions and 183 deletions

123
update.ce
View File

@@ -1,30 +1,47 @@
// cell update - Update packages from remote sources
//
// This command checks for updates to all packages and downloads new versions.
// For local packages, ensures the symlink is correct.
// For remote packages, checks the remote for new commits.
// cell update [<locator>] - Update packages from remote sources
//
// Usage:
// cell update - Update all packages
// cell update <package> - Update a specific package
// cell update Update all packages in shop
// cell update . Update current directory package
// cell update <locator> Update a specific package
//
// Options:
// --build Run build after updating
// --target <triple> Target platform for build (requires --build)
// --follow-links Update link targets instead of origins
var shop = use('internal/shop')
var build = use('build')
var fd = use('fd')
var target_pkg = null
var run_build = false
var target_triple = null
var follow_links = false
// Parse arguments
for (var i = 0; i < args.length; i++) {
if (args[i] == '--help' || args[i] == '-h') {
log.console("Usage: cell update [package]")
log.console("Usage: cell update [<locator>] [options]")
log.console("")
log.console("Update packages from remote sources.")
log.console("")
log.console("Arguments:")
log.console(" package Optional package name to update. If omitted, updates all.")
log.console("")
log.console("This command checks for updates to all packages and downloads")
log.console("new versions. For local packages, ensures the symlink is correct.")
log.console("Options:")
log.console(" --build Run build after updating")
log.console(" --target <triple> Target platform for build (requires --build)")
log.console(" --follow-links Update link targets instead of origins")
$stop()
} else if (args[i] == '--build') {
run_build = true
} else if (args[i] == '--target' || args[i] == '-t') {
if (i + 1 < args.length) {
target_triple = args[++i]
} else {
log.error('--target requires a triple')
$stop()
}
} else if (args[i] == '--follow-links') {
follow_links = true
} else if (!args[i].startsWith('-')) {
target_pkg = args[i]
// Resolve relative paths to absolute paths
@@ -37,56 +54,94 @@ for (var i = 0; i < args.length; i++) {
}
}
// Default target if building
if (run_build && !target_triple) {
target_triple = build.detect_host_target()
}
var link = use('link')
function update_and_fetch(pkg)
{
var lock = shop.load_lock()
var old_entry = lock[pkg]
var old_commit = old_entry ? old_entry.commit : null
var new_entry = shop.update(pkg)
// Handle follow-links option
var effective_pkg = pkg
if (follow_links) {
var link_target = link.get_target(pkg)
if (link_target) {
effective_pkg = link_target
log.console(" Following link: " + pkg + " -> " + effective_pkg)
}
}
var new_entry = shop.update(effective_pkg)
if (new_entry) {
if (new_entry.commit) {
var old_str = old_commit ? old_commit.substring(0, 8) : "(new)"
log.console(" " + pkg + " " + old_str + " -> " + new_entry.commit.substring(0, 8))
shop.fetch(pkg)
log.console(" " + effective_pkg + " " + old_str + " -> " + new_entry.commit.substring(0, 8))
shop.fetch(effective_pkg)
} else {
// Local package - just ensure symlink is correct
log.console(" " + pkg + " (local)")
log.console(" " + effective_pkg + " (local)")
}
shop.extract(pkg)
shop.build_package_scripts(pkg)
return true
shop.extract(effective_pkg)
shop.build_package_scripts(effective_pkg)
return effective_pkg
}
return false
return null
}
var updated_packages = []
if (target_pkg) {
if (update_and_fetch(target_pkg))
var updated = update_and_fetch(target_pkg)
if (updated) {
updated_packages.push(updated)
log.console("Updated " + target_pkg + ".")
else
} else {
log.console(target_pkg + " is up to date.")
}
} else {
var packages = shop.list_packages()
var pkg_count = packages.length
log.console("Checking for updates (" + text(pkg_count) + " package" + (pkg_count == 1 ? "" : "s") + ")...")
var updated_count = 0
for (var i = 0; i < packages.length; i++) {
var pkg = packages[i]
if (pkg == 'core') continue
if (update_and_fetch(pkg)) {
updated_count++
var updated = update_and_fetch(pkg)
if (updated) {
updated_packages.push(updated)
}
}
if (updated_count > 0) {
log.console("Updated " + text(updated_count) + " package" + (updated_count == 1 ? "" : "s") + ".")
if (updated_packages.length > 0) {
log.console("Updated " + text(updated_packages.length) + " package" + (updated_packages.length == 1 ? "" : "s") + ".")
} else {
log.console("All packages are up to date.")
}
}
// Run build if requested
if (run_build && updated_packages.length > 0) {
log.console("")
log.console("Building updated packages...")
for (var pkg of updated_packages) {
try {
var lib = build.build_dynamic(pkg, target_triple, 'release')
if (lib) {
log.console(" Built: " + lib)
}
} catch (e) {
log.error(" Failed to build " + pkg + ": " + e)
}
}
}
$stop()