hexz_cli/cmd/data/
status.rs1use anyhow::{Context, Result};
4use colored::Colorize;
5use std::path::PathBuf;
6use walkdir::WalkDir;
7
8use super::workspace::Workspace;
9
10pub fn run(path: Option<PathBuf>) -> Result<()> {
12 let start_path =
13 path.unwrap_or(std::env::current_dir().context("Failed to get current directory")?);
14
15 let ws = Workspace::find(&start_path)?
16 .ok_or_else(|| anyhow::anyhow!("Not in a hexz workspace (no .hexz found)"))?;
17
18 let overlay = ws.overlay_path();
19
20 println!(
21 "{} Workspace {}",
22 "╭".dimmed(),
23 ws.root.display().to_string().cyan()
24 );
25 if let Some(b) = ws.config.base_archive {
26 println!(
27 "{} Base {}",
28 "╰".dimmed(),
29 b.display().to_string().bright_black()
30 );
31 } else {
32 println!("{} Base {}", "╰".dimmed(), "(none)".bright_black());
33 }
34
35 let mut changes = Vec::new();
36 for entry in WalkDir::new(&overlay)
37 .into_iter()
38 .filter_map(std::result::Result::ok)
39 {
40 if entry.path() == overlay {
41 continue;
42 }
43
44 let rel = entry.path().strip_prefix(&overlay)?;
45 if entry.file_type().is_dir() {
46 changes.push(format!(
47 " {} {} {}",
48 "→".dimmed(),
49 rel.display(),
50 "(dir)".bright_black()
51 ));
52 } else {
53 changes.push(format!(
54 " {} {} {}",
55 "→".dimmed(),
56 rel.display().to_string().green(),
57 "(mod)".bright_black()
58 ));
59 }
60 }
61
62 if changes.is_empty() {
63 println!(" {} No changes detected.", "→".green());
64 } else {
65 println!(" {} Changes detected:", "→".yellow());
66 for change in changes {
67 println!("{change}");
68 }
69 }
70
71 Ok(())
72}