git_stk/commands/
adopt.rs1use anyhow::{Context, Result};
2use clap::ArgAction;
3use clap_complete::engine::ArgValueCompleter;
4
5use crate::commands::Run;
6use crate::completions;
7
8#[derive(Debug, clap::Args)]
11pub struct Adopt {
12 #[arg(add = ArgValueCompleter::new(completions::branch_candidates))]
14 branch: Option<String>,
15 #[arg(long, add = ArgValueCompleter::new(completions::branch_candidates))]
17 parent: Option<String>,
18 #[arg(long, short = 'n', action = ArgAction::SetTrue)]
20 dry_run: bool,
21}
22
23impl Run for Adopt {
24 fn run(self) -> Result<()> {
25 let branch = match self.branch {
26 Some(branch) => branch,
27 None => crate::git::current_branch()?,
28 };
29 let parent = match self.parent {
30 Some(parent) => parent,
31 None => crate::stack::trunk_branch(&crate::git::local_branches()?)
32 .context("could not detect the trunk branch; pass --parent")?,
33 };
34 crate::stack::adopt_branch(&branch, &parent, self.dry_run)
35 }
36}