diff options
| author | rorka900 <rorka900@gmail.com> | 2026-03-19 11:44:27 +0000 |
|---|---|---|
| committer | rorka900 <rorka900@gmail.com> | 2026-03-19 11:44:27 +0000 |
| commit | 693f5143adb352b9fa1ee262b3537f6e429678f9 (patch) | |
| tree | b8c9bc10fc0901bcbfd3c1d5990b70d601a08828 /src/info.rs | |
| download | ror-693f5143adb352b9fa1ee262b3537f6e429678f9.tar.gz ror-693f5143adb352b9fa1ee262b3537f6e429678f9.zip | |
Initial commitmaster
Diffstat (limited to 'src/info.rs')
| -rw-r--r-- | src/info.rs | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/src/info.rs b/src/info.rs new file mode 100644 index 0000000..8b07daf --- /dev/null +++ b/src/info.rs @@ -0,0 +1,119 @@ +use serde::{Deserialize, Serialize}; +use std::fs; +use std::path::{Path, PathBuf}; +use colored::Colorize; + +const REPO_ROOT: &str = "/var/ror/packages"; + +fn find_package_file(pkg_name: &str) -> Option<PathBuf> { + let repo = Path::new(REPO_ROOT); + for entry in fs::read_dir(repo).ok()? { + let entry = entry.ok()?; + let cat_path = entry.path(); + if !cat_path.is_dir() { + continue; + } + let pkg_path = cat_path.join(pkg_name).join(format!("{}.yaml", pkg_name)); + if pkg_path.exists() && pkg_path.is_file() { + return Some(pkg_path); + } + } + None +} + +#[derive(Debug, Serialize, Deserialize)] +struct Package { + name: String, + version: String, + #[serde(default)] + release: Option<String>, + #[serde(default)] + license: Option<String>, + #[serde(default)] + homepage: Option<String>, + #[serde(default)] + description: Option<String>, + #[serde(default)] + binaries: Vec<BinaryPackage>, +} + +#[derive(Debug, Serialize, Deserialize)] +struct BinaryPackage { + #[serde(rename = "type", default)] + pkg_type: Option<String>, + arch: String, + filename: String, + mirrors: Vec<String>, + sha256: String, +} +pub fn print_package_info(pkg_name: &str) { + let pkg_path = match find_package_file(pkg_name) { + Some(p) => p, + None => { + eprintln!( + "{} Package '{}' not found!", + "[ror]".red().bold(), + pkg_name + ); + return; + } + }; + + let content = match fs::read_to_string(&pkg_path) { + Ok(c) => c, + Err(e) => { + eprintln!( + "{} Failed to read package file: {}", + "[ror]".red().bold(), + e + ); + return; + } + }; + + let pkg: Package = match serde_yaml::from_str(&content) { + Ok(p) => p, + Err(e) => { + eprintln!( + "{} YAML structure error: {}", + "[ror]".red().bold(), + e + ); + return; + } + }; + + println!("\n{} {}", "[ Package Info ]".cyan().bold(), "=".repeat(50).cyan()); + + println!("{} {}{}", + "Name:".yellow().bold(), + pkg.name, + if let Some(rel) = &pkg.release { format!("-{}", rel) } else { String::new() } + ); + println!("{} {}", "Version:".yellow().bold(), pkg.version); + + if let Some(lic) = &pkg.license { + println!("{} {}", "License:".yellow().bold(), lic); + } + if let Some(home) = &pkg.homepage { + println!("{} {}", "Homepage:".yellow().bold(), home); + } + if let Some(desc) = &pkg.description { + println!("{} {}", "Description:".yellow().bold(), desc); + } + + if !pkg.binaries.is_empty() { + println!("\n{}", "[ Binaries ]".green().bold()); + for bin in &pkg.binaries { + if let Some(t) = &bin.pkg_type { + println!(" {} [{}]", "Type:".white(), t); + } + println!(" {} {}", "Arch:".white(), bin.arch); + println!(" {} {}", "Filename:".white(), bin.filename); + println!(" {} {}...", "SHA256:".white(), &bin.sha256[..16]); + println!(" {} {} mirrors", "Mirrors:".white(), bin.mirrors.len()); + println!(); + } +} + println!("{}", "=".repeat(60).cyan()); +} |