vectordb-cli 1.3.2-stable

A CLI tool for semantic code search.
use anyhow::{bail, Result};
use clap::Args;
use std::path::PathBuf;
use colored::*;

use crate::config::{self, AppConfig};

#[derive(Args, Debug)]
#[derive(Clone)]
pub struct UseRepoArgs {
    /// Name of the repository to set as active.
    pub name: String,
}

pub fn use_repository(
    args: UseRepoArgs, 
    config: &mut AppConfig, 
    override_path: Option<&PathBuf>
) -> Result<()> {
    let repo_name = args.name;

    if config.repositories.iter().any(|r| r.name == repo_name) {
        config.active_repository = Some(repo_name.clone());
        config::save_config(&config, override_path)?;
        println!(
            "{}",
            format!("Set active repository to '{}'.", repo_name.cyan()).green()
        );
    } else {
        bail!(
            "Repository '{}' not found. Use 'repo list' to see available repositories.",
            repo_name
        );
    }

    Ok(())
}