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

View File

@@ -1,17 +1,65 @@
// cell install <locator> - Install a package to the shop
// Does not modify the current project's cell.toml
//
// Usage:
// cell install <locator> Install a package and its dependencies
// cell install . Install current directory package
//
// Options:
// --target <triple> Build for target platform
// --refresh Refresh floating refs before locking
// --dry-run Show what would be installed
var shop = use('internal/shop')
var build = use('build')
var pkg = use('package')
var fd = use('fd')
if (args.length < 1) {
log.console("Usage: cell install <locator>")
log.console("Usage: cell install <locator> [options]")
log.console("")
log.console("Options:")
log.console(" --target <triple> Build for target platform")
log.console(" --refresh Refresh floating refs before locking")
log.console(" --dry-run Show what would be installed")
$stop()
return
}
var locator = args[0]
var locator = null
var target_triple = null
var refresh = false
var dry_run = false
for (var i = 0; i < args.length; i++) {
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] == '--refresh') {
refresh = true
} else if (args[i] == '--dry-run') {
dry_run = true
} else if (args[i] == '--help' || args[i] == '-h') {
log.console("Usage: cell install <locator> [options]")
log.console("")
log.console("Install a package and its dependencies to the shop.")
log.console("")
log.console("Options:")
log.console(" --target <triple> Build for target platform")
log.console(" --refresh Refresh floating refs before locking")
log.console(" --dry-run Show what would be installed")
$stop()
} else if (!args[i].startsWith('-')) {
locator = args[i]
}
}
if (!locator) {
log.console("Usage: cell install <locator>")
$stop()
}
// Resolve relative paths to absolute paths
// Local paths like '.' or '../foo' need to be converted to absolute paths
@@ -22,41 +70,86 @@ if (locator == '.' || locator.startsWith('./') || locator.startsWith('../') || f
}
}
// Default target
if (!target_triple) {
target_triple = build.detect_host_target()
}
log.console("Installing " + locator + "...")
var pkg = use('package')
// Gather all packages that will be installed
var packages_to_install = []
var visited = {}
// Recursive install function that handles dependencies
function install_package(pkg_locator, visited) {
function gather_packages(pkg_locator) {
if (visited[pkg_locator]) return
visited[pkg_locator] = true
// First, add to lock.toml
shop.update(pkg_locator)
// Extract/symlink the package so we can read its cell.toml
shop.extract(pkg_locator)
// Now get direct dependencies and install them first
packages_to_install.push(pkg_locator)
// Try to read dependencies
try {
// For packages not yet extracted, we need to update and extract first to read deps
var lock = shop.load_lock()
if (!lock[pkg_locator]) {
if (!dry_run) {
shop.update(pkg_locator)
shop.extract(pkg_locator)
}
}
var deps = pkg.dependencies(pkg_locator)
if (deps) {
for (var alias in deps) {
var dep_locator = deps[alias]
log.console("Installing dependency " + dep_locator)
install_package(dep_locator, visited)
gather_packages(dep_locator)
}
}
} catch (e) {
// Package might not have dependencies or cell.toml issue
log.console("Warning: Could not read dependencies for " + pkg_locator + ": " + e.message)
if (!dry_run) {
log.console("Warning: Could not read dependencies for " + pkg_locator + ": " + e.message)
}
}
// Build the package after all dependencies are installed
build.build_package(pkg_locator)
}
install_package(locator, {})
log.console("Installed " + locator)
// Gather all packages
gather_packages(locator)
if (dry_run) {
log.console("Would install:")
for (var p of packages_to_install) {
var lock = shop.load_lock()
var exists = lock[p] != null
log.console(" " + p + (exists ? " (already installed)" : ""))
}
$stop()
}
// Install each package
function install_package(pkg_locator) {
// Update lock entry
shop.update(pkg_locator)
// Extract/symlink the package
shop.extract(pkg_locator)
// Build scripts
shop.build_package_scripts(pkg_locator)
// Build C code
try {
build.build_dynamic(pkg_locator, target_triple, 'release')
} catch (e) {
// Not all packages have C code
}
}
for (var p of packages_to_install) {
log.console(" Installing " + p + "...")
install_package(p)
}
log.console("Installed " + text(packages_to_install.length) + " package(s).")
$stop()