/****************************************************************************** __ ____ __ / / ___ ____ _/ __/_____________ _/ /__ / / / _ \/ __ `/ /_/ ___/ ___/ __ `/ / _ \ / /___/ __/ /_/ / __(__ ) /__/ /_/ / / __/ /_____/\___/\__,_/_/ /____/\___/\__,_/_/\___/ (C)opyright 2025, Leafscale, LLC - https://www.leafscale.com Project: Zygaena Filename: info.reef Authors: Chris Tusa License: Description: Info command - display package information ******************************************************************************/ module commands.info import sys.args import core.str import core.config import core.database import core.port import types import util.color import exitcodes as ec export fn execute(opts: types.GlobalOptions): int end export fn execute(opts: types.GlobalOptions): int let argc = args.count() // Package name should be at cmd_index + 1 if argc <= opts.cmd_index + 1 print_usage() return ec.EXIT_USAGE() end if // Load configuration and apply command-line overrides let base_cfg = config.load() let cfg = config.apply_overrides(base_cfg, opts.root, opts.prefix) let root_path = config.get_root(cfg) // Show root if set (verbose mode) if opts.verbose and str.length(root_path) > 0 color.print_info("Using root: " + root_path) end if let pkg_name = args.get(opts.cmd_index + 1) // Check if installed (use rooted version if root is set) let is_installed = check_installed(pkg_name, root_path) // Find port let port_result = port.find(pkg_name) if not is_installed and not port_result.success color.print_error("Package not found: " + pkg_name) return ec.EXIT_PKG_NOT_FOUND() end if // Print package info if is_installed let installed_pkg = get_installed_pkg(pkg_name, root_path) print_installed_info(installed_pkg) if port_result.success let p = port_result.port // Check if upgrade available if str.compare(installed_pkg.info.version, p.info.version) < 0 println("") color.print_info("Upgrade available: " + p.info.version) end if end if else // Not installed, show port info let p = port_result.port print_port_info(p) end if return ec.EXIT_SUCCESS() end execute // Helper functions for rooted operations fn check_installed(name: string, root_path: string): bool if str.length(root_path) > 0 return database.is_installed_rooted(name, root_path) end if return database.is_installed(name) end check_installed fn get_installed_pkg(name: string, root_path: string): types.InstalledPackage if str.length(root_path) > 0 return database.get_installed_rooted(name, root_path) end if return database.get_installed(name) end get_installed_pkg proc print_usage() println("Usage: coral info ") println("") println("Display detailed information about a package.") println("") println("Arguments:") println(" Name of package to show info for") println("") println("Examples:") println(" coral info vim") println(" coral info hello") end print_usage proc print_installed_info(pkg: types.InstalledPackage) color.print_action("Package: " + pkg.info.name) println("") println("Status: installed") println("Version: " + pkg.info.version + "-" + int_to_str(pkg.info.release)) println("Description: " + pkg.info.description) println("URL: " + pkg.info.url) println("License: " + pkg.info.license) println("Maintainer: " + pkg.info.maintainer) println("Architecture: " + pkg.info.arch) println("") println("Install date: " + pkg.install_date) println("Reason: " + pkg.install_reason) println("Files: " + int_to_str(pkg.files_count)) end print_installed_info proc print_port_info(p: types.Port) color.print_action("Port: " + p.info.name) println("") println("Status: not installed") println("Version: " + p.info.version + "-" + int_to_str(p.info.release)) println("Description: " + p.info.description) println("URL: " + p.info.url) println("License: " + p.info.license) println("Maintainer: " + p.info.maintainer) println("Architecture: " + p.info.arch) // Show dependencies if any if p.deps.runtime_count > 0 println("") print("Depends on: ") mut i = 0 while i < p.deps.runtime_count if i > 0 print(", ") end if print(p.deps.runtime[i]) i = i + 1 end while println("") end if if p.deps.build_count > 0 println("") print("Build deps: ") mut i = 0 while i < p.deps.build_count if i > 0 print(", ") end if print(p.deps.build[i]) i = i + 1 end while println("") end if end print_port_info // Helper: convert int to string fn int_to_str(n: int): string if n == 0 return "0" end if mut negative = false mut value = n if n < 0 negative = true value = 0 - n end if mut result = "" while value > 0 let digit = value % 10 result = str.concat(str.substring("0123456789", digit, 1), result) value = value / 10 end while if negative result = str.concat("-", result) end if return result end int_to_str end module