use anyhow::{Context, Result};
use clap_complete::engine::ArgValueCompleter;
use crate::commands::Run;
use crate::completions;
#[derive(Debug, clap::Args)]
pub struct Adopt {
#[arg(add = ArgValueCompleter::new(completions::branch_candidates))]
branch: Option<String>,
#[arg(long, add = ArgValueCompleter::new(completions::branch_candidates))]
parent: Option<String>,
}
impl Run for Adopt {
fn run(self) -> Result<()> {
let branch = match self.branch {
Some(branch) => branch,
None => crate::git::current_branch()?,
};
let parent = match self.parent {
Some(parent) => parent,
None => crate::stack::trunk_branch(&crate::git::local_branches()?)
.context("could not detect the trunk branch; pass --parent")?,
};
crate::stack::adopt_branch(&branch, &parent)
}
}