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 #[arg(long, action = ArgAction::SetTrue)]
40 markdown: bool,
41 },
42 Status {
44 #[arg(add = ArgValueCompleter::new(completions::branch_candidates))]
45 branch: Option<String>,
46 },
47 Adopt {
49 #[arg(add = ArgValueCompleter::new(completions::branch_candidates))]
50 branch: String,
51 #[arg(long, add = ArgValueCompleter::new(completions::branch_candidates))]
52 parent: String,
53 },
54 Detach {
56 #[arg(add = ArgValueCompleter::new(completions::branch_candidates))]
57 branch: Option<String>,
58 },
59 Restack {
61 #[arg(long, action = ArgAction::SetTrue, conflicts_with = "no_update_refs")]
63 update_refs: bool,
64 #[arg(long, action = ArgAction::SetTrue)]
66 no_update_refs: bool,
67 #[arg(long, action = ArgAction::SetTrue, conflicts_with = "no_push")]
69 push: bool,
70 #[arg(long, action = ArgAction::SetTrue)]
72 no_push: bool,
73 },
74 Continue,
76 Abort,
78 Provider,
80 Review {
82 #[arg(add = ArgValueCompleter::new(completions::branch_candidates))]
83 branch: Option<String>,
84 },
85 Sync {
87 #[arg(add = ArgValueCompleter::new(completions::branch_candidates))]
88 branch: Option<String>,
89 #[arg(long, action = ArgAction::SetTrue)]
91 dry_run: bool,
92 },
93 Repair {
95 #[arg(long, action = ArgAction::SetTrue)]
97 dry_run: bool,
98 },
99 Submit {
101 #[arg(add = ArgValueCompleter::new(completions::branch_candidates))]
102 branch: Option<String>,
103 #[arg(long, action = ArgAction::SetTrue)]
105 dry_run: bool,
106 #[arg(long, conflicts_with = "branch")]
108 stack: bool,
109 #[arg(long, action = ArgAction::SetTrue, conflicts_with = "no_push")]
111 push: bool,
112 #[arg(long, action = ArgAction::SetTrue)]
114 no_push: bool,
115 },
116 Config,
118 Completions {
120 #[arg(value_enum)]
122 shell: clap_complete::Shell,
123 },
124 Setup {
126 #[arg(long, short = 'y', action = ArgAction::SetTrue)]
128 yes: bool,
129 #[arg(long, action = ArgAction::SetTrue, conflicts_with = "yes")]
131 refresh: bool,
132 },
133 Upgrade {
135 #[arg(long, action = ArgAction::SetTrue, conflicts_with = "force")]
137 head: bool,
138 #[arg(long, action = ArgAction::SetTrue)]
140 force: bool,
141 #[arg(long, short = 'y', action = ArgAction::SetTrue, requires = "head")]
143 yes: bool,
144 },
145 Cleanup {
147 #[arg(add = ArgValueCompleter::new(completions::branch_candidates))]
148 branch: Option<String>,
149 #[arg(long, action = ArgAction::SetTrue)]
151 dry_run: bool,
152 #[arg(long, action = ArgAction::SetTrue)]
154 delete_branch: bool,
155 },
156}
157
158#[derive(Debug, Clone, Copy, Eq, PartialEq)]
159pub enum UpdateRefsMode {
160 Config,
161 Enabled,
162 Disabled,
163}
164
165impl UpdateRefsMode {
166 pub fn from_flags(update_refs: bool, no_update_refs: bool) -> Self {
167 match (update_refs, no_update_refs) {
168 (true, false) => Self::Enabled,
169 (false, true) => Self::Disabled,
170 _ => Self::Config,
171 }
172 }
173}
174
175#[derive(Debug, Clone, Copy, Eq, PartialEq)]
176pub enum PushMode {
177 Config,
178 Enabled,
179 Disabled,
180}
181
182impl PushMode {
183 pub fn from_flags(push: bool, no_push: bool) -> Self {
184 match (push, no_push) {
185 (true, false) => Self::Enabled,
186 (false, true) => Self::Disabled,
187 _ => Self::Config,
188 }
189 }
190}