Skip to main content

git_stk/commands/
bottom.rs

1use anyhow::Result;
2
3use crate::commands::Run;
4
5/// Move to the bottom of the stack: check out the branch just above the
6/// trunk.
7#[derive(Debug, clap::Args)]
8pub struct Bottom {
9    /// Print the destination directory instead of announcing the switch, so
10    /// `cd "$(git stk bottom --from-path)"` follows the branch - including into another
11    /// worktree, which cannot be checked out here.
12    #[arg(long)]
13    from_path: bool,
14}
15
16impl Run for Bottom {
17    fn run(self) -> Result<()> {
18        crate::stack::checkout_bottom(self.nav_output())
19    }
20}
21
22impl Bottom {
23    fn nav_output(&self) -> crate::stack::NavOutput {
24        if self.from_path {
25            crate::stack::NavOutput::Path
26        } else {
27            crate::stack::NavOutput::Announce
28        }
29    }
30}