diff --git a/add.ce b/add.ce index ba2ce584..1278f0f8 100644 --- a/add.ce +++ b/add.ce @@ -21,111 +21,115 @@ var added = 0 var failed = 0 var _add_dep = null var _install = null +var i = 0 -array(args, function(arg) { - if (arg == '--help' || arg == '-h') { +var run = function() { + for (i = 0; i < length(args); i++) { + if (args[i] == '--help' || args[i] == '-h') { + log.console("Usage: cell add [alias]") + log.console("") + log.console("Add a dependency to the current package.") + log.console("") + log.console("Examples:") + log.console(" cell add gitea.pockle.world/john/prosperon") + log.console(" cell add gitea.pockle.world/john/cell-image image") + log.console(" cell add ../local-package") + log.console(" cell add -r ../packages") + return + } else if (args[i] == '-r') { + recursive = true + } else if (!starts_with(args[i], '-')) { + if (!locator) { + locator = args[i] + } else if (!alias) { + alias = args[i] + } + } + } + + if (!locator && !recursive) { log.console("Usage: cell add [alias]") - log.console("") - log.console("Add a dependency to the current package.") - log.console("") - log.console("Examples:") - log.console(" cell add gitea.pockle.world/john/prosperon") - log.console(" cell add gitea.pockle.world/john/cell-image image") - log.console(" cell add ../local-package") - log.console(" cell add -r ../packages") - $stop() - } else if (arg == '-r') { - recursive = true - } else if (!starts_with(arg, '-')) { - if (!locator) { - locator = arg - } else if (!alias) { - alias = arg + return + } + + if (locator) + locator = shop.resolve_locator(locator) + + // Generate default alias from locator + if (!alias && locator) { + parts = array(locator, '/') + alias = parts[length(parts) - 1] + if (search(alias, '@') != null) + alias = array(alias, '@')[0] + } + + // Check we're in a package directory + if (!fd.is_file(cwd + '/cell.toml')) { + log.error("Not in a package directory (no cell.toml found)") + return + } + + // Recursive mode + if (recursive) { + if (!locator) locator = '.' + locator = shop.resolve_locator(locator) + if (!fd.is_dir(locator)) { + log.error(`${locator} is not a directory`) + return } - } -}) - -if (!locator && !recursive) { - log.console("Usage: cell add [alias]") - $stop() -} - -if (locator) - locator = shop.resolve_locator(locator) - -// Generate default alias from locator -if (!alias && locator) { - parts = array(locator, '/') - alias = parts[length(parts) - 1] - if (search(alias, '@') != null) - alias = array(alias, '@')[0] -} - -// Check we're in a package directory -if (!fd.is_file(cwd + '/cell.toml')) { - log.error("Not in a package directory (no cell.toml found)") - $stop() -} - -// Recursive mode -if (recursive) { - if (!locator) locator = '.' - locator = shop.resolve_locator(locator) - if (!fd.is_dir(locator)) { - log.error(`${locator} is not a directory`) - $stop() - } - locators = filter(pkg.find_packages(locator), function(p) { - return p != cwd - }) - if (length(locators) == 0) { - log.console("No packages found in " + locator) - $stop() - } - log.console(`Found ${text(length(locators))} package(s) in ${locator}`) - - added = 0 - failed = 0 - arrfor(locators, function(loc) { - var loc_parts = array(loc, '/') - var loc_alias = loc_parts[length(loc_parts) - 1] - log.console(" Adding " + loc + " as '" + loc_alias + "'...") - var _add = function() { - pkg.add_dependency(null, loc, loc_alias) - shop.sync(loc) - added = added + 1 - } disruption { - log.console(` Warning: Failed to add ${loc}`) - failed = failed + 1 + locators = filter(pkg.find_packages(locator), function(p) { + return p != cwd + }) + if (length(locators) == 0) { + log.console("No packages found in " + locator) + return } - _add() - }) + log.console(`Found ${text(length(locators))} package(s) in ${locator}`) - log.console("Added " + text(added) + " package(s)." + (failed > 0 ? " Failed: " + text(failed) + "." : "")) - $stop() + added = 0 + failed = 0 + arrfor(locators, function(loc) { + var loc_parts = array(loc, '/') + var loc_alias = loc_parts[length(loc_parts) - 1] + log.console(" Adding " + loc + " as '" + loc_alias + "'...") + var _add = function() { + pkg.add_dependency(null, loc, loc_alias) + shop.sync(loc) + added = added + 1 + } disruption { + log.console(` Warning: Failed to add ${loc}`) + failed = failed + 1 + } + _add() + }) + + log.console("Added " + text(added) + " package(s)." + (failed > 0 ? " Failed: " + text(failed) + "." : "")) + return + } + + // Single package add + log.console("Adding " + locator + " as '" + alias + "'...") + + _add_dep = function() { + pkg.add_dependency(null, locator, alias) + log.console(" Added to cell.toml") + } disruption { + log.error("Failed to update cell.toml") + return + } + _add_dep() + + _install = function() { + shop.sync_with_deps(locator) + log.console(" Installed to shop") + } disruption { + log.error("Failed to install") + return + } + _install() + + log.console("Added " + alias + " (" + locator + ")") } - -// Single package add -log.console("Adding " + locator + " as '" + alias + "'...") - -_add_dep = function() { - pkg.add_dependency(null, locator, alias) - log.console(" Added to cell.toml") -} disruption { - log.error("Failed to update cell.toml") - $stop() -} -_add_dep() - -_install = function() { - shop.sync_with_deps(locator) - log.console(" Installed to shop") -} disruption { - log.error("Failed to install") - $stop() -} -_install() - -log.console("Added " + alias + " (" + locator + ")") +run() $stop() diff --git a/audit.ce b/audit.ce index 948f76db..33a5d9f3 100644 --- a/audit.ce +++ b/audit.ce @@ -14,17 +14,18 @@ var pkg = use('package') var target_package = null var i = 0 -for (i = 0; i < length(args); i++) { - if (args[i] == '--help' || args[i] == '-h') { - log.console("Usage: cell audit []") - log.console("") - log.console("Test-compile all .ce and .cm scripts in package(s).") - log.console("Reports all errors without stopping at the first failure.") - $stop() - } else if (!starts_with(args[i], '-')) { - target_package = args[i] +var run = function() { + for (i = 0; i < length(args); i++) { + if (args[i] == '--help' || args[i] == '-h') { + log.console("Usage: cell audit []") + log.console("") + log.console("Test-compile all .ce and .cm scripts in package(s).") + log.console("Reports all errors without stopping at the first failure.") + return + } else if (!starts_with(args[i], '-')) { + target_package = args[i] + } } -} // Resolve local paths if (target_package) { @@ -68,5 +69,7 @@ if (length(all_failures) > 0) { } log.console("Audit complete: " + text(total_ok) + "/" + text(total_scripts) + " scripts compiled" + (total_errors > 0 ? ", " + text(total_errors) + " failed" : "")) +} +run() $stop() diff --git a/build.ce b/build.ce index fd025aa3..3f7aebc4 100644 --- a/build.ce +++ b/build.ce @@ -27,51 +27,52 @@ var results = null var success = 0 var failed = 0 -for (i = 0; i < length(args); i++) { - if (args[i] == '-t' || args[i] == '--target') { - if (i + 1 < length(args)) { - target = args[++i] - } else { - log.error('-t requires a target') - $stop() - } - } else if (args[i] == '-p' || args[i] == '--package') { - // Legacy support for -p flag - if (i + 1 < length(args)) { - target_package = args[++i] - } else { - log.error('-p requires a package name') - $stop() - } - } else if (args[i] == '-b' || args[i] == '--buildtype') { - if (i + 1 < length(args)) { - buildtype = args[++i] - if (buildtype != 'release' && buildtype != 'debug' && buildtype != 'minsize') { - log.error('Invalid buildtype: ' + buildtype + '. Must be release, debug, or minsize') - $stop() +var run = function() { + for (i = 0; i < length(args); i++) { + if (args[i] == '-t' || args[i] == '--target') { + if (i + 1 < length(args)) { + target = args[++i] + } else { + log.error('-t requires a target') + return } - } else { - log.error('-b requires a buildtype (release, debug, minsize)') - $stop() + } else if (args[i] == '-p' || args[i] == '--package') { + // Legacy support for -p flag + if (i + 1 < length(args)) { + target_package = args[++i] + } else { + log.error('-p requires a package name') + return + } + } else if (args[i] == '-b' || args[i] == '--buildtype') { + if (i + 1 < length(args)) { + buildtype = args[++i] + if (buildtype != 'release' && buildtype != 'debug' && buildtype != 'minsize') { + log.error('Invalid buildtype: ' + buildtype + '. Must be release, debug, or minsize') + return + } + } else { + log.error('-b requires a buildtype (release, debug, minsize)') + return + } + } else if (args[i] == '--force') { + force_rebuild = true + } else if (args[i] == '--verbose' || args[i] == '-v') { + verbose = true + } else if (args[i] == '--dry-run') { + dry_run = true + } else if (args[i] == '--list-targets') { + log.console('Available targets:') + targets = build.list_targets() + for (t = 0; t < length(targets); t++) { + log.console(' ' + targets[t]) + } + return + } else if (!starts_with(args[i], '-') && !target_package) { + // Positional argument - treat as package locator + target_package = args[i] } - } else if (args[i] == '--force') { - force_rebuild = true - } else if (args[i] == '--verbose' || args[i] == '-v') { - verbose = true - } else if (args[i] == '--dry-run') { - dry_run = true - } else if (args[i] == '--list-targets') { - log.console('Available targets:') - targets = build.list_targets() - for (t = 0; t < length(targets); t++) { - log.console(' ' + targets[t]) - } - $stop() - } else if (!starts_with(args[i], '-') && !target_package) { - // Positional argument - treat as package locator - target_package = args[i] } -} if (target_package) target_package = shop.resolve_locator(target_package) @@ -82,11 +83,11 @@ if (!target) { if (target) log.console('Target: ' + target) } -if (target && !build.has_target(target)) { - log.error('Invalid target: ' + target) - log.console('Available targets: ' + text(build.list_targets(), ', ')) - $stop() -} + if (target && !build.has_target(target)) { + log.error('Invalid target: ' + target) + log.console('Available targets: ' + text(build.list_targets(), ', ')) + return + } var packages = shop.list_packages() arrfor(packages, function(package) { @@ -123,5 +124,7 @@ if (target_package) { log.console(`Build complete: ${success} libraries built${failed > 0 ? `, ${failed} failed` : ''}`) } +} +run() $stop() diff --git a/clean.ce b/clean.ce index 9b5cceed..83b7c260 100644 --- a/clean.ce +++ b/clean.ce @@ -26,39 +26,40 @@ var dry_run = false var i = 0 var deps = null -for (i = 0; i < length(args); i++) { - if (args[i] == '--build') { - clean_build = true - } else if (args[i] == '--fetch') { - clean_fetch = true - } else if (args[i] == '--all') { - clean_build = true - clean_fetch = true - } else if (args[i] == '--deep') { - deep = true - } else if (args[i] == '--dry-run') { - dry_run = true - } else if (args[i] == '--help' || args[i] == '-h') { - log.console("Usage: cell clean [] [options]") - log.console("") - log.console("Remove cached material to force refetch/rebuild.") - log.console("") - log.console("Scopes:") - log.console(" Clean specific package") - log.console(" shop Clean entire shop") - log.console(" world Clean all world packages") - log.console("") - log.console("Options:") - log.console(" --build Remove build outputs only (default)") - log.console(" --fetch Remove fetched sources only") - log.console(" --all Remove both build outputs and fetched sources") - log.console(" --deep Apply to full dependency closure") - log.console(" --dry-run Show what would be deleted") - $stop() - } else if (!starts_with(args[i], '-')) { - scope = args[i] +var run = function() { + for (i = 0; i < length(args); i++) { + if (args[i] == '--build') { + clean_build = true + } else if (args[i] == '--fetch') { + clean_fetch = true + } else if (args[i] == '--all') { + clean_build = true + clean_fetch = true + } else if (args[i] == '--deep') { + deep = true + } else if (args[i] == '--dry-run') { + dry_run = true + } else if (args[i] == '--help' || args[i] == '-h') { + log.console("Usage: cell clean [] [options]") + log.console("") + log.console("Remove cached material to force refetch/rebuild.") + log.console("") + log.console("Scopes:") + log.console(" Clean specific package") + log.console(" shop Clean entire shop") + log.console(" world Clean all world packages") + log.console("") + log.console("Options:") + log.console(" --build Remove build outputs only (default)") + log.console(" --fetch Remove fetched sources only") + log.console(" --all Remove both build outputs and fetched sources") + log.console(" --deep Apply to full dependency closure") + log.console(" --dry-run Show what would be deleted") + return + } else if (!starts_with(args[i], '-')) { + scope = args[i] + } } -} // Default to --build if nothing specified if (!clean_build && !clean_fetch) { @@ -190,5 +191,7 @@ if (dry_run) { log.console("Clean complete: " + text(deleted_count) + " item(s) deleted.") } } +} +run() $stop() diff --git a/clone.ce b/clone.ce index 366e5407..b5211e63 100644 --- a/clone.ce +++ b/clone.ce @@ -7,11 +7,12 @@ var fd = use('fd') var http = use('http') var miniz = use('miniz') -if (length(args) < 2) { - log.console("Usage: cell clone ") - log.console("Clones a cell package to a local path and links it.") - $stop() -} +var run = function() { + if (length(args) < 2) { + log.console("Usage: cell clone ") + log.console("Clones a cell package to a local path and links it.") + return + } var origin = args[0] var target_path = args[1] @@ -20,34 +21,34 @@ var target_path = args[1] target_path = shop.resolve_locator(target_path) // Check if target already exists -if (fd.is_dir(target_path)) { - log.console("Error: " + target_path + " already exists") - $stop() -} + if (fd.is_dir(target_path)) { + log.console("Error: " + target_path + " already exists") + return + } log.console("Cloning " + origin + " to " + target_path + "...") // Get the latest commit var info = shop.resolve_package_info(origin) -if (!info || info == 'local') { - log.console("Error: " + origin + " is not a remote package") - $stop() -} + if (!info || info == 'local') { + log.console("Error: " + origin + " is not a remote package") + return + } // Update to get the commit hash var update_result = shop.update(origin) -if (!update_result) { - log.console("Error: Could not fetch " + origin) - $stop() -} + if (!update_result) { + log.console("Error: Could not fetch " + origin) + return + } // Fetch and extract to the target path var lock = shop.load_lock() var entry = lock[origin] -if (!entry || !entry.commit) { - log.console("Error: No commit found for " + origin) - $stop() -} + if (!entry || !entry.commit) { + log.console("Error: No commit found for " + origin) + return + } var download_url = shop.get_download_url(origin, entry.commit) log.console("Downloading from " + download_url) @@ -69,7 +70,7 @@ var _clone = function() { zip = miniz.read(zip_blob) if (!zip) { log.console("Error: Failed to read zip archive") - $stop() + return } // Create target directory @@ -102,6 +103,8 @@ var _clone = function() { } disruption { log.console("Error during clone") } -_clone() + _clone() +} +run() $stop() diff --git a/fetch.ce b/fetch.ce index f2b5c45a..89f653b7 100644 --- a/fetch.ce +++ b/fetch.ce @@ -14,33 +14,36 @@ var i = 0 var packages = null var count = 0 -for (i = 0; i < length(args); i++) { - if (args[i] == '--help' || args[i] == '-h') { - log.console("Usage: cell fetch [package]") - log.console("Sync packages from remote sources.") - log.console("") - log.console("Arguments:") - log.console(" package Optional package to sync. If omitted, syncs all.") - $stop() - } else if (!starts_with(args[i], '-')) { - target_pkg = args[i] +var run = function() { + for (i = 0; i < length(args); i++) { + if (args[i] == '--help' || args[i] == '-h') { + log.console("Usage: cell fetch [package]") + log.console("Sync packages from remote sources.") + log.console("") + log.console("Arguments:") + log.console(" package Optional package to sync. If omitted, syncs all.") + return + } else if (!starts_with(args[i], '-')) { + target_pkg = args[i] + } + } + + if (target_pkg) { + target_pkg = shop.resolve_locator(target_pkg) + log.console("Syncing " + target_pkg + "...") + shop.sync(target_pkg) + log.console("Done.") + } else { + packages = shop.list_packages() + count = 0 + arrfor(packages, function(pkg) { + if (pkg == 'core') return + shop.sync(pkg) + count = count + 1 + }) + log.console("Synced " + text(count) + " package(s).") } } - -if (target_pkg) { - target_pkg = shop.resolve_locator(target_pkg) - log.console("Syncing " + target_pkg + "...") - shop.sync(target_pkg) - log.console("Done.") -} else { - packages = shop.list_packages() - count = 0 - arrfor(packages, function(pkg) { - if (pkg == 'core') return - shop.sync(pkg) - count = count + 1 - }) - log.console("Synced " + text(count) + " package(s).") -} +run() $stop() diff --git a/graph.ce b/graph.ce index e8eb2cea..7bc87971 100644 --- a/graph.ce +++ b/graph.ce @@ -23,39 +23,40 @@ var show_locked = false var show_world = false var i = 0 -for (i = 0; i < length(args); i++) { - if (args[i] == '--format' || args[i] == '-f') { - if (i + 1 < length(args)) { - format = args[++i] - if (format != 'tree' && format != 'dot' && format != 'json') { - log.error('Invalid format: ' + format + '. Must be tree, dot, or json') - $stop() +var run = function() { + for (i = 0; i < length(args); i++) { + if (args[i] == '--format' || args[i] == '-f') { + if (i + 1 < length(args)) { + format = args[++i] + if (format != 'tree' && format != 'dot' && format != 'json') { + log.error('Invalid format: ' + format + '. Must be tree, dot, or json') + return + } + } else { + log.error('--format requires a format type') + return } - } else { - log.error('--format requires a format type') - $stop() + } else if (args[i] == '--resolved') { + show_locked = false + } else if (args[i] == '--locked') { + show_locked = true + } else if (args[i] == '--world') { + show_world = true + } else if (args[i] == '--help' || args[i] == '-h') { + log.console("Usage: cell graph [] [options]") + log.console("") + log.console("Emit the dependency graph.") + log.console("") + log.console("Options:") + log.console(" --format Output format: tree (default), dot, json") + log.console(" --resolved Show resolved view with links applied (default)") + log.console(" --locked Show lock view without links") + log.console(" --world Graph all packages in shop") + return + } else if (!starts_with(args[i], '-')) { + target_locator = args[i] } - } else if (args[i] == '--resolved') { - show_locked = false - } else if (args[i] == '--locked') { - show_locked = true - } else if (args[i] == '--world') { - show_world = true - } else if (args[i] == '--help' || args[i] == '-h') { - log.console("Usage: cell graph [] [options]") - log.console("") - log.console("Emit the dependency graph.") - log.console("") - log.console("Options:") - log.console(" --format Output format: tree (default), dot, json") - log.console(" --resolved Show resolved view with links applied (default)") - log.console(" --locked Show lock view without links") - log.console(" --world Graph all packages in shop") - $stop() - } else if (!starts_with(args[i], '-')) { - target_locator = args[i] } -} var links = show_locked ? {} : link.load() @@ -236,5 +237,7 @@ if (format == 'tree') { log.console(json.encode(output)) } +} +run() $stop() diff --git a/install.ce b/install.ce index 41deb8df..2e76fc0b 100644 --- a/install.ce +++ b/install.ce @@ -24,37 +24,38 @@ var lock = null var installed = 0 var failed = 0 -for (i = 0; i < length(args); i++) { - if (args[i] == '--target' || args[i] == '-t') { - if (i + 1 < length(args)) { - target_triple = args[++i] - } else { - log.error('--target requires a triple') - $stop() +var run = function() { + for (i = 0; i < length(args); i++) { + if (args[i] == '--target' || args[i] == '-t') { + if (i + 1 < length(args)) { + target_triple = args[++i] + } else { + log.error('--target requires a triple') + return + } + } else if (args[i] == '--dry-run') { + dry_run = true + } else if (args[i] == '-r') { + recursive = true + } else if (args[i] == '--help' || args[i] == '-h') { + log.console("Usage: cell install [options]") + log.console("") + log.console("Install a package and its dependencies.") + log.console("") + log.console("Options:") + log.console(" --target Build for target platform") + log.console(" --dry-run Show what would be installed") + log.console(" -r Recursively find and install all packages in directory") + return + } else if (!starts_with(args[i], '-')) { + locator = args[i] } - } else if (args[i] == '--dry-run') { - dry_run = true - } else if (args[i] == '-r') { - recursive = true - } else if (args[i] == '--help' || args[i] == '-h') { - log.console("Usage: cell install [options]") - log.console("") - log.console("Install a package and its dependencies.") - log.console("") - log.console("Options:") - log.console(" --target Build for target platform") - log.console(" --dry-run Show what would be installed") - log.console(" -r Recursively find and install all packages in directory") - $stop() - } else if (!starts_with(args[i], '-')) { - locator = args[i] } -} -if (!locator && !recursive) { - log.console("Usage: cell install [options]") - $stop() -} + if (!locator && !recursive) { + log.console("Usage: cell install [options]") + return + } if (locator) locator = shop.resolve_locator(locator) @@ -65,14 +66,14 @@ if (recursive) { locator = shop.resolve_locator(locator) if (!fd.is_dir(locator)) { log.error(`${locator} is not a directory`) - $stop() + return } locators = filter(pkg.find_packages(locator), function(p) { return p != cwd }) if (length(locators) == 0) { log.console("No packages found in " + locator) - $stop() + return } log.console(`Found ${text(length(locators))} package(s) in ${locator}`) @@ -82,35 +83,36 @@ if (recursive) { lock = shop.load_lock() log.console(" " + loc + (lock[loc] ? " (already installed)" : "")) }) - $stop() + } else { + installed = 0 + failed = 0 + arrfor(locators, function(loc) { + log.console(" Installing " + loc + "...") + var _inst = function() { + shop.sync(loc, {target: target_triple}) + installed = installed + 1 + } disruption { + failed = failed + 1 + log.console(` Warning: Failed to install ${loc}`) + } + _inst() + }) + + log.console("Installed " + text(installed) + " package(s)." + (failed > 0 ? " Failed: " + text(failed) + "." : "")) + } + return +} + + // Single package install with dependencies + if (dry_run) { + log.console("Would install: " + locator + " (and dependencies)") + return } - installed = 0 - failed = 0 - arrfor(locators, function(loc) { - log.console(" Installing " + loc + "...") - var _inst = function() { - shop.sync(loc, {target: target_triple}) - installed = installed + 1 - } disruption { - failed = failed + 1 - log.console(` Warning: Failed to install ${loc}`) - } - _inst() - }) - - log.console("Installed " + text(installed) + " package(s)." + (failed > 0 ? " Failed: " + text(failed) + "." : "")) - $stop() + log.console("Installing " + locator + "...") + shop.sync_with_deps(locator, {refresh: true, target: target_triple}) + log.console("Done.") } - -// Single package install with dependencies -if (dry_run) { - log.console("Would install: " + locator + " (and dependencies)") - $stop() -} - -log.console("Installing " + locator + "...") -shop.sync_with_deps(locator, {refresh: true, target: target_triple}) -log.console("Done.") +run() $stop() diff --git a/link.ce b/link.ce index 234c0c65..0f766e0e 100644 --- a/link.ce +++ b/link.ce @@ -34,17 +34,18 @@ var _restore = null var _read_toml = null var _add_link = null -if (length(args) < 1) { - log.console("Usage: link [args] or link [package] ") - log.console("Commands:") - log.console(" list List all active links") - log.console(" sync Ensure all symlinks are in place") - log.console(" delete Remove a link and restore original") - log.console(" clear Remove all links") - log.console(" Link the package in to that path") - log.console(" Link to (path or package)") - $stop() -} +var run = function() { + if (length(args) < 1) { + log.console("Usage: link [args] or link [package] ") + log.console("Commands:") + log.console(" list List all active links") + log.console(" sync Ensure all symlinks are in place") + log.console(" delete Remove a link and restore original") + log.console(" clear Remove all links") + log.console(" Link the package in to that path") + log.console(" Link to (path or package)") + return + } cmd = args[0] @@ -71,7 +72,7 @@ if (cmd == 'list') { } else if (cmd == 'delete' || cmd == 'rm') { if (length(args) < 2) { log.console("Usage: link delete ") - $stop() + return } pkg = args[1] @@ -113,7 +114,7 @@ if (cmd == 'list') { if (!arg1) { log.console("Error: target or package required") - $stop() + return } if (arg2) { @@ -136,7 +137,7 @@ if (cmd == 'list') { if (!fd.is_file(toml_path)) { log.console("Error: No cell.toml found at " + target) log.console("For linking to another package, use: link ") - $stop() + return } // Read package name from cell.toml @@ -159,7 +160,7 @@ if (cmd == 'list') { if (starts_with(target, '/')) { if (!fd.is_file(target + '/cell.toml')) { log.console("Error: " + target + " is not a valid package (no cell.toml)") - $stop() + return } } @@ -172,5 +173,7 @@ if (cmd == 'list') { } _add_link() } +} +run() $stop() diff --git a/list.ce b/list.ce index 283c6e82..362b95b2 100644 --- a/list.ce +++ b/list.ce @@ -18,31 +18,32 @@ var local_pkgs = null var linked_pkgs = null var remote_pkgs = null -if (args && length(args) > 0) { - if (args[0] == 'shop') { - mode = 'shop' - } else if (args[0] == '--help' || args[0] == '-h') { - log.console("Usage: cell list []") - log.console("") - log.console("List packages and dependencies.") - log.console("") - log.console("Scopes:") - log.console(" (none) List dependencies of current package") - log.console(" shop List all packages in shop with status") - log.console(" List dependency tree for a package") - $stop() - } else { - mode = 'package' - target_pkg = args[0] +var run = function() { + if (args && length(args) > 0) { + if (args[0] == 'shop') { + mode = 'shop' + } else if (args[0] == '--help' || args[0] == '-h') { + log.console("Usage: cell list []") + log.console("") + log.console("List packages and dependencies.") + log.console("") + log.console("Scopes:") + log.console(" (none) List dependencies of current package") + log.console(" shop List all packages in shop with status") + log.console(" List dependency tree for a package") + return + } else { + mode = 'package' + target_pkg = args[0] - target_pkg = shop.resolve_locator(target_pkg) + target_pkg = shop.resolve_locator(target_pkg) + } } -} -var links = link.load() -var lock = shop.load_lock() + var links = link.load() + var lock = shop.load_lock() -function print_deps(ctx, raw_indent) { + function print_deps(ctx, raw_indent) { var aliases = null var indent = raw_indent || "" deps = null @@ -173,5 +174,7 @@ if (mode == 'local') { log.console("Total: " + text(length(packages)) + " package(s)") } } +} +run() $stop() diff --git a/remove.ce b/remove.ce index a7f31e9b..30d55391 100644 --- a/remove.ce +++ b/remove.ce @@ -18,29 +18,30 @@ var prune = false var dry_run = false var i = 0 -for (i = 0; i < length(args); i++) { - if (args[i] == '--prune') { - prune = true - } else if (args[i] == '--dry-run') { - dry_run = true - } else if (args[i] == '--help' || args[i] == '-h') { - log.console("Usage: cell remove [options]") - log.console("") - log.console("Remove a package from the shop.") - log.console("") - log.console("Options:") - log.console(" --prune Also remove packages no longer needed by any root") - log.console(" --dry-run Show what would be removed") - $stop() - } else if (!starts_with(args[i], '-')) { - target_pkg = args[i] +var run = function() { + for (i = 0; i < length(args); i++) { + if (args[i] == '--prune') { + prune = true + } else if (args[i] == '--dry-run') { + dry_run = true + } else if (args[i] == '--help' || args[i] == '-h') { + log.console("Usage: cell remove [options]") + log.console("") + log.console("Remove a package from the shop.") + log.console("") + log.console("Options:") + log.console(" --prune Also remove packages no longer needed by any root") + log.console(" --dry-run Show what would be removed") + return + } else if (!starts_with(args[i], '-')) { + target_pkg = args[i] + } } -} -if (!target_pkg) { - log.console("Usage: cell remove [options]") - $stop() -} + if (!target_pkg) { + log.console("Usage: cell remove [options]") + return + } target_pkg = shop.resolve_locator(target_pkg) @@ -100,5 +101,7 @@ if (dry_run) { log.console("Removed " + text(length(packages_to_remove)) + " package(s).") } +} +run() $stop() diff --git a/resolve.ce b/resolve.ce index c69d787b..e2e94a22 100644 --- a/resolve.ce +++ b/resolve.ce @@ -22,32 +22,33 @@ var show_locked = false var refresh_first = false var i = 0 -for (i = 0; i < length(args); i++) { - if (args[i] == '--target' || args[i] == '-t') { - if (i + 1 < length(args)) { - target_triple = args[++i] - } else { - log.error('--target requires a triple') - $stop() +var run = function() { + for (i = 0; i < length(args); i++) { + if (args[i] == '--target' || args[i] == '-t') { + if (i + 1 < length(args)) { + target_triple = args[++i] + } else { + log.error('--target requires a triple') + return + } + } else if (args[i] == '--locked') { + show_locked = true + } else if (args[i] == '--refresh') { + refresh_first = true + } else if (args[i] == '--help' || args[i] == '-h') { + log.console("Usage: cell resolve [] [options]") + log.console("") + log.console("Print the fully resolved dependency closure.") + log.console("") + log.console("Options:") + log.console(" --target Annotate builds for target platform") + log.console(" --locked Show lock state without applying links") + log.console(" --refresh Refresh floating refs before printing") + return + } else if (!starts_with(args[i], '-')) { + target_locator = args[i] } - } else if (args[i] == '--locked') { - show_locked = true - } else if (args[i] == '--refresh') { - refresh_first = true - } else if (args[i] == '--help' || args[i] == '-h') { - log.console("Usage: cell resolve [] [options]") - log.console("") - log.console("Print the fully resolved dependency closure.") - log.console("") - log.console("Options:") - log.console(" --target Annotate builds for target platform") - log.console(" --locked Show lock state without applying links") - log.console(" --refresh Refresh floating refs before printing") - $stop() - } else if (!starts_with(args[i], '-')) { - target_locator = args[i] } -} // Default to current directory if (!target_locator) { @@ -57,16 +58,16 @@ if (!target_locator) { // Resolve local paths target_locator = shop.resolve_locator(target_locator) -// Check if it's a valid package -var pkg_dir = null -if (!fd.is_file(target_locator + '/cell.toml')) { - // Try to find it in the shop - pkg_dir = shop.get_package_dir(target_locator) - if (!fd.is_file(pkg_dir + '/cell.toml')) { - log.error("Not a valid package: " + target_locator) - $stop() + // Check if it's a valid package + var pkg_dir = null + if (!fd.is_file(target_locator + '/cell.toml')) { + // Try to find it in the shop + pkg_dir = shop.get_package_dir(target_locator) + if (!fd.is_file(pkg_dir + '/cell.toml')) { + log.error("Not a valid package: " + target_locator) + return + } } -} // Detect target if not specified if (!target_triple) { @@ -210,7 +211,9 @@ for (i = 0; i < length(sorted); i++) { } } -log.console("") -log.console("Total: " + text(length(sorted)) + " package(s)") + log.console("") + log.console("Total: " + text(length(sorted)) + " package(s)") +} +run() $stop() diff --git a/update.ce b/update.ce index db653ac7..fc8f5325 100644 --- a/update.ce +++ b/update.ce @@ -23,25 +23,26 @@ var i = 0 var updated = 0 var packages = null -for (i = 0; i < length(args); i++) { - if (args[i] == '--help' || args[i] == '-h') { - log.console("Usage: cell update [] [options]") - log.console("") - log.console("Update packages from remote sources.") - log.console("") - log.console("Options:") - log.console(" --target Target platform for build") - log.console(" --follow-links Update link targets instead of origins") - log.console(" --git Run git pull on local packages") - $stop() - } else if (args[i] == '--target' || args[i] == '-t') { - if (i + 1 < length(args)) { - target_triple = args[++i] - } else { - log.error('--target requires a triple') - $stop() - } - } else if (args[i] == '--follow-links') { +var run = function() { + for (i = 0; i < length(args); i++) { + if (args[i] == '--help' || args[i] == '-h') { + log.console("Usage: cell update [] [options]") + log.console("") + log.console("Update packages from remote sources.") + log.console("") + log.console("Options:") + log.console(" --target Target platform for build") + log.console(" --follow-links Update link targets instead of origins") + log.console(" --git Run git pull on local packages") + return + } else if (args[i] == '--target' || args[i] == '-t') { + if (i + 1 < length(args)) { + target_triple = args[++i] + } else { + log.error('--target requires a triple') + return + } + } else if (args[i] == '--follow-links') { follow_links = true } else if (args[i] == '--git') { git_pull = true @@ -113,5 +114,7 @@ if (target_pkg) { log.console("All packages are up to date.") } } +} +run() $stop() diff --git a/verify.ce b/verify.ce index 5e9d2e30..e08bfe3b 100644 --- a/verify.ce +++ b/verify.ce @@ -22,34 +22,35 @@ var deep = false var target_triple = null var i = 0 -for (i = 0; i < length(args); i++) { - if (args[i] == '--deep') { - deep = true - } else if (args[i] == '--target' || args[i] == '-t') { - if (i + 1 < length(args)) { - target_triple = args[++i] - } else { - log.error('--target requires a triple') - $stop() +var run = function() { + for (i = 0; i < length(args); i++) { + if (args[i] == '--deep') { + deep = true + } else if (args[i] == '--target' || args[i] == '-t') { + if (i + 1 < length(args)) { + target_triple = args[++i] + } else { + log.error('--target requires a triple') + return + } + } else if (args[i] == '--help' || args[i] == '-h') { + log.console("Usage: cell verify [] [options]") + log.console("") + log.console("Verify integrity and consistency.") + log.console("") + log.console("Scopes:") + log.console(" Verify specific package") + log.console(" shop Verify entire shop") + log.console(" world Verify all world roots") + log.console("") + log.console("Options:") + log.console(" --deep Traverse full dependency closure") + log.console(" --target Verify builds for specific target") + return + } else if (!starts_with(args[i], '-')) { + scope = args[i] } - } else if (args[i] == '--help' || args[i] == '-h') { - log.console("Usage: cell verify [] [options]") - log.console("") - log.console("Verify integrity and consistency.") - log.console("") - log.console("Scopes:") - log.console(" Verify specific package") - log.console(" shop Verify entire shop") - log.console(" world Verify all world roots") - log.console("") - log.console("Options:") - log.console(" --deep Traverse full dependency closure") - log.console(" --target Verify builds for specific target") - $stop() - } else if (!starts_with(args[i], '-')) { - scope = args[i] } -} // Default to current directory if (!scope) { @@ -250,5 +251,7 @@ if (length(errors) > 0) { } else { log.console("Verification PASSED: " + text(checked) + " package(s) checked, " + text(length(warnings)) + " warning(s)") } +} +run() $stop()