Skip to main content

git_stk/commands/
new.rs

1use anyhow::Result;
2use clap::ArgAction;
3
4use crate::commands::Run;
5
6/// Create a new child branch from the current branch.
7#[derive(Debug, clap::Args)]
8pub struct New {
9    branch: String,
10    /// Insert above the current branch, moving its children onto the new one.
11    #[arg(long, conflicts_with = "prepend")]
12    insert: bool,
13    /// Insert below the current branch, moving it onto the new one.
14    #[arg(long)]
15    prepend: bool,
16    /// Print what would change (the branch, and any retargeted children)
17    /// without creating or moving anything.
18    #[arg(long, short = 'n', action = ArgAction::SetTrue)]
19    dry_run: bool,
20}
21
22impl Run for New {
23    fn run(self) -> Result<()> {
24        if self.insert {
25            crate::stack::insert_branch(&self.branch, self.dry_run)
26        } else if self.prepend {
27            crate::stack::prepend_branch(&self.branch, self.dry_run)
28        } else {
29            crate::stack::create_branch(&self.branch, self.dry_run)
30        }
31    }
32}