use heroforge_core::{Repository, Result};
use std::env;
fn main() -> Result<()> {
let args: Vec<String> = env::args().collect();
let repo_path = args
.get(1)
.map(|s| s.as_str())
.unwrap_or("../code/heroforge.forge");
println!("Opening repository: {}", repo_path);
println!("{}", "=".repeat(60));
let repo = Repository::open(repo_path)?;
let project_code = repo.project_code()?;
let project_name = repo.project_name()?;
println!(
"Project: {}",
project_name.as_deref().unwrap_or("(unnamed)")
);
println!("Code: {}", &project_code[..16]);
println!();
println!("Branches:");
let branches = repo.branches().list()?;
for branch in branches.iter().take(10) {
println!(" - {}", branch);
}
if branches.len() > 10 {
println!(" ... and {} more", branches.len() - 10);
}
println!();
println!("Latest check-in (trunk):");
let tip = repo.history().trunk_tip()?;
println!(" Hash: {}", &tip.hash[..16]);
println!(" Date: {}", tip.timestamp);
println!(" User: {}", tip.user);
println!(" Comment: {}", tip.comment.lines().next().unwrap_or(""));
println!();
println!("Root directory files:");
let root_files = repo.files().on_trunk().list()?;
let root_only: Vec<_> = root_files
.iter()
.filter(|f| !f.name.contains('/'))
.collect();
for file in root_only.iter().take(15) {
println!(" {}", file.name);
}
if root_only.len() > 15 {
println!(" ... and {} more files", root_only.len() - 15);
}
println!();
println!("Root subdirectories:");
let subdirs = repo.files().on_trunk().subdirs("")?;
for dir in &subdirs {
println!(" {}/", dir);
}
println!();
println!("C source files (src/*.c):");
let c_files = repo.files().on_trunk().find("src/*.c")?;
for file in c_files.iter().take(10) {
println!(" {}", file.name);
}
if c_files.len() > 10 {
println!(" ... and {} more", c_files.len() - 10);
}
println!();
println!("README.md content (first 500 chars):");
match repo.files().on_trunk().read_string("README.md") {
Ok(text) => {
let preview: String = text.chars().take(500).collect();
println!("{}", preview);
if text.len() > 500 {
println!("...");
}
}
Err(e) => {
println!(" Could not read README.md: {}", e);
}
}
println!();
println!("Recent check-ins:");
let recent = repo.history().recent(5)?;
for ci in &recent {
println!(
" {} {} - {}",
&ci.hash[..8],
ci.user,
ci.comment.lines().next().unwrap_or("")
);
}
Ok(())
}