Skip to main content

git_stk/commands/
up.rs

1use anyhow::Result;
2use clap_complete::engine::ArgValueCompleter;
3
4use crate::commands::Run;
5use crate::completions;
6
7/// Move up the stack: check out a child of the current branch.
8#[derive(Debug, clap::Args)]
9pub struct Up {
10    #[arg(add = ArgValueCompleter::new(completions::child_branch_candidates))]
11    branch: Option<String>,
12    /// Print the destination directory instead of announcing the switch, so
13    /// `cd "$(git stk up --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 Up {
20    fn run(self) -> Result<()> {
21        crate::stack::checkout_child(self.branch.as_deref(), self.nav_output())
22    }
23}
24
25impl Up {
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}