ccd-cli 1.0.0-alpha.9

Bootstrap and validate Continuous Context Development repositories
use std::process::ExitCode;

use anyhow::Result;

use crate::commands;
use crate::output::{self, OutputFormat};
use crate::paths;

pub(crate) fn attach(args: crate::AttachArgs, format: OutputFormat) -> Result<ExitCode> {
    let repo_path = paths::cli::resolve(&args.path)?;
    let report = commands::attach::run(
        &repo_path,
        args.profile.as_deref(),
        args.project_id.as_deref(),
        args.display_name.as_deref(),
    )?;
    output::render_report(format, &report)
}

pub(crate) fn init(args: crate::InitArgs, format: OutputFormat) -> Result<ExitCode> {
    let repo_path = paths::cli::resolve(&args.path)?;
    let report = commands::host::init(
        &repo_path,
        args.profile.as_deref(),
        args.project_id.as_deref(),
        args.display_name.as_deref(),
        &args
            .host
            .iter()
            .copied()
            .map(crate::RepoHostArg::into_host)
            .collect::<Vec<_>>(),
        args.force,
    )?;
    output::render_report(format, &report)
}

pub(crate) fn scaffold(args: crate::ScaffoldArgs, format: OutputFormat) -> Result<ExitCode> {
    let repo_path = paths::cli::resolve(&args.path)?;
    let report = commands::scaffold::run(&repo_path, args.force)?;
    output::render_report(format, &report)
}

pub(crate) fn link(args: crate::LinkArgs, format: OutputFormat) -> Result<ExitCode> {
    let repo_path = paths::cli::resolve(&args.path)?;
    let report = commands::link::run(
        &repo_path,
        args.profile.as_deref(),
        args.project_id.as_deref(),
        args.display_name.as_deref(),
    )?;
    output::render_report(format, &report)
}

pub(crate) fn unlink(args: crate::UnlinkArgs, format: OutputFormat) -> Result<ExitCode> {
    let repo_path = paths::cli::resolve(&args.path)?;
    let report = commands::unlink::run(&repo_path)?;
    output::render_report(format, &report)
}