devist 0.2.0

Project bootstrap CLI for AI-assisted development. Spin up new projects from templates, manage backends, and keep your codebase comprehensible.
use anyhow::Result;
use console::style;
use std::fs;

use crate::config::Config;
use crate::paths;

pub fn run() -> Result<()> {
    println!("{}", style("Initializing devist workspace").bold());
    println!();

    ensure_dir(&paths::devist_root()?, "root")?;
    ensure_dir(&paths::templates_dir()?, "templates")?;
    ensure_dir(&paths::cache_dir()?, "cache")?;

    let config_path = paths::config_file()?;
    if config_path.exists() {
        println!(
            "  {}  config       {}",
            style("[KEEP]").yellow(),
            style(config_path.display()).dim()
        );
    } else {
        Config::default().save()?;
        println!(
            "  {}  config       {}",
            style("[NEW]").green(),
            style(config_path.display()).dim()
        );
    }

    println!();
    println!("{}", style("Done.").green());
    Ok(())
}

fn ensure_dir(path: &std::path::Path, label: &str) -> Result<()> {
    if path.exists() {
        println!(
            "  {}  {:12} {}",
            style("[KEEP]").yellow(),
            label,
            style(path.display()).dim()
        );
    } else {
        fs::create_dir_all(path)?;
        println!(
            "  {}  {:12} {}",
            style("[NEW]").green(),
            label,
            style(path.display()).dim()
        );
    }
    Ok(())
}