Skip to main content

git_stk/commands/
down.rs

1use anyhow::Result;
2
3use crate::cli::parse_distance;
4use crate::commands::Run;
5
6/// Move down the stack: check out the current branch's parent.
7#[derive(Debug, clap::Args)]
8pub struct Down {
9    /// How many branches to move down.
10    #[arg(value_name = "COUNT", value_parser = parse_distance, allow_negative_numbers = true)]
11    count: Option<usize>,
12    /// Print the destination directory instead of announcing the switch, so
13    /// `cd "$(git stk down --from-path)"` follows the branch - including into another
14    /// worktree, which cannot be checked out here.
15    #[arg(long)]
16    from_path: bool,
17}
18
19impl Run for Down {
20    fn run(self) -> Result<()> {
21        crate::stack::checkout_parent(self.count.unwrap_or(1), self.nav_output())
22    }
23}
24
25impl Down {
26    fn nav_output(&self) -> crate::stack::NavOutput {
27        if self.from_path {
28            crate::stack::NavOutput::Path
29        } else {
30            crate::stack::NavOutput::Announce
31        }
32    }
33}