mod commands;
use anyhow::Result;
use clap::{Parser, Subcommand};
use std::path::PathBuf;
use crate::output;
#[derive(Parser)]
#[command(
name = "parsec",
about = "Git worktree lifecycle manager for parallel AI agent workflows",
version,
arg_required_else_help = true
)]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
#[arg(long, global = true)]
pub json: bool,
#[arg(long, short, global = true)]
pub quiet: bool,
#[arg(long, global = true)]
pub repo: Option<PathBuf>,
}
#[derive(Subcommand)]
pub enum Command {
Start {
ticket: String,
#[arg(long, short)]
base: Option<String>,
#[arg(long)]
title: Option<String>,
},
List,
Status {
ticket: Option<String>,
},
Ship {
ticket: String,
#[arg(long)]
draft: bool,
#[arg(long)]
no_pr: bool,
},
Clean {
#[arg(long)]
all: bool,
#[arg(long)]
dry_run: bool,
},
Conflicts,
Switch {
ticket: String,
},
Config {
#[command(subcommand)]
action: ConfigAction,
},
}
#[derive(Subcommand)]
pub enum ConfigAction {
Init,
Show,
Shell {
#[arg(default_value = "zsh")]
shell: String,
},
}
pub async fn run(cli: Cli) -> Result<()> {
let repo_path = cli.repo.unwrap_or_else(|| PathBuf::from("."));
let output_mode = if cli.json {
output::Mode::Json
} else if cli.quiet {
output::Mode::Quiet
} else {
output::Mode::Human
};
match cli.command {
Command::Start {
ticket,
base,
title,
} => commands::start(&repo_path, &ticket, base.as_deref(), title, output_mode).await,
Command::List => commands::list(&repo_path, output_mode).await,
Command::Status { ticket } => {
commands::status(&repo_path, ticket.as_deref(), output_mode).await
}
Command::Ship {
ticket,
draft,
no_pr,
} => commands::ship(&repo_path, &ticket, draft, no_pr, output_mode).await,
Command::Clean { all, dry_run } => {
commands::clean(&repo_path, all, dry_run, output_mode).await
}
Command::Conflicts => commands::conflicts(&repo_path, output_mode).await,
Command::Switch { ticket } => commands::switch(&repo_path, &ticket, output_mode).await,
Command::Config { action } => match action {
ConfigAction::Init => commands::config_init(output_mode).await,
ConfigAction::Show => commands::config_show(output_mode).await,
ConfigAction::Shell { shell } => commands::config_shell(&shell, output_mode).await,
},
}
}