1use clap::{ArgAction, Parser, Subcommand};
2use clap_complete::engine::ArgValueCompleter;
3
4use crate::completions;
5
6#[derive(Debug, Parser)]
7#[command(name = "git-stk")]
8#[command(version)]
9#[command(about = "Git-native stacked branch workflow helper, with GitHub and GitLab integration")]
10pub struct Cli {
11 #[command(subcommand)]
12 pub command: Command,
13}
14
15#[derive(Debug, Subcommand)]
16pub enum Command {
17 New { branch: String },
19 Parent {
21 #[arg(add = ArgValueCompleter::new(completions::branch_candidates))]
22 branch: Option<String>,
23 },
24 Children {
26 #[arg(add = ArgValueCompleter::new(completions::branch_candidates))]
27 branch: Option<String>,
28 },
29 Up {
31 #[arg(add = ArgValueCompleter::new(completions::child_branch_candidates))]
32 branch: Option<String>,
33 },
34 Down,
36 List,
38 Status {
40 #[arg(add = ArgValueCompleter::new(completions::branch_candidates))]
41 branch: Option<String>,
42 },
43 Adopt {
45 #[arg(add = ArgValueCompleter::new(completions::branch_candidates))]
46 branch: String,
47 #[arg(long, add = ArgValueCompleter::new(completions::branch_candidates))]
48 parent: String,
49 },
50 Detach {
52 #[arg(add = ArgValueCompleter::new(completions::branch_candidates))]
53 branch: Option<String>,
54 },
55 Restack {
57 #[arg(long, action = ArgAction::SetTrue, conflicts_with = "no_update_refs")]
59 update_refs: bool,
60 #[arg(long, action = ArgAction::SetTrue)]
62 no_update_refs: bool,
63 #[arg(long, action = ArgAction::SetTrue, conflicts_with = "no_push")]
65 push: bool,
66 #[arg(long, action = ArgAction::SetTrue)]
68 no_push: bool,
69 },
70 Continue,
72 Abort,
74 Provider,
76 Review {
78 #[arg(add = ArgValueCompleter::new(completions::branch_candidates))]
79 branch: Option<String>,
80 },
81 Sync {
83 #[arg(add = ArgValueCompleter::new(completions::branch_candidates))]
84 branch: Option<String>,
85 #[arg(long, action = ArgAction::SetTrue)]
87 dry_run: bool,
88 },
89 Repair {
91 #[arg(long, action = ArgAction::SetTrue)]
93 dry_run: bool,
94 },
95 Submit {
97 #[arg(add = ArgValueCompleter::new(completions::branch_candidates))]
98 branch: Option<String>,
99 #[arg(long, action = ArgAction::SetTrue)]
101 dry_run: bool,
102 #[arg(long, conflicts_with = "branch")]
104 stack: bool,
105 #[arg(long, action = ArgAction::SetTrue, conflicts_with = "no_push")]
107 push: bool,
108 #[arg(long, action = ArgAction::SetTrue)]
110 no_push: bool,
111 },
112 Config,
114 Completions {
116 #[arg(value_enum)]
118 shell: clap_complete::Shell,
119 },
120 Setup {
122 #[arg(long, short = 'y', action = ArgAction::SetTrue)]
124 yes: bool,
125 #[arg(long, action = ArgAction::SetTrue, conflicts_with = "yes")]
127 refresh: bool,
128 },
129 Upgrade {
131 #[arg(long, action = ArgAction::SetTrue, conflicts_with = "force")]
133 head: bool,
134 #[arg(long, action = ArgAction::SetTrue)]
136 force: bool,
137 #[arg(long, short = 'y', action = ArgAction::SetTrue, requires = "head")]
139 yes: bool,
140 },
141 Cleanup {
143 #[arg(add = ArgValueCompleter::new(completions::branch_candidates))]
144 branch: Option<String>,
145 #[arg(long, action = ArgAction::SetTrue)]
147 dry_run: bool,
148 #[arg(long, action = ArgAction::SetTrue)]
150 delete_branch: bool,
151 },
152}
153
154#[derive(Debug, Clone, Copy, Eq, PartialEq)]
155pub enum UpdateRefsMode {
156 Config,
157 Enabled,
158 Disabled,
159}
160
161impl UpdateRefsMode {
162 pub fn from_flags(update_refs: bool, no_update_refs: bool) -> Self {
163 match (update_refs, no_update_refs) {
164 (true, false) => Self::Enabled,
165 (false, true) => Self::Disabled,
166 _ => Self::Config,
167 }
168 }
169}
170
171#[derive(Debug, Clone, Copy, Eq, PartialEq)]
172pub enum PushMode {
173 Config,
174 Enabled,
175 Disabled,
176}
177
178impl PushMode {
179 pub fn from_flags(push: bool, no_push: bool) -> Self {
180 match (push, no_push) {
181 (true, false) => Self::Enabled,
182 (false, true) => Self::Disabled,
183 _ => Self::Config,
184 }
185 }
186}