Skip to main content

hexz_cli/cmd/data/
push.rs

1//! Push archives to a remote endpoint.
2
3use anyhow::{Context, Result};
4use std::path::PathBuf;
5use colored::Colorize;
6use super::workspace::Workspace;
7
8/// Execute the `hexz push` command to upload thin archives to a remote.
9pub fn run(remote: &str, archive: Option<PathBuf>) -> Result<()> {
10    let ws = Workspace::find(&std::env::current_dir()?)?
11        .context("Not in a hexz workspace (no .hexz found)")?;
12
13    let url = ws.config.remotes.get(remote).with_context(|| {
14        format!("Remote '{remote}' not found. Add it with `hexz remote add {remote} <url>`")
15    })?;
16
17    let target = if let Some(a) = archive {
18        a
19    } else if let Some(b) = &ws.config.base_archive {
20        b.clone()
21    } else {
22        anyhow::bail!("No archive specified and workspace has no base archive to push.");
23    };
24
25    println!("{} Pushing       {}", "╭".dimmed(), target.display().to_string().cyan());
26    println!("{} Remote        {} {}", "╰".dimmed(), remote.magenta(), url.bright_black());
27    
28    println!("\n  {} Analyzing missing blocks...", "→".yellow());
29    println!("  {} Connecting to remote...", "→".yellow());
30    
31    // Future Implementation:
32    // 1. Fetch remote manifest
33    // 2. Identify missing blocks
34    // 3. Upload only missing chunks
35    
36    println!("\n  {} Push complete.", "✓".green());
37    Ok(())
38}