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