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

215
list.ce
View File

@@ -1,85 +1,170 @@
// list installed packages
// cell list -> list packages installed in this package
// cell list all -> list all packages (including those that are there due to installed packages)
// cell list package <name> -> list the packages for the package <name>
// cell list [<scope>] - List packages and dependencies
//
// Usage:
// cell list List dependencies of current package
// cell list shop List all packages in shop with status
// cell list <locator> List dependency tree for a package
var shop = use('internal/shop')
var pkg = use('package')
var link = use('link')
var fd = use('fd')
var mode = 'local'
var target_pkg = null
if (args && args.length > 0) {
if (args[0] == 'all') {
mode = 'all'
} else if (args[0] == 'shop') {
mode = 'shop'
} else if (args[0] == 'package') {
if (args.length < 2) {
log.console("Usage: cell list package <name>")
$stop()
return
}
mode = 'package'
target_pkg = args[1]
} else {
log.console("Usage:")
log.console(" cell list : list local packages")
log.console(" cell list all : list all recursive packages")
log.console(" cell list package <name>: list dependencies of <name>")
log.console(" cell list shop : list all packages in shop")
$stop()
return
if (args[0] == 'shop') {
mode = 'shop'
} else if (args[0] == '--help' || args[0] == '-h') {
log.console("Usage: cell list [<scope>]")
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(" <locator> List dependency tree for a package")
$stop()
} else {
mode = 'package'
target_pkg = args[0]
// Resolve local paths
if (target_pkg == '.' || target_pkg.startsWith('./') || target_pkg.startsWith('../') || fd.is_dir(target_pkg)) {
var resolved = fd.realpath(target_pkg)
if (resolved) {
target_pkg = resolved
}
}
}
}
var links = link.load()
var lock = shop.load_lock()
function print_deps(ctx, indent) {
indent = indent || ""
var deps
try {
deps = pkg.dependencies(ctx)
} catch (e) {
log.console(indent + " (could not read dependencies)")
return
}
if (!deps) {
log.console(indent + " (none)")
return
}
var aliases = []
for (var k in deps) aliases.push(k)
aliases.sort()
if (aliases.length == 0) {
log.console(indent + " (none)")
return
}
for (var i = 0; i < aliases.length; i++) {
var alias = aliases[i]
var locator = deps[alias]
var link_target = links[locator]
var lock_entry = lock[locator]
var line = indent + " " + alias
if (alias != locator) {
line += " -> " + locator
}
// Add status indicators
var status = []
if (link_target) {
status.push("linked -> " + link_target)
}
if (lock_entry && lock_entry.commit) {
status.push("@" + lock_entry.commit.substring(0, 8))
}
if (lock_entry && lock_entry.type == 'local') {
status.push("local")
}
if (!lock_entry) {
status.push("not installed")
}
if (status.length > 0) {
line += " [" + status.join(", ") + "]"
}
log.console(line)
}
}
if (mode == 'local') {
log.console("Installed Packages (Local):")
print_deps(null)
log.console("Dependencies:")
print_deps(null)
} else if (mode == 'package') {
// Resolve alias to canonical package path
var canon = shop.get_canonical_package(target_pkg, null)
if (!canon) {
log.console("Package '" + target_pkg + "' not found in local dependencies.")
} else {
log.console("Dependencies for " + target_pkg + " (" + canon + "):")
print_deps(canon)
}
} else if (mode == 'all') {
log.console("All Packages:")
var all = shop.list_packages(null)
// list_packages returns an array of package strings (locators)
// We want to perhaps sort them
all.sort()
for (var i = 0; i < all.length; i++) {
log.console(" " + all[i])
}
if (all.length == 0) log.console(" (none)")
log.console("Dependencies for " + target_pkg + ":")
print_deps(target_pkg)
} else if (mode == 'shop') {
log.console("Shop Packages:")
var all = shop.list_packages()
if (all.length == 0)
log.console(" (none)")
else
all.forEach(package => log.console(" " + package))
}
log.console("Shop packages:")
log.console("")
function print_deps(ctx) {
var deps = pkg.dependencies(ctx)
var aliases = []
for (var k in deps) aliases.push(k)
aliases.sort()
var packages = shop.list_packages()
if (packages.length == 0) {
log.console(" (none)")
} else {
packages.sort()
if (aliases.length == 0) {
log.console(" (none)")
} else {
for (var i = 0; i < aliases.length; i++) {
var alias = aliases[i]
var locator = deps[alias]
log.console(" " + alias + " -> " + locator)
}
// Group by type
var local_pkgs = []
var linked_pkgs = []
var remote_pkgs = []
for (var p of packages) {
if (p == 'core') continue
var lock_entry = lock[p]
var link_target = links[p]
if (link_target) {
linked_pkgs.push(p)
} else if (lock_entry && lock_entry.type == 'local') {
local_pkgs.push(p)
} else {
remote_pkgs.push(p)
}
}
if (linked_pkgs.length > 0) {
log.console("Linked packages:")
for (var p of linked_pkgs) {
var target = links[p]
log.console(" " + p + " -> " + target)
}
log.console("")
}
if (local_pkgs.length > 0) {
log.console("Local packages:")
for (var p of local_pkgs) {
log.console(" " + p)
}
log.console("")
}
if (remote_pkgs.length > 0) {
log.console("Remote packages:")
for (var p of remote_pkgs) {
var lock_entry = lock[p]
var commit = lock_entry && lock_entry.commit ? " @" + lock_entry.commit.substring(0, 8) : ""
log.console(" " + p + commit)
}
log.console("")
}
log.console("Total: " + text(packages.length) + " package(s)")
}
}
$stop()