quinjet 0.0.40

A fast, live, keyboard-first Git source-control interface for the terminal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
#[cfg_attr(not(test), expect(clippy::wildcard_imports, reason = "shared"))]
use super::*;

#[derive(Debug, Subcommand)]
pub(super) enum BranchVerb {
    /// List local branches
    List(BranchListArgs),
    /// Switch to a branch
    Switch {
        /// Branch to switch to
        #[arg(value_name = "BRANCH", value_hint = ValueHint::Other)]
        name: String,
    },
    /// Create a branch and switch to it
    Create {
        /// New branch name
        #[arg(value_name = "BRANCH", value_hint = ValueHint::Other)]
        name: String,
        /// Commit to branch from
        #[arg(value_name = "START", value_hint = ValueHint::Other)]
        start: Option<String>,
    },
    /// Rename a branch
    Rename {
        /// Existing branch name
        #[arg(value_name = "OLD", value_hint = ValueHint::Other)]
        old: String,
        /// New branch name
        #[arg(value_name = "NEW", value_hint = ValueHint::Other)]
        new: String,
    },
    /// Delete a branch
    Delete {
        /// Branch to delete
        #[arg(value_name = "BRANCH", value_hint = ValueHint::Other)]
        name: String,
        /// Confirm; without it the command reports what it would delete
        #[arg(long)]
        yes: bool,
    },
    /// Diff a branch against the current one without checking anything out
    Compare {
        /// Local or remote-tracking branch to compare
        #[arg(value_name = "BRANCH", value_hint = ValueHint::Other)]
        reference: String,
        /// Print whole files instead of three lines of context
        #[arg(long)]
        expanded: bool,
    },
}

#[derive(Debug, Args)]
pub(super) struct BranchListArgs {
    /// Include remote-tracking branches
    #[arg(long)]
    pub(super) all: bool,
}

#[derive(Debug, Clone, Copy, Subcommand)]
pub(super) enum WorktreeVerb {
    /// List this repository's worktrees
    List,
}

#[derive(Debug, Subcommand)]
pub(super) enum StashVerb {
    /// List stashes
    List,
    /// Stash the current changes
    Push {
        /// Message to record
        #[arg(short, long, default_value = "")]
        message: String,
        /// Include untracked files
        #[arg(long)]
        include_untracked: bool,
        /// Stash only what is staged
        #[arg(long, conflicts_with = "include_untracked")]
        staged: bool,
        /// Limit the stash to these paths
        #[arg(value_name = "PATH", value_hint = ValueHint::AnyPath)]
        paths: Vec<PathBuf>,
    },
    /// Apply a stash and keep it
    Apply {
        /// Stash reference to apply
        #[arg(value_name = "STASH", value_hint = ValueHint::Other)]
        reference: String,
    },
    /// Apply a stash and drop it
    Pop {
        /// Stash reference to apply and drop
        #[arg(value_name = "STASH", value_hint = ValueHint::Other)]
        reference: Option<String>,
    },
    /// Drop a stash
    Drop {
        /// Stash reference to drop
        #[arg(value_name = "STASH", value_hint = ValueHint::Other)]
        reference: String,
        /// Confirm; without it the command reports what it would drop
        #[arg(long)]
        yes: bool,
    },
    /// Drop every stash
    Clear {
        /// Confirm; without it the command reports what it would drop
        #[arg(long)]
        yes: bool,
    },
    /// Print a stash as a patch
    Show {
        /// Stash reference to print
        #[arg(value_name = "STASH", value_hint = ValueHint::Other)]
        reference: String,
        /// Print whole files instead of three lines of context
        #[arg(long)]
        expanded: bool,
    },
}

#[derive(Debug, Args, Clone)]
pub(super) struct PrArgs {
    /// Pull-request number
    #[arg(value_name = "NUMBER", value_hint = ValueHint::Other)]
    pub(super) number: u64,
    /// Repository the number belongs to, as owner/name
    #[arg(long, value_name = "OWNER/NAME", value_hint = ValueHint::Other)]
    pub(super) repo: Option<String>,
    /// Ask GitHub again instead of answering from the cache
    #[arg(long)]
    pub(super) refresh: bool,
}

#[derive(Debug, Args)]
pub(super) struct PrWatchArgs {
    #[command(flatten)]
    pub(super) pull_request: PrArgs,
    /// Keep the reading on screen and refresh it
    #[arg(long)]
    pub(super) watch: bool,
    /// Seconds between refreshes
    #[arg(
        long,
        value_name = "SECONDS",
        default_value_t = CHECK_WATCH_INTERVAL,
        requires = "watch",
        value_parser = clap::value_parser!(u64).range(CHECK_WATCH_FLOOR..),
        value_hint = ValueHint::Other
    )]
    pub(super) interval: u64,
}

#[derive(Debug, Args)]
pub(super) struct PrOpenArgs {
    #[command(flatten)]
    pub(super) pull_request: PrArgs,
    /// Open a matching check run instead of the pull request
    #[arg(long, value_name = "NAME", value_hint = ValueHint::Other)]
    pub(super) check: Option<String>,
}

#[derive(Debug, Args)]
#[group(required = true, multiple = false)]
pub(super) struct PrMergeMethodArgs {
    /// Create a merge commit
    #[arg(long)]
    pub(super) merge: bool,
    /// Squash commits into one and merge
    #[arg(long)]
    pub(super) squash: bool,
    /// Rebase commits onto the base branch and merge
    #[arg(long)]
    pub(super) rebase: bool,
}

impl PrMergeMethodArgs {
    pub(super) const fn method(&self) -> PullRequestMergeMethod {
        if self.merge {
            PullRequestMergeMethod::Merge
        } else if self.rebase {
            PullRequestMergeMethod::Rebase
        } else {
            PullRequestMergeMethod::Squash
        }
    }
}

#[derive(Debug, Args)]
pub(super) struct PrMergeArgs {
    #[command(flatten)]
    pub(super) pull_request: PrArgs,
    #[command(flatten)]
    pub(super) method: PrMergeMethodArgs,
    /// Delete the head branch after merging
    #[arg(long)]
    pub(super) delete_branch: bool,
    /// Confirm; without it the command reports what it would do
    #[arg(long)]
    pub(super) yes: bool,
}

#[derive(Debug, Args)]
pub(super) struct PrMutateArgs {
    #[command(flatten)]
    pub(super) pull_request: PrArgs,
    /// Confirm; without it the command reports what it would do
    #[arg(long)]
    pub(super) yes: bool,
}

#[derive(Debug, Args)]
pub(super) struct PrTextMutateArgs {
    #[command(flatten)]
    pub(super) pull_request: PrArgs,
    /// Text to submit
    #[arg(value_name = "BODY", value_hint = ValueHint::Other)]
    pub(super) body: String,
    /// Confirm; without it the command reports what it would do
    #[arg(long)]
    pub(super) yes: bool,
}

#[derive(Debug, Args)]
#[group(required = true, multiple = false)]
pub(super) struct PrReviewChoiceArgs {
    /// Approve the pull request
    #[arg(long)]
    pub(super) approve: bool,
    /// Submit a review without a verdict
    #[arg(long)]
    pub(super) comment: bool,
    /// Request changes before merging
    #[arg(long)]
    pub(super) request_changes: bool,
}

impl PrReviewChoiceArgs {
    pub(super) const fn kind(&self) -> PullRequestReviewKind {
        if self.approve {
            PullRequestReviewKind::Approve
        } else if self.request_changes {
            PullRequestReviewKind::RequestChanges
        } else {
            PullRequestReviewKind::Comment
        }
    }
}

#[derive(Debug, Args)]
pub(super) struct PrReviewArgs {
    #[command(flatten)]
    pub(super) pull_request: PrArgs,
    #[command(flatten)]
    pub(super) choice: PrReviewChoiceArgs,
    /// Optional review body
    #[arg(long, value_name = "TEXT", value_hint = ValueHint::Other)]
    pub(super) body: Option<String>,
    /// Confirm; without it the command reports what it would do
    #[arg(long)]
    pub(super) yes: bool,
}

#[derive(Debug, Clone, Copy, ValueEnum)]
pub(super) enum PrEditFieldArg {
    Title,
    Body,
    Base,
    AddAssignee,
    RemoveAssignee,
    AddLabel,
    RemoveLabel,
    AddProject,
    RemoveProject,
    AddReviewer,
    RemoveReviewer,
    Milestone,
    RemoveMilestone,
}

#[derive(Debug, Args)]
pub(super) struct PrEditArgs {
    #[command(flatten)]
    pub(super) pull_request: PrArgs,
    /// Metadata field or relationship to change
    #[arg(value_enum, value_name = "FIELD")]
    pub(super) field: PrEditFieldArg,
    /// New value, or a comma-separated list for relationship fields
    #[arg(value_name = "VALUE", value_hint = ValueHint::Other)]
    pub(super) value: Option<String>,
    /// Confirm; without it the command reports what it would do
    #[arg(long)]
    pub(super) yes: bool,
}

impl PrEditArgs {
    pub(super) fn edit(&self) -> Result<PullRequestEdit> {
        if matches!(self.field, PrEditFieldArg::RemoveMilestone) {
            if self.value.is_some() {
                return Err(anyhow::anyhow!("remove-milestone does not take a value"));
            }
            return Ok(PullRequestEdit::RemoveMilestone);
        }
        let value = self
            .value
            .clone()
            .ok_or_else(|| anyhow::anyhow!("the selected edit field needs a value"))?;
        Ok(match self.field {
            PrEditFieldArg::Title => PullRequestEdit::Title(value),
            PrEditFieldArg::Body => PullRequestEdit::Body(value),
            PrEditFieldArg::Base => PullRequestEdit::Base(value),
            PrEditFieldArg::AddAssignee => PullRequestEdit::AddAssignee(value),
            PrEditFieldArg::RemoveAssignee => PullRequestEdit::RemoveAssignee(value),
            PrEditFieldArg::AddLabel => PullRequestEdit::AddLabel(value),
            PrEditFieldArg::RemoveLabel => PullRequestEdit::RemoveLabel(value),
            PrEditFieldArg::AddProject => PullRequestEdit::AddProject(value),
            PrEditFieldArg::RemoveProject => PullRequestEdit::RemoveProject(value),
            PrEditFieldArg::AddReviewer => PullRequestEdit::AddReviewer(value),
            PrEditFieldArg::RemoveReviewer => PullRequestEdit::RemoveReviewer(value),
            PrEditFieldArg::Milestone => PullRequestEdit::SetMilestone(value),
            PrEditFieldArg::RemoveMilestone => return Ok(PullRequestEdit::RemoveMilestone),
        })
    }
}

#[derive(Debug, Args)]
pub(super) struct PrUpdateBranchArgs {
    #[command(flatten)]
    pub(super) pull_request: PrArgs,
    /// Rebase onto the base branch instead of merging it
    #[arg(long)]
    pub(super) rebase: bool,
    /// Confirm; without it the command reports what it would do
    #[arg(long)]
    pub(super) yes: bool,
}

#[derive(Debug, Clone, Copy, ValueEnum)]
pub(super) enum PrLockReasonArg {
    OffTopic,
    Resolved,
    Spam,
    TooHeated,
}

impl From<PrLockReasonArg> for PullRequestLockReason {
    fn from(value: PrLockReasonArg) -> Self {
        match value {
            PrLockReasonArg::OffTopic => Self::OffTopic,
            PrLockReasonArg::Resolved => Self::Resolved,
            PrLockReasonArg::Spam => Self::Spam,
            PrLockReasonArg::TooHeated => Self::TooHeated,
        }
    }
}

#[derive(Debug, Args)]
pub(super) struct PrLockArgs {
    #[command(flatten)]
    pub(super) pull_request: PrArgs,
    /// Why the conversation is being locked
    #[arg(long, value_enum)]
    pub(super) reason: Option<PrLockReasonArg>,
    /// Confirm; without it the command reports what it would do
    #[arg(long)]
    pub(super) yes: bool,
}

#[derive(Debug, Args)]
pub(super) struct PrRevertArgs {
    #[command(flatten)]
    pub(super) pull_request: PrArgs,
    /// Title for the revert pull request
    #[arg(long, value_name = "TEXT", value_hint = ValueHint::Other)]
    pub(super) title: Option<String>,
    /// Description for the revert pull request
    #[arg(long, value_name = "TEXT", value_hint = ValueHint::Other)]
    pub(super) body: Option<String>,
    /// Create the revert pull request as a draft
    #[arg(long)]
    pub(super) draft: bool,
    /// Confirm; without it the command reports what it would do
    #[arg(long)]
    pub(super) yes: bool,
}

#[derive(Debug, Args)]
pub(super) struct PrDiffArgs {
    #[command(flatten)]
    pub(super) pull_request: PrArgs,
    /// Limit the patch to one path
    #[arg(value_name = "PATH", value_hint = ValueHint::AnyPath)]
    pub(super) path: Option<PathBuf>,
}

#[derive(Debug, Args)]
pub(super) struct PrChecksArgs {
    #[command(flatten)]
    pub(super) pull_request: PrArgs,
    /// Keep reading until every check has settled
    #[arg(long)]
    pub(super) watch: bool,
    /// Seconds between reads while watching
    #[arg(
        long,
        value_name = "SECONDS",
        default_value_t = CHECK_WATCH_INTERVAL,
        requires = "watch",
        value_parser = clap::value_parser!(u64).range(CHECK_WATCH_FLOOR..),
        value_hint = ValueHint::Other
    )]
    pub(super) interval: u64,
    /// Exit 1 when a check has not passed
    #[arg(long, conflicts_with = "watch")]
    pub(super) exit_code: bool,
}

#[derive(Debug, Args)]
pub(super) struct PrLogsArgs {
    #[command(flatten)]
    pub(super) pull_request: PrArgs,
    /// Check run to read, by name
    #[arg(value_name = "CHECK", value_hint = ValueHint::Other)]
    pub(super) check: String,
    /// Keep reading while the run is still going
    #[arg(long)]
    pub(super) watch: bool,
    /// Seconds between reads while watching
    #[arg(
        long,
        value_name = "SECONDS",
        default_value_t = LOG_WATCH_INTERVAL,
        requires = "watch",
        value_parser = clap::value_parser!(u64).range(LOG_WATCH_FLOOR..),
        value_hint = ValueHint::Other
    )]
    pub(super) interval: u64,
}