void-cli 0.0.4

CLI for void — anonymous encrypted source control
//! Print the current repository's encryption key (hex-encoded).
//!
//! Extracts the repo key by loading the current identity and ECIES-unwrapping
//! from `.void/contributors.json`. Useful for debugging and scripted clone workflows.

use std::path::Path;

use serde::Serialize;

use crate::context::{find_void_dir, load_identity_cached, void_err_to_cli};
use crate::output::{run_command, CliError, CliOptions};

#[derive(Debug, Serialize)]
pub struct RepoKeyOutput {
    pub key: String,
}

pub fn run(cwd: &Path, opts: &CliOptions) -> Result<(), CliError> {
    run_command("debug repo-key", opts, |ctx| {
        let void_dir = find_void_dir(cwd)?;
        let identity = load_identity_cached()?;
        let repo_key = void_core::collab::manifest::load_repo_key(&void_dir, Some(&identity))
            .map_err(void_err_to_cli)?;
        let hex_str = hex::encode(repo_key.as_bytes());

        if !ctx.use_json() {
            ctx.info(hex_str.clone());
        }

        Ok(RepoKeyOutput { key: hex_str })
    })
}