repograph 0.4.0

Register, group, and expose local git repos as structured context for AI agents
//! `repograph remove <name>` — deregister a repository.

use std::path::Path;

use clap::Parser;
use repograph_core::{Config, RepographError};

use crate::output::{self, Mutation};

#[derive(Debug, Parser)]
pub struct Args {
    /// Name of the registered repository to remove.
    pub name: String,

    /// Emit a JSON confirmation of the removal to stdout.
    #[arg(long)]
    pub json: bool,
}

/// Remove the named repository from the config.
///
/// # Errors
///
/// Propagates [`RepographError::NotFound`] when the name is not registered,
/// and other errors from config load/save.
#[tracing::instrument(skip(args), fields(
    name = %args.name,
    config_dir = %config_dir.display(),
))]
pub fn run(args: &Args, config_dir: &Path) -> Result<(), RepographError> {
    tracing::debug!("remove: start");
    let mut config = Config::load(config_dir)?;
    config.remove_repo(&args.name)?;
    config.save(config_dir)?;
    tracing::info!(repo = %args.name, "removed");

    if args.json {
        output::render_mutation(&Mutation::Remove { name: &args.name })?;
    }
    Ok(())
}