use crate::error::Result;
use async_trait::async_trait;
use clap::Args;
use std::path::PathBuf;
#[derive(Debug, Clone, Args)]
pub struct InitCommand {
#[arg(short, long)]
pub name: String,
#[arg(short, long, value_delimiter = ',')]
pub agents: Vec<String>,
#[arg(short, long, default_value = ".")]
pub dir: PathBuf,
#[arg(long, default_value_t = true)]
pub use_worktree: bool,
}
#[async_trait]
impl super::Command for InitCommand {
async fn execute(self) -> Result<()> {
let project = ProjectBuilder::new(self.name)
.directory(self.dir)
.agents(self.agents)
.worktree(self.use_worktree)
.build()?;
project.initialize().await?;
Ok(())
}
}
pub struct ProjectBuilder {
name: String,
directory: PathBuf,
agents: Vec<String>,
use_worktree: bool,
}
impl ProjectBuilder {
pub fn new(name: String) -> Self {
Self {
name,
directory: PathBuf::from("."),
agents: Vec::new(),
use_worktree: true,
}
}
pub fn directory(mut self, dir: PathBuf) -> Self {
self.directory = dir;
self
}
pub fn agents(mut self, agents: Vec<String>) -> Self {
self.agents = agents;
self
}
pub fn worktree(mut self, use_worktree: bool) -> Self {
self.use_worktree = use_worktree;
self
}
pub fn build(self) -> Result<Project> {
Ok(Project {
name: self.name,
directory: self.directory,
agents: self.agents,
use_worktree: self.use_worktree,
})
}
}
pub struct Project {
name: String,
directory: PathBuf,
agents: Vec<String>,
use_worktree: bool,
}
impl Project {
pub async fn initialize(&self) -> Result<()> {
tracing::info!("Initializing project: {}", self.name);
tokio::fs::create_dir_all(&self.directory).await?;
if self.use_worktree {
self.setup_worktrees().await?;
}
self.create_config().await?;
Ok(())
}
async fn setup_worktrees(&self) -> Result<()> {
for agent in &self.agents {
let _worktree_path = self.directory.join(format!("agent-{}", agent));
tracing::debug!("Creating worktree for agent: {}", agent);
}
Ok(())
}
async fn create_config(&self) -> Result<()> {
Ok(())
}
}