/****************************************************************************** __ ____ __ / / ___ ____ _/ __/_____________ _/ /__ / / / _ \/ __ `/ /_/ ___/ ___/ __ `/ / _ \ / /___/ __/ /_/ / __(__ ) /__/ /_/ / / __/ /_____/\___/\__,_/_/ /____/\___/\__,_/_/\___/ (C)opyright 2025, Leafscale, LLC - https://www.leafscale.com Project: Zygaena Filename: files.reef Authors: Chris Tusa License: Description: Files command - list files owned by a package ******************************************************************************/ module commands.files import sys.args import core.str import core.config import core.database 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, opts.no_chroot) 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) if not check_installed(pkg_name, root_path) color.print_error(pkg_name + " is not installed") return ec.EXIT_PKG_NOT_FOUND() end if // Get files (use rooted version if root is set) mut files: [string] = new [string](4096) let file_count = get_files_list(pkg_name, files, 4096, root_path) if file_count == 0 color.print_info("No files recorded for " + pkg_name) return ec.EXIT_SUCCESS() end if color.print_action("Files owned by " + pkg_name + ":") println("") mut i = 0 while i < file_count println("/" + files[i]) i = i + 1 end while println("") color.print_info("Total: " + int_to_str(file_count) + " files") 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_files_list(name: string, files: [string], max_count: int, root_path: string): int if str.length(root_path) > 0 return database.get_files_rooted(name, files, max_count, root_path) end if return database.get_files(name, files, max_count) end get_files_list proc print_usage() println("Usage: coral files ") println("") println("List all files owned by an installed package.") println("") println("Arguments:") println(" Name of installed package") println("") println("Examples:") println(" coral files vim") println(" coral files hello") end print_usage // 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