git_stk/commands/top.rs
1use anyhow::Result;
2
3use crate::commands::Run;
4
5/// Move to the top of the stack: check out its leaf branch.
6#[derive(Debug, clap::Args)]
7pub struct Top {
8 /// Print the destination directory instead of announcing the switch, so
9 /// `cd "$(git stk top --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 Top {
16 fn run(self) -> Result<()> {
17 crate::stack::checkout_top(self.nav_output())
18 }
19}
20
21impl Top {
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}