OXYGENHUB

Coverage / src/cli/mod.rs 60.8%

208 of 342 lines run, 9 of 18 functions · run #318 on main · run missed

1
//! Command-line definitions and dispatch.
2
3
mod approve;
4
mod auth;
5
mod format;
6
mod identity;
7
mod json;
8
mod proposal;
9
mod receipt;
10
mod sync;
11
pub mod ui;
12
mod workspace;
13
14
use anyhow::{Context, Result};
15
use clap::{Parser, Subcommand};
16
use oxy_core::repo::Repo;
17
use std::path::PathBuf;
18
19
#[derive(Parser)]
20
#[command(
21
    name = "oxy",
22
    version = env!("OXY_VERSION_LONG"),
23
    about = "Oxygen: breathing fresh air into version control"
24
)]
25
struct Cli {
26
    /// Plain output: no colour, no spinner (also implied by NO_COLOR or a non-terminal)
27
    #[arg(long, global = true)]
28
    plain: bool,
29
    /// Read the repository as it was after operation OP (an ID from oxy op log, @ or @-); commands that would change it are refused
30
    #[arg(long, global = true, value_name = "OP")]
31
    at_op: Option<String>,
32
    #[command(subcommand)]
33
    cmd: Cmd,
34
}
35
36
/// `--at-op`, for `open` to apply.
37
static AT_OP: std::sync::OnceLock<Option<String>> = std::sync::OnceLock::new();
38
39
#[derive(Subcommand)]
40
enum Cmd {
41
    /// Create a repository in PATH (default: current directory)
42
    Init {
43
        /// Directory to create the repository in (default: the current directory)
44
        path: Option<PathBuf>,
45
        /// No working copy: an object store and references only, for hosting
46
        #[arg(long)]
47
        bare: bool,
48
        /// Keep the objects and the operation log on this store
49
        /// (dir://PATH, s3://BUCKET/PREFIX, gs://…, az://…) instead of
50
        /// in .oxy, with a local cache in front (storage.cache, 2 GiB)
51
        #[arg(long, value_name = "URL")]
52
        store: Option<String>,
53
    },
54
    /// Clone a repository from a local path or an http(s) URL
55
    Clone {
56
        /// Local path or http(s) URL of the repository
57
        url: String,
58
        /// Directory to clone into (default: the last part of the URL)
59
        dest: Option<PathBuf>,
60
        /// Leave blobs larger than this (e.g. 1M) to be fetched on first read
61
        #[arg(long)]
62
        max_blob: Option<String>,
63
        /// Materialize only these paths (repeatable); implies lazy blobs
64
        #[arg(long = "sparse")]
65
        sparse: Vec<String>,
66
        /// Shallow clone: fetch only this many levels of history below the heads
67
        #[arg(long)]
68
        depth: Option<u32>,
69
        /// Clone the subrepos too (as oxy submodule update --init)
70
        #[arg(long)]
71
        recursive: bool,
72
    },
73
    /// Fetch more history below a shallow clone's boundary
74
    Deepen {
75
        /// Levels of history to add below the boundary
76
        #[arg(default_value_t = 10)]
77
        depth: u32,
78
        /// Remote to fetch the history from
79
        #[arg(long, default_value = "origin")]
80
        remote: String,
81
    },
82
    /// Show or set the sparse filter (paths to materialize); re-checks out the bookmark
83
    Sparse {
84
        /// Paths to materialize; none prints the current filter
85
        paths: Vec<String>,
86
    },
87
    /// Show the working copy: changed paths and conflicts
88
    Status {
89
        /// Machine-readable output: paths, and every conflict with its kind and contributing changes
90
        #[arg(long)]
91
        json: bool,
92
    },
93
    /// One-line summary for shell prompts; fast and records nothing
94
    Prompt {
95
        /// Placeholders: %b bookmark, %c change id, %h heads, %d dirty (*), %x conflict (!), %A/%D ahead/behind (+n/-n), %a/%B raw counts, %s state glyph, %U/%O ahead/behind arrows, %i icon
96
        #[arg(long, default_value = oxy_core::repo::DEFAULT_PROMPT_FORMAT)]
97
        format: String,
98
        /// Glyph format (%i %b %c %s%U%O) instead of the plain default
99
        #[arg(long)]
100
        glyphs: bool,
101
        /// Colour by state (cyan clean, yellow dirty, red conflicted): raw escapes, or guarded for a bash or zsh PS1
102
        #[arg(long, value_parser = ["raw", "bash", "zsh"])]
103
        color: Option<String>,
104
    },
105
    /// Record the working copy as a change on the current bookmark
106
    Commit {
107
        /// The change's message: a subject line, then optionally a blank line and a body
108
        #[arg(short, long, required_unless_present = "file", conflicts_with = "file")]
109
        message: Option<String>,
110
        /// Read the message from FILE (`-` for standard input)
111
        #[arg(short = 'F', long, value_name = "FILE")]
112
        file: Option<PathBuf>,
113
        /// Extra explicit dependencies (ChangeId prefix, #hash prefix)
114
        #[arg(long = "depends-on")]
115
        depends_on: Vec<String>,
116
        /// Commit only these paths; the rest stays as uncommitted work
117
        paths: Vec<String>,
118
        /// Choose hunks one by one
119
        #[arg(short, long)]
120
        interactive: bool,
121
        /// Commit these hunks (as `oxy hunks` numbers them), comma separated
122
        #[arg(long, value_delimiter = ',')]
123
        hunks: Vec<usize>,
124
    },
125
    /// Fold CHANGE into one of its dependencies (keeps that change's id)
126
    Squash {
127
        /// The change to fold (ChangeId prefix, #hash prefix)
128
        change: String,
129
        /// The dependency that absorbs it
130
        #[arg(long)]
131
        into: String,
132
    },
133
    /// Re-express CHANGE against another base state
134
    Rebase {
135
        /// The change to re-express (ChangeId prefix, #hash prefix)
136
        change: String,
137
        /// The changes, bookmark or tag whose state becomes the new base
138
        #[arg(long, required = true, num_args = 1..)]
139
        onto: Vec<String>,
140
        /// Where the rebase would be conflicted, merge the target into the
141
        /// current bookmark instead, leaving the conflict in the working
142
        /// copy to fix and commit
143
        #[arg(long)]
144
        into_working_copy: bool,
145
    },
146
    /// Show which change introduced each line of a file
147
    Blame {
148
        /// File to annotate, relative to the repository root
149
        path: String,
150
        /// Machine-readable output: one JSON document on stdout
151
        #[arg(long)]
152
        json: bool,
153
    },
154
    /// Find the change that introduced a regression
155
    Bisect {
156
        #[command(subcommand)]
157
        cmd: BisectCmd,
158
    },
159
    /// List changes reachable from the bookmark and the working copy
160
    Log {
161
        /// Show the changes a revset selects: `main` (a bookmark name means its
162
        /// heads; `bookmark(main)` only ever the bookmark), `main..feature &
163
        /// author(andy)`, `touches("src/**") & date(-7d..)` (see
164
        /// docs/revset_query_language.md)
165
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with_all = ["path", "lines"])]
166
        revset: Option<String>,
167
        /// Show at most this many changes
168
        #[arg(short = 'n', long)]
169
        limit: Option<usize>,
170
        /// Show full messages, dependencies, and signatures
171
        #[arg(short, long)]
172
        verbose: bool,
173
        /// Only changes touching this path (renames followed)
174
        #[arg(long)]
175
        path: Option<String>,
176
        /// Only changes that wrote or deleted lines START to END of PATH
177
        /// (numbered as in the working copy's base), or deleted lines from
178
        /// between them: the history of a function
179
        #[arg(short = 'L', value_name = "START,END:PATH", conflicts_with = "path")]
180
        lines: Option<String>,
181
        /// Machine-readable output: one JSON document on stdout
182
        #[arg(long)]
183
        json: bool,
184
    },
185
    /// Show what the working copy changes against its base
186
    Diff {
187
        /// A change instead of the working copy
188
        change: Option<String>,
189
        /// Machine-readable output: one JSON document on stdout
190
        #[arg(long)]
191
        json: bool,
192
    },
193
    /// Print a file as it is in a state (default: the working copy's base)
194
    Cat {
195
        /// File to print, relative to the repository root
196
        path: String,
197
        /// A bookmark or tag (its state), or a change: a change means its
198
        /// dependency closure, the change and what it depends on, so files
199
        /// only later changes touched are absent or at older versions
200
        #[arg(short = 'r', long)]
201
        change: Option<String>,
202
    },
203
    /// Print the repository root, workspace, and bookmark
204
    Root {
205
        /// Machine-readable output: one JSON document on stdout
206
        #[arg(long)]
207
        json: bool,
208
    },
209
    /// Print the version of oxy, its repository format, and protocol
210
    Version {
211
        /// Machine-readable output: one JSON document on stdout
212
        #[arg(long)]
213
        json: bool,
214
    },
215
    /// Restore paths to the working copy's base, or undo chosen hunks
216
    Discard {
217
        /// Paths to restore; none with --hunks, or everything with neither
218
        paths: Vec<String>,
219
        /// Hunk indices as `oxy hunks` numbers them, comma separated
220
        #[arg(long, value_delimiter = ',')]
221
        hunks: Vec<usize>,
222
    },
223
    /// List the working copy's hunks, numbered as commit --hunks expects
224
    Hunks {
225
        /// Machine-readable output: one JSON document on stdout
226
        #[arg(long)]
227
        json: bool,
228
    },
229
    /// With -m, change the message of a head; without, name the working
230
    /// copy for a build: its tag, or the nearest tag plus distance and
231
    /// change, or the bookmark and change, and -dirty
232
    Describe {
233
        /// The new message
234
        #[arg(short, long)]
235
        message: Option<String>,
236
        /// The head to describe (default: the one the working copy sits on)
237
        change: Option<String>,
238
        /// Machine-readable output (naming only)
239
        #[arg(long, conflicts_with = "message")]
240
        json: bool,
241
    },
242
    /// Fold the working copy into the head it sits on, or into CHANGE with --into
243
    Amend {
244
        /// Replace the message too
245
        #[arg(short, long)]
246
        message: Option<String>,
247
        /// Amend an older change; the edits must touch only lines it already knows
248
        #[arg(long)]
249
        into: Option<String>,
250
    },
251
    /// Split a head: the named paths become a separate first change
252
    Split {
253
        /// The head to split
254
        change: String,
255
        /// Paths whose edits become the first change
256
        paths: Vec<String>,
257
    },
258
    /// Drop a change from the bookmark; its content stays on disk as uncommitted work
259
    Abandon {
260
        /// The change to drop (ChangeId prefix, #hash prefix)
261
        #[arg(required_unless_present = "revset")]
262
        change: Option<String>,
263
        /// Drop every change a revset selects, newest first
264
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
265
        revset: Option<String>,
266
        /// Drop more than five changes without asking
267
        #[arg(long, short = 'y')]
268
        yes: bool,
269
    },
270
    /// Show one change (ChangeId prefix, #hash prefix, or @), or those a revset selects
271
    Show {
272
        /// ChangeId prefix, #hash prefix, or @ for the working copy
273
        #[arg(required_unless_present = "revset")]
274
        change: Option<String>,
275
        /// Show every change a revset selects
276
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
277
        revset: Option<String>,
278
        /// Machine-readable output: one JSON document on stdout
279
        #[arg(long)]
280
        json: bool,
281
    },
282
    /// Move the working copy to the state formed by CHANGE... (default: the bookmark heads)
283
    Checkout {
284
        /// Changes whose state to check out (default: the bookmark heads)
285
        changes: Vec<String>,
286
        /// Throw away uncommitted working-copy changes
287
        #[arg(long)]
288
        discard: bool,
289
        /// Take uncommitted changes along; refused when the target has
290
        /// other versions of the files they touch
291
        #[arg(long, conflicts_with = "discard")]
292
        carry: bool,
293
    },
294
    /// Report which conflicts of the working copy's base are resolved by the current files
295
    Resolve {
296
        /// Machine-readable output: one JSON document on stdout
297
        #[arg(long)]
298
        json: bool,
299
    },
300
    /// Undo the last operation
301
    Undo,
302
    /// Write a checkpoint of the current bookmark's state now
303
    Checkpoint,
304
    /// Print a shell completion script: `oxy completions bash > ~/.local/share/bash-completion/completions/oxy`
305
    Completions {
306
        /// bash, zsh, fish, elvish or powershell
307
        shell: clap_complete::Shell,
308
    },
309
    /// Write man pages (oxy.1 and one per command) into DIR, or print oxy.1
310
    Man {
311
        /// Directory to write every page into, e.g. ~/.local/share/man/man1
312
        #[arg(long)]
313
        dir: Option<PathBuf>,
314
    },
315
    /// Check the identity, configuration and remotes, and say what to do about any problem
316
    Doctor {
317
        /// Do not contact the remotes
318
        #[arg(long)]
319
        offline: bool,
320
        /// Machine-readable output: one JSON document on stdout
321
        #[arg(long)]
322
        json: bool,
323
    },
324
    /// Check the repository's integrity: objects, operation log, references, signatures, checkpoints
325
    Fsck {
326
        /// Machine-readable output: one JSON document on stdout
327
        #[arg(long)]
328
        json: bool,
329
    },
330
    /// Prune unreachable objects older than the grace period and repack everything into one pack
331
    Gc {
332
        /// Ignore the grace period (core.gc-grace) and prune immediately
333
        #[arg(long)]
334
        now: bool,
335
        /// Keep no past working-copy snapshots, only each workspace's current one, so files only they held go (core.snapshot-retention, default 7 days)
336
        #[arg(long)]
337
        expire_snapshots: bool,
338
        /// Instead: fold the bundles of a remote kept on a store into one, and remove the ones a gc superseded 7 days ago (or now, with --now)
339
        #[arg(long, value_name = "NAME")]
340
        remote: Option<String>,
341
    },
342
    /// List operations
343
    #[command(name = "op")]
344
    Op {
345
        #[command(subcommand)]
346
        cmd: OpCmd,
347
    },
348
    /// Take the advisory local lock on a lockable file, making it writable
349
    Lock {
350
        /// The lockable file
351
        path: String,
352
    },
353
    /// Release the local lock and make the file read-only again
354
    Unlock {
355
        /// The locked file
356
        path: String,
357
    },
358
    /// Workspaces: extra checkout directories sharing this repository
359
    Workspace {
360
        #[command(subcommand)]
361
        cmd: WorkspaceCmd,
362
    },
363
    /// Bookmarks: named states; each workspace works on one
364
    Bookmark {
365
        #[command(subcommand)]
366
        cmd: BookmarkCmd,
367
    },
368
    /// Union another bookmark's heads into the current one (no merge change)
369
    Merge {
370
        /// The bookmark whose heads to add
371
        bookmark: String,
372
    },
373
    /// Sign in to a hub once, for every repository on it
374
    Auth {
375
        #[command(subcommand)]
376
        cmd: AuthCmd,
377
    },
378
    /// Subrepositories: nested repositories pinned to a state
379
    Submodule {
380
        #[command(subcommand)]
381
        cmd: SubmoduleCmd,
382
    },
383
    /// Execution receipts: signed records of what a runner ran on a state
384
    Receipt {
385
        #[command(subcommand)]
386
        cmd: ReceiptCmd,
387
    },
388
    /// Tags: immutable named states
389
    Tag {
390
        #[command(subcommand)]
391
        cmd: TagCmd,
392
    },
393
    /// Manage remotes
394
    Remote {
395
        #[command(subcommand)]
396
        cmd: RemoteCmd,
397
    },
398
    /// Fetch every bookmark of a remote into its tracking references
399
    Fetch {
400
        /// Remote name (default: origin)
401
        remote: Option<String>,
402
        /// Machine-readable output: one JSON document on stdout
403
        #[arg(long)]
404
        json: bool,
405
    },
406
    /// Fetch, then union the remote bookmark into the local one (no merge change)
407
    Pull {
408
        /// Remote name (default: origin)
409
        remote: Option<String>,
410
        /// Machine-readable output: one JSON document on stdout
411
        #[arg(long)]
412
        json: bool,
413
    },
414
    /// Push the current bookmark to a remote
415
    Push {
416
        /// Remote name (default: origin)
417
        remote: Option<String>,
418
        /// Allow dropping heads the remote has
419
        #[arg(long)]
420
        force: bool,
421
        /// Push this bookmark instead of the workspace's current one
422
        #[arg(short = 'b', long)]
423
        bookmark: Option<String>,
424
        /// Delete this bookmark on the remote (never its default bookmark);
425
        /// the local bookmark is kept
426
        #[arg(long, value_name = "NAME", conflicts_with_all = ["bookmark", "force"])]
427
        delete: Option<String>,
428
        /// Machine-readable output: one JSON document on stdout
429
        #[arg(long)]
430
        json: bool,
431
    },
432
    /// Serve repositories under ROOT over HTTPS (with --tls-cert/--tls-key) or plain HTTP
433
    Serve {
434
        /// Directory with one repository per subdirectory
435
        #[arg(long, default_value = ".")]
436
        root: PathBuf,
437
        /// Address and port to listen on
438
        #[arg(long, default_value = "127.0.0.1:8890")]
439
        bind: String,
440
        /// Bearer token allowed to push (repeatable); none means open
441
        #[arg(long = "token")]
442
        tokens: Vec<String>,
443
        /// PEM certificate chain; enables HTTPS together with --tls-key
444
        #[arg(long, requires = "tls_key")]
445
        tls_cert: Option<PathBuf>,
446
        /// PEM private key
447
        #[arg(long, requires = "tls_cert")]
448
        tls_key: Option<PathBuf>,
449
    },
450
    /// Manage the signing identity
451
    Identity {
452
        #[command(subcommand)]
453
        cmd: IdentityCmd,
454
    },
455
    /// Seal changes with your key: named ones, or every change on the current bookmark you can authenticate but have not
456
    Seal {
457
        /// Changes to seal (default: every change on the bookmark you can authenticate and have not sealed)
458
        changes: Vec<String>,
459
        /// Seal every change of a hub proposal and push the seal (your approval)
460
        #[arg(long, conflicts_with = "changes")]
461
        proposal: Option<String>,
462
        /// Approve a job of a hub run that waits for a sealed approval: `--flow https://hub/OWNER/NAME/flow/N --job apply`
463
        #[arg(long, conflicts_with_all = ["changes", "proposal"], requires = "job")]
464
        flow: Option<String>,
465
        /// The job to approve, with --flow
466
        #[arg(long, requires = "flow")]
467
        job: Option<String>,
468
        /// Reject the job instead of approving it, with --flow
469
        #[arg(long, requires = "flow")]
470
        reject: bool,
471
        /// Machine-readable output: one JSON document on stdout
472
        #[arg(long)]
473
        json: bool,
474
    },
475
    /// Hub proposals: show one, or land it from this client
476
    Proposal {
477
        #[command(subcommand)]
478
        cmd: ProposalCmd,
479
    },
480
    /// Verify the signatures on a change (default: every change in the log)
481
    Verify {
482
        /// The change to verify (default: every change in the log)
483
        change: Option<String>,
484
        /// Verify every change a revset selects: `release..main & unsigned()`
485
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
486
        revset: Option<String>,
487
        /// Machine-readable output: one JSON document on stdout
488
        #[arg(long)]
489
        json: bool,
490
    },
491
    /// Git interoperability
492
    Git {
493
        #[command(subcommand)]
494
        cmd: GitCmd,
495
    },
496
    /// Manage the trust policy (who may update which bookmarks)
497
    Policy {
498
        #[command(subcommand)]
499
        cmd: PolicyCmd,
500
    },
501
    /// Set a configuration key (author.*, core.sign, core.op-retention, core.gc-grace, core.checkpoint-interval, filter.max-blob, filter.paths, storage.cache, workspace.bookmark, remote.<name>.url|token|ca, auth.helper with --user)
502
    Config {
503
        /// The key, such as author.name or remote.origin.token
504
        key: String,
505
        /// The value to set (none with --unset); `-` reads it from standard input, out of the shell's history
506
        #[arg(required_unless_present = "unset")]
507
        value: Option<String>,
508
        /// Write to the user file (~/.config/oxy/config.toml) instead of this repository
509
        #[arg(long)]
510
        user: bool,
511
        /// Remove the key from this repository's file (or the user file with --user)
512
        #[arg(long)]
513
        unset: bool,
514
    },
515
}
516
517
#[derive(Subcommand)]
518
enum OpCmd {
519
    /// List operations, newest first, with what each changed
520
    Log {
521
        /// Show only the latest N (snapshots folded together count as one)
522
        #[arg(short = 'n', long)]
523
        limit: Option<usize>,
524
        /// Machine-readable output: one JSON document on stdout
525
        #[arg(long)]
526
        json: bool,
527
    },
528
    /// Go back to the bookmarks and working copy as they were after OP (recorded as a new operation, so it can be undone)
529
    Restore {
530
        /// The operation: an ID prefix from oxy op log, @ or @-
531
        op: String,
532
        /// Throw away uncommitted working-copy changes
533
        #[arg(long)]
534
        discard: bool,
535
    },
536
    /// Undo OP alone, keeping every operation after it: the bookmarks it moved go back
537
    Revert {
538
        /// The operation: an ID prefix from oxy op log
539
        op: String,
540
    },
541
}
542
543
#[derive(Subcommand)]
544
enum WorkspaceCmd {
545
    /// Create a workspace at PATH checked out on CHANGE... (default: the bookmark heads)
546
    Add {
547
        /// Directory for the new workspace (must be empty or absent)
548
        path: PathBuf,
549
        /// Changes whose state to check out there
550
        changes: Vec<String>,
551
    },
552
    /// List workspaces and their working-copy changes
553
    List {
554
        /// Machine-readable output: one JSON document on stdout
555
        #[arg(long)]
556
        json: bool,
557
    },
558
    /// Stop tracking a workspace (by id prefix or path); its files stay
559
    Forget {
560
        /// Workspace id prefix or path
561
        workspace: String,
562
    },
563
}
564
565
#[derive(Subcommand)]
566
enum BisectCmd {
567
    /// Begin; remembers where the working copy was
568
    Start,
569
    /// Mark CHANGE... (or the state under test) as good
570
    Good {
571
        /// Changes known to be good (default: the state under test)
572
        changes: Vec<String>,
573
    },
574
    /// Mark CHANGE... (or the state under test) as bad
575
    Bad {
576
        /// Changes known to be bad (default: the state under test)
577
        changes: Vec<String>,
578
    },
579
    /// The state under test cannot be tested; try another
580
    Skip,
581
    /// Run a command for each step: exit 0 good, 125 skip, else bad
582
    Run {
583
        /// Command and arguments to run at each step
584
        #[arg(required = true, trailing_var_arg = true)]
585
        command: Vec<String>,
586
    },
587
    /// Where the search stands
588
    Status {
589
        /// Machine-readable output: one JSON document on stdout
590
        #[arg(long)]
591
        json: bool,
592
    },
593
    /// Restore the working copy and forget the search
594
    Reset,
595
}
596
597
#[derive(Subcommand)]
598
enum BookmarkCmd {
599
    /// Create a bookmark at CHANGE... (default: the working copy's base)
600
    Create {
601
        /// Name of the new bookmark
602
        name: String,
603
        /// Its heads (default: the working copy's base). A state is its
604
        /// heads and what they depend on: a change alone may leave out
605
        /// earlier changes of the current state, which is refused unless
606
        /// --upto or --only says which is meant
607
        changes: Vec<String>,
608
        /// Everything of the current state up to CHANGE..., as a Git
609
        /// branch at a commit would hold
610
        #[arg(long, conflicts_with = "only")]
611
        upto: bool,
612
        /// Just CHANGE... and what they depend on. Other changes to the
613
        /// same files are left out, so a file can come out partly edited;
614
        /// to add one change to a bookmark's work, give the bookmark's
615
        /// heads with it instead: `bookmark set NAME <its heads> CHANGE`
616
        #[arg(long)]
617
        only: bool,
618
    },
619
    /// Point an existing bookmark at CHANGE...
620
    Set {
621
        /// The bookmark to move
622
        name: String,
623
        /// Its new heads. A change alone may leave out changes the
624
        /// bookmark now holds that were recorded before it, which is
625
        /// refused unless --upto or --only says which is meant
626
        changes: Vec<String>,
627
        /// Everything the bookmark holds up to CHANGE..., as a Git branch
628
        /// moved to a commit would hold
629
        #[arg(long, conflicts_with = "only")]
630
        upto: bool,
631
        /// Just CHANGE... and what they depend on. Other changes to the
632
        /// same files are left out, so a file can come out partly edited;
633
        /// to add one change to a bookmark's work, give the bookmark's
634
        /// heads with it instead: `bookmark set NAME <its heads> CHANGE`
635
        #[arg(long)]
636
        only: bool,
637
    },
638
    /// Remove a bookmark; its changes stay
639
    Delete {
640
        /// The bookmark to remove
641
        name: String,
642
    },
643
    /// List bookmarks with their heads and difference from origin
644
    List {
645
        /// Also list remotes' bookmarks that have no local bookmark
646
        #[arg(long, short)]
647
        all: bool,
648
        /// Each head of every bookmark, as `bookmark show` prints them
649
        #[arg(long, short)]
650
        verbose: bool,
651
        /// Machine-readable output: one JSON document on stdout
652
        #[arg(long)]
653
        json: bool,
654
    },
655
    /// A bookmark's heads: each change nothing else on it depends on,
656
    /// newest first. A bookmark name is also a revset for its heads
657
    /// (`oxy log -r NAME`, or `bookmark(NAME)` to mean only the bookmark)
658
    Show {
659
        /// The bookmark, or REMOTE/NAME (default: the current one)
660
        name: Option<String>,
661
        /// Machine-readable output: one JSON document on stdout
662
        #[arg(long)]
663
        json: bool,
664
    },
665
    /// Make NAME this workspace's bookmark and check it out. Uncommitted work stops it; --carry takes the work along, --discard drops it
666
    Switch {
667
        /// The bookmark to work on; one only a remote has (NAME or REMOTE/NAME) is created from it
668
        name: String,
669
        /// Throw away uncommitted working-copy changes
670
        #[arg(long)]
671
        discard: bool,
672
        /// Take uncommitted changes along; refused when NAME has other
673
        /// versions of the files they touch
674
        #[arg(long, conflicts_with = "discard")]
675
        carry: bool,
676
    },
677
}
678
679
#[derive(Subcommand)]
680
enum AuthCmd {
681
    /// Sign in to HUB in the browser (device sign-in) and keep the token for
682
    /// every repository there
683
    Login {
684
        /// The hub, as https://oxygenhub.io or oxygenhub.io (default: this checkout's origin)
685
        hub: Option<String>,
686
        /// Read a token from standard input instead (for CI and scripts)
687
        #[arg(long)]
688
        with_token: bool,
689
        /// PEM file of extra roots to trust (a hub with a self-signed certificate)
690
        #[arg(long)]
691
        ca: Option<PathBuf>,
692
    },
693
    /// List the hubs you are signed in to, checking each token with its hub
694
    Status,
695
    /// Forget HUB's token and revoke it on the hub
696
    Logout {
697
        /// The hub (default: this checkout's origin, or the only one)
698
        hub: Option<String>,
699
    },
700
    /// Keep an agent grant token (from `oh agent grant`) for keyless
701
    /// signing: with `author.signer = keyless`, commits and pushes are
702
    /// signed by fresh keys the hub certifies, in the grantor's name
703
    /// (the token is read from standard input, so it stays out of the
704
    /// shell's history)
705
    Grant {
706
        /// The hub (default: this checkout's origin)
707
        hub: Option<String>,
708
    },
709
}
710
711
#[derive(Subcommand)]
712
enum SubmoduleCmd {
713
    /// Clone URL (Oxygen or Git) into PATH and register it in .oxymodules
714
    Add {
715
        /// URL or path of the Oxygen or Git repository
716
        url: String,
717
        /// Where to put it, relative to the repository root
718
        path: String,
719
        /// Bookmark (Oxygen) or branch (Git) to check out and track
720
        #[arg(long)]
721
        bookmark: Option<String>,
722
    },
723
    /// Bring nested repositories to their pins
724
    Update {
725
        /// Clone nested repositories that are absent
726
        #[arg(long)]
727
        init: bool,
728
        /// Subrepos to update (default: all)
729
        paths: Vec<String>,
730
    },
731
    /// List subrepos with their pins and on-disk state
732
    Status {
733
        /// Machine-readable output: one JSON document on stdout
734
        #[arg(long)]
735
        json: bool,
736
    },
737
    /// Unregister PATH; the directory stays, the node goes with the next commit
738
    Remove {
739
        /// The subrepo to unregister
740
        path: String,
741
    },
742
}
743
744
#[derive(Subcommand)]
745
enum ReceiptCmd {
746
    /// The receipts kept for a state (default: the bookmark heads)
747
    List {
748
        /// Change, bookmark or tag whose state to look at
749
        rev: Option<String>,
750
        /// Machine-readable output: one JSON document on stdout
751
        #[arg(long)]
752
        json: bool,
753
    },
754
    /// One receipt in full, and whether its signature verifies
755
    Show {
756
        /// The receipt (a prefix of its hash, as `list` shows it)
757
        receipt: String,
758
        /// Change, bookmark or tag whose state holds it
759
        #[arg(long)]
760
        rev: Option<String>,
761
        /// Machine-readable output: one JSON document on stdout
762
        #[arg(long)]
763
        json: bool,
764
    },
765
    /// Write a signed receipt to FILE
766
    Export {
767
        /// The receipt (a prefix of its hash, as `list` shows it)
768
        receipt: String,
769
        /// Where to write it
770
        file: String,
771
        /// Change, bookmark or tag whose state holds it
772
        #[arg(long)]
773
        rev: Option<String>,
774
        /// `oxygen`: the runner's signed receipt, as `verify` and `import`
775
        /// read it. `slsa`: SLSA provenance in a DSSE envelope, signed with
776
        /// your key, for in-toto and cosign (`oxy identity export --pem`
777
        /// gives the key they check it with)
778
        #[arg(long, default_value = "oxygen", value_parser = ["oxygen", "slsa"])]
779
        format: String,
780
    },
781
    /// Check a signed receipt in FILE without keeping it
782
    Verify {
783
        /// A signed receipt, as a runner or `export` writes it
784
        file: String,
785
        /// Machine-readable output: one JSON document on stdout
786
        #[arg(long)]
787
        json: bool,
788
    },
789
    /// Verify a signed receipt in FILE and keep it with its state
790
    Import {
791
        /// A signed receipt, as a runner or `export` writes it
792
        file: String,
793
    },
794
}
795
796
#[derive(Subcommand)]
797
enum TagCmd {
798
    /// Tag the state of CHANGE... (default: the bookmark heads)
799
    Create {
800
        /// Name of the tag; tags never move
801
        name: String,
802
        /// Changes whose state to tag (default: the bookmark heads)
803
        changes: Vec<String>,
804
        /// A message recorded with the tag
805
        #[arg(short, long, default_value = "")]
806
        message: String,
807
    },
808
    /// List tags and the states they name
809
    List {
810
        /// Machine-readable output: one JSON document on stdout
811
        #[arg(long)]
812
        json: bool,
813
    },
814
}
815
816
#[derive(Subcommand)]
817
enum RemoteCmd {
818
    /// Add a remote
819
    Add {
820
        /// Name to refer to the remote by, such as origin
821
        name: String,
822
        /// A local path or the http(s) URL of a hub repository; or a store the repository is kept on: s3://BUCKET/PREFIX, gs://BUCKET/PREFIX, az://ACCOUNT/CONTAINER/PREFIX, dir://PATH
823
        url: String,
824
        /// For an s3:// store: the AWS profile to use (default: AWS_PROFILE, else "default")
825
        #[arg(long)]
826
        profile: Option<String>,
827
        /// For an s3:// store: its region (default: the environment, the profile, else asked of S3)
828
        #[arg(long)]
829
        region: Option<String>,
830
        /// For an s3://, gs:// or az:// store: another endpoint, such as an S3-compatible service
831
        #[arg(long)]
832
        endpoint: Option<String>,
833
        /// For a gs:// store: a service account key file, or application default credentials
834
        #[arg(long)]
835
        credentials: Option<String>,
836
    },
837
    /// Check a remote: that it is reachable with the credentials in hand, what it holds, and (for a store) that it behaves
838
    Check {
839
        /// The remote to check
840
        name: String,
841
    },
842
    /// Remove a remote
843
    Remove {
844
        /// The remote to remove
845
        name: String,
846
    },
847
    /// List remotes and their URLs
848
    List {
849
        /// Machine-readable output: one JSON document on stdout
850
        #[arg(long)]
851
        json: bool,
852
    },
853
}
854
855
#[derive(Subcommand)]
856
enum ProposalCmd {
857
    /// Show a proposal by its hub URL
858
    Show {
859
        /// The proposal's URL on the hub
860
        url: String,
861
        /// Machine-readable output: one JSON document on stdout
862
        #[arg(long)]
863
        json: bool,
864
    },
865
    /// Fetch the proposal's changes, set the target bookmark to the projected state, and push with your key
866
    Land {
867
        /// The proposal's URL on the hub
868
        url: String,
869
        /// Land even when the hub reports blockers
870
        #[arg(long)]
871
        force: bool,
872
    },
873
}
874
875
#[derive(Subcommand)]
876
enum IdentityCmd {
877
    /// Generate a composite Ed25519 + ML-DSA-65 key pair and make it your author identity
878
    Create {
879
        /// Your name (default: author.name)
880
        #[arg(long)]
881
        name: Option<String>,
882
        /// Your email (default: author.email)
883
        #[arg(long)]
884
        email: Option<String>,
885
        /// Record the author in this repository only, not in the user config
886
        #[arg(long)]
887
        local: bool,
888
        /// Expire the identity this many days from now
889
        #[arg(long)]
890
        expires: Option<u64>,
891
    },
892
    /// Show the configured identity
893
    Show,
894
    /// Write your identity object to a file, to hand to a policy holder
895
    Export {
896
        /// File to write (default: <key>.identity, or <key>.pem with --pem, in the current directory)
897
        path: Option<PathBuf>,
898
        /// Write the Ed25519 public key as PEM instead, as cosign's --key and
899
        /// other DSSE verifiers take it
900
        #[arg(long)]
901
        pem: bool,
902
    },
903
    /// Sign a host's challenge (hex, at least 16 bytes) to prove you hold your key; prints the signature as hex
904
    SignChallenge {
905
        /// The host's challenge, as hex
906
        challenge: String,
907
        /// Machine-readable output: one JSON document on stdout
908
        #[arg(long)]
909
        json: bool,
910
    },
911
    /// Move to a fresh key pair; the policy follows if it names your key
912
    Rotate,
913
    /// Re-issue your identity with a new expiry (in days from now; 0 = never)
914
    Renew {
915
        /// Days from now until it expires; 0 for never
916
        #[arg(long)]
917
        expires: u64,
918
    },
919
    /// Revoke a key: yours by default, or any key if you hold a policy root
920
    Revoke {
921
        /// KeyId prefix (default: your own key)
922
        key: Option<String>,
923
        /// Why, recorded in the revocation
924
        #[arg(long, default_value = "")]
925
        reason: String,
926
    },
927
    /// Keys allowed to sign or seal on your behalf
928
    Delegate {
929
        #[command(subcommand)]
930
        cmd: DelegateCmd,
931
    },
932
}
933
934
#[derive(Subcommand)]
935
enum DelegateCmd {
936
    /// Add a delegate from an exported identity file
937
    Add {
938
        /// The delegates' exported identity files: one rotation for all of them
939
        #[arg(required = true)]
940
        identity_file: Vec<PathBuf>,
941
        /// What it may do for you: changes, refs, seal (comma-separated) or all.
942
        /// An agent gets `changes`; a host that lands for you needs `changes,refs`
943
        #[arg(long, default_value = "changes")]
944
        scope: String,
945
        /// How long for: 30m, 8h, 7d, or a number of days (default: until removed)
946
        #[arg(long)]
947
        expires: Option<String>,
948
    },
949
    /// Remove a delegate by KeyId prefix
950
    Remove {
951
        /// KeyId prefix of the delegate
952
        key: String,
953
    },
954
    /// List delegates
955
    List,
956
}
957
958
#[derive(Subcommand)]
959
enum GitCmd {
960
    /// Export the current bookmark to a Git repository (created bare if absent)
961
    Export {
962
        /// Git repository to write to (created bare if absent)
963
        git_dir: PathBuf,
964
        /// Git branch to write (default: the bookmark name)
965
        #[arg(long)]
966
        branch: Option<String>,
967
    },
968
    /// Fetch a branch from a Git remote (path or URL) into the current bookmark
969
    Fetch {
970
        /// Git remote: a path or URL
971
        url: String,
972
        /// Branch to fetch
973
        #[arg(long, default_value = "main")]
974
        branch: String,
975
        /// Author your own commits (Git author email = your identity's) with your key; sets git.claim
976
        #[arg(long)]
977
        claim: bool,
978
    },
979
    /// Push the current bookmark to a branch of a Git remote (fetch first)
980
    Push {
981
        /// Git remote: a path or URL
982
        url: String,
983
        /// Branch to push to
984
        #[arg(long, default_value = "main")]
985
        branch: String,
986
    },
987
    /// Recover an import that stopped before it moved the bookmark: point the bookmark at every imported commit's change in the store, so oxy git fetch carries on from there
988
    Recover,
989
    /// Check this repository's import of a Git branch: every commit's tree must be reproduced exactly
990
    Verify {
991
        /// The Git repository the import came from
992
        git_dir: PathBuf,
993
        /// Branch that was imported
994
        #[arg(long, default_value = "main")]
995
        branch: String,
996
        /// Rebuild only the last N commits (the others are followed, not checked)
997
        #[arg(long, value_name = "N")]
998
        last: Option<usize>,
999
        /// Stop after N differences (0: check every commit whatever it finds)
1000
        #[arg(long, value_name = "N", default_value_t = 50)]
1001
        max_differences: usize,
1002
    },
1003
    /// Import a Git branch into a new Oxygen repository at DEST
1004
    Import {
1005
        /// Git repository to read
1006
        git_dir: PathBuf,
1007
        /// Directory for the new Oxygen repository
1008
        dest: PathBuf,
1009
        /// Branch to import
1010
        #[arg(long, default_value = "main")]
1011
        branch: String,
1012
        /// Author your own commits (Git author email = your identity's) with your key; sets git.claim
1013
        #[arg(long)]
1014
        claim: bool,
1015
    },
1016
}
1017
1018
#[derive(Subcommand)]
1019
enum PolicyCmd {
1020
    /// Create the initial policy with your identity as the only root
1021
    Init,
1022
    /// Show the current policy
1023
    Show {
1024
        /// Machine-readable output: one JSON document on stdout
1025
        #[arg(long)]
1026
        json: bool,
1027
    },
1028
    /// Allow an identity (from `oxy identity export`) to update bookmarks
1029
    Grant {
1030
        /// The identity to grant, exported with `oxy identity export`
1031
        identity_file: PathBuf,
1032
        /// Reference pattern the grant applies to (default: every bookmark)
1033
        #[arg(long)]
1034
        pattern: Option<String>,
1035
        /// Where to write the proposal when more root signatures are needed
1036
        #[arg(long)]
1037
        out: Option<PathBuf>,
1038
    },
1039
    /// Allow holders of an issuer's certificates for SUBJECT to sign (keyless)
1040
    GrantSubject {
1041
        /// Who: `repo:OWNER/NAME:bookmark:main`, `agent:NAME@ACCOUNT`; `*` matches any run of characters
1042
        subject: String,
1043
        /// The issuer's identity file, e.g. a hub's /.well-known/oxyhub-key
1044
        #[arg(long)]
1045
        issuer: PathBuf,
1046
        /// What its keys may sign: changes, refs, seal
1047
        #[arg(long, default_value = "changes,refs")]
1048
        scope: String,
1049
        /// Reference pattern the grant applies to (default: every bookmark)
1050
        #[arg(long)]
1051
        pattern: Option<String>,
1052
        /// Where to write the proposal when more root signatures are needed
1053
        #[arg(long)]
1054
        out: Option<PathBuf>,
1055
    },
1056
    /// Revoke a key (KeyId prefix of an identity in the policy)
1057
    Revoke {
1058
        /// KeyId prefix of the identity
1059
        key: String,
1060
        /// Where to write the proposal when more root signatures are needed
1061
        #[arg(long)]
1062
        out: Option<PathBuf>,
1063
    },
1064
    /// Manage root keys and the signature threshold for policy updates
1065
    Root {
1066
        #[command(subcommand)]
1067
        cmd: RootCmd,
1068
    },
1069
    /// Add your root signature to a proposal file; applies it once the threshold is met
1070
    Sign {
1071
        /// The proposal file to sign
1072
        proposal: PathBuf,
1073
        /// Where to write the proposal if it still needs signatures (default: in place)
1074
        #[arg(long)]
1075
        out: Option<PathBuf>,
1076
    },
1077
}
1078
1079
#[derive(Subcommand)]
1080
enum RootCmd {
1081
    /// Make an exported identity a root key
1082
    Add {
1083
        /// The identity to make a root, exported with `oxy identity export`
1084
        identity_file: PathBuf,
1085
        /// Where to write the proposal when more root signatures are needed
1086
        #[arg(long)]
1087
        out: Option<PathBuf>,
1088
    },
1089
    /// Remove a root key by KeyId prefix
1090
    Remove {
1091
        /// KeyId prefix of the root key
1092
        key: String,
1093
        /// Where to write the proposal when more root signatures are needed
1094
        #[arg(long)]
1095
        out: Option<PathBuf>,
1096
    },
1097
    /// Require this many root signatures on policy updates
1098
    Threshold {
1099
        /// Number of root signatures
1100
        n: u32,
1101
        /// Where to write the proposal when more root signatures are needed
1102
        #[arg(long)]
1103
        out: Option<PathBuf>,
1104
    },
1105
}
1106
1107
/// Open the repository containing the current directory.
1108121×
fn open() -> Result<Repo> {
1109121×
    let repo = Repo::open(&std::env::current_dir()?).context("opening repository")?;
1110121×
    match AT_OP.get().and_then(|o| o.as_deref()) {
11110×
        Some(op) => Ok(repo.at_op(op)?),
1112121×
        None => Ok(repo),
1113
    }
1114121×
}
1115
1116
/// `oxy man`: every page into `dir`, or the top-level page on stdout.
11172×
fn man(dir: Option<PathBuf>) -> Result<i32> {
1118
    use clap::CommandFactory;
11192×
    let cmd = Cli::command();
11202×
    match dir {
11211×
        Some(dir) => {
11221×
            std::fs::create_dir_all(&dir)?;
11231×
            clap_mangen::generate_to(cmd, &dir)?;
11241×
            let pages = std::fs::read_dir(&dir)?
1125122×
                .filter(|e| {
1126122×
                    e.as_ref()
1127122×
                        .is_ok_and(|e| e.path().extension().is_some_and(|x| x == "1"))
1128122×
                })
11291×
                .count();
11301×
            println!(
1131
                "{}",
11321×
                ui::done(format!("Wrote {pages} man pages to {}", dir.display()))
1133
            );
1134
        }
11351×
        None => clap_mangen::Man::new(cmd).render(&mut std::io::stdout())?,
1136
    }
11372×
    Ok(0)
11382×
}
1139
1140
/// Parse arguments and run; returns the process exit code.
1141151×
pub fn run() -> Result<i32> {
1142
    // The cloud stores (s3://, gs://, az://) for remotes kept on them.
1143151×
    oxy_strata::register();
1144151×
    let cli = Cli::parse();
1145151×
    ui::init(cli.plain);
1146151×
    AT_OP.set(cli.at_op.clone()).ok();
11470×
    match cli.cmd {
11484×
        Cmd::Completions { shell } => {
1149
            use clap::CommandFactory;
11504×
            clap_complete::generate(shell, &mut Cli::command(), "oxy", &mut std::io::stdout());
11514×
            Ok(0)
1152
        }
11532×
        Cmd::Man { dir } => man(dir),
115414×
        Cmd::Init { path, bare, store } => workspace::init(path, bare, store.as_deref()),
11558×
        Cmd::Status { json } => workspace::status(json),
1156
        Cmd::Prompt {
11570×
            format,
11580×
            glyphs,
11590×
            color,
11600×
        } => workspace::prompt(&format, glyphs, color.as_deref()),
1161
        Cmd::Commit {
116226×
            message,
116326×
            file,
116426×
            depends_on,
116526×
            paths,
116626×
            interactive,
116726×
            hunks,
1168
        } => {
116926×
            let message = match (message, file) {
117025×
                (Some(m), _) => m,
11711×
                (None, Some(f)) if f.as_os_str() == "-" => {
11720×
                    let mut s = String::new();
11730×
                    std::io::Read::read_to_string(&mut std::io::stdin(), &mut s)?;
11740×
                    s
1175
                }
11761×
                (None, Some(f)) => std::fs::read_to_string(&f).map_err(|e| {
11770×
                    anyhow::anyhow!("reading the message from {}: {e}", f.display())
11780×
                })?,
11790×
                (None, None) => anyhow::bail!("a commit message is required (-m or -F)"),
1180
            };
118126×
            workspace::commit(&message, &depends_on, &paths, interactive, &hunks)
1182
        }
11832×
        Cmd::Cat { path, change } => workspace::cat(&path, change.as_deref()),
11841×
        Cmd::Root { json } => workspace::root(json),
11851×
        Cmd::Version { json } => workspace::version(json),
11862×
        Cmd::Discard { paths, hunks } => workspace::discard(&paths, &hunks),
11872×
        Cmd::Hunks { json } => workspace::hunks(json),
11880×
        Cmd::Squash { change, into } => workspace::squash(&change, &into),
1189
        Cmd::Rebase {
11900×
            change,
11910×
            onto,
11920×
            into_working_copy,
11930×
        } => workspace::rebase(&change, &onto, into_working_copy),
11940×
        Cmd::Blame { path, json } => workspace::blame(&path, json),
11951×
        Cmd::Bisect { cmd } => match cmd {
11960×
            BisectCmd::Start => workspace::bisect_start(),
11970×
            BisectCmd::Good { changes } => workspace::bisect_mark(Some(true), &changes),
11980×
            BisectCmd::Bad { changes } => workspace::bisect_mark(Some(false), &changes),
11990×
            BisectCmd::Skip => workspace::bisect_mark(None, &[]),
12000×
            BisectCmd::Run { command } => workspace::bisect_run(&command),
12011×
            BisectCmd::Status { json } => workspace::bisect_status(json),
12020×
            BisectCmd::Reset => workspace::bisect_reset(),
1203
        },
1204
        Cmd::Log {
12058×
            revset,
12068×
            limit,
12078×
            verbose,
12088×
            path,
12098×
            lines,
12108×
            json,
12118×
        } => workspace::log(
12128×
            revset.as_deref(),
12138×
            limit,
12148×
            verbose,
12158×
            path.as_deref(),
12168×
            lines.as_deref(),
12178×
            json,
1218
        ),
12191×
        Cmd::Diff { change, json } => workspace::diff(change.as_deref(), json),
1220
        Cmd::Describe {
12214×
            message,
12224×
            change,
12234×
            json,
12244×
        } => match message {
12250×
            Some(m) => workspace::describe(&m, change.as_deref()),
12264×
            None if change.is_some() => {
12270×
                anyhow::bail!(
1228
                    "naming works on the working copy; to change a head's message pass -m"
1229
                )
1230
            }
12314×
            None => workspace::describe_name(json),
1232
        },
12330×
        Cmd::Amend { message, into } => workspace::amend(message.as_deref(), into.as_deref()),
12340×
        Cmd::Split { change, paths } => workspace::split(&change, &paths),
1235
        Cmd::Abandon {
12360×
            change,
12370×
            revset,
12380×
            yes,
12390×
        } => workspace::abandon(change.as_deref(), revset.as_deref(), yes),
1240
        Cmd::Show {
12412×
            change,
12422×
            revset,
12432×
            json,
12442×
        } => workspace::show(change.as_deref(), revset.as_deref(), json),
1245
        Cmd::Checkout {
12460×
            changes,
12470×
            discard,
12480×
            carry,
12490×
        } => workspace::checkout(&changes, discard, carry),
12501×
        Cmd::Resolve { json } => workspace::resolve(json),
12510×
        Cmd::Undo => workspace::undo(),
1252
        Cmd::Gc {
12532×
            now,
12542×
            expire_snapshots,
12552×
            remote,
12562×
        } => match remote {
12572×
            Some(name) => workspace::gc_remote(&name, now),
12580×
            None => workspace::gc(now, expire_snapshots),
1259
        },
12600×
        Cmd::Fsck { json } => workspace::fsck(json),
12610×
        Cmd::Doctor { offline, json } => workspace::doctor(offline, json),
12620×
        Cmd::Checkpoint => workspace::checkpoint(),
12631×
        Cmd::Op { cmd } => match cmd {
12641×
            OpCmd::Log { limit, json } => workspace::op_log(limit, json),
12650×
            OpCmd::Restore { op, discard } => workspace::op_restore(&op, discard),
12660×
            OpCmd::Revert { op } => workspace::op_revert(&op),
1267
        },
1268
        Cmd::Clone {
12695×
            url,
12705×
            dest,
12715×
            max_blob,
12725×
            sparse,
12735×
            depth,
12745×
            recursive,
12755×
        } => sync::clone(&url, dest, max_blob.as_deref(), &sparse, depth, recursive),
12760×
        Cmd::Deepen { depth, remote } => sync::deepen(&remote, depth),
12770×
        Cmd::Sparse { paths } => workspace::sparse(&paths),
12780×
        Cmd::Lock { path } => workspace::lock(&path),
12790×
        Cmd::Unlock { path } => workspace::unlock(&path),
12801×
        Cmd::Workspace { cmd } => match cmd {
12810×
            WorkspaceCmd::Add { path, changes } => workspace::workspace_add(&path, &changes),
12821×
            WorkspaceCmd::List { json } => workspace::workspace_list(json),
12830×
            WorkspaceCmd::Forget { workspace } => workspace::workspace_forget(&workspace),
1284
        },
128517×
        Cmd::Bookmark { cmd } => match cmd {
1286
            BookmarkCmd::Create {
12876×
                name,
12886×
                changes,
12896×
                upto,
12906×
                only,
12916×
            } => workspace::bookmark_create(&name, &changes, upto, only),
1292
            BookmarkCmd::Set {
12933×
                name,
12943×
                changes,
12953×
                upto,
12963×
                only,
12973×
            } => workspace::bookmark_set(&name, &changes, upto, only),
12980×
            BookmarkCmd::Delete { name } => workspace::bookmark_delete(&name),
12995×
            BookmarkCmd::List { all, verbose, json } => {
13005×
                workspace::bookmark_list(all, verbose, json)
1301
            }
13020×
            BookmarkCmd::Show { name, json } => workspace::bookmark_show(name.as_deref(), json),
1303
            BookmarkCmd::Switch {
13043×
                name,
13053×
                discard,
13063×
                carry,
13073×
            } => workspace::bookmark_switch(&name, discard, carry),
1308
        },
13090×
        Cmd::Merge { bookmark } => workspace::merge(&bookmark),
13100×
        Cmd::Auth { cmd } => match cmd {
1311
            AuthCmd::Login {
13120×
                hub,
13130×
                with_token,
13140×
                ca,
13150×
            } => auth::login(hub.as_deref(), with_token, ca),
13160×
            AuthCmd::Status => auth::status(),
13170×
            AuthCmd::Logout { hub } => auth::logout(hub.as_deref()),
13180×
            AuthCmd::Grant { hub } => auth::grant(hub.as_deref()),
1319
        },
13201×
        Cmd::Submodule { cmd } => match cmd {
1321
            SubmoduleCmd::Add {
13220×
                url,
13230×
                path,
13240×
                bookmark,
13250×
            } => sync::submodule_add(&url, &path, bookmark.as_deref()),
13260×
            SubmoduleCmd::Update { init, paths } => sync::submodule_update(init, &paths),
13271×
            SubmoduleCmd::Status { json } => sync::submodule_status(json),
13280×
            SubmoduleCmd::Remove { path } => sync::submodule_remove(&path),
1329
        },
133010×
        Cmd::Receipt { cmd } => match cmd {
13312×
            ReceiptCmd::List { rev, json } => receipt::list(rev.as_deref(), json),
1332
            ReceiptCmd::Show {
13331×
                receipt: r,
13341×
                rev,
13351×
                json,
13361×
            } => receipt::show(&r, rev.as_deref(), json),
1337
            ReceiptCmd::Export {
13383×
                receipt: r,
13393×
                file,
13403×
                rev,
13413×
                format,
13423×
            } => receipt::export(&r, &file, rev.as_deref(), &format),
13432×
            ReceiptCmd::Verify { file, json } => receipt::verify(&file, json),
13442×
            ReceiptCmd::Import { file } => receipt::import(&file),
1345
        },
13463×
        Cmd::Tag { cmd } => match cmd {
1347
            TagCmd::Create {
13482×
                name,
13492×
                changes,
13502×
                message,
13512×
            } => workspace::tag_create(&name, &changes, &message),
13521×
            TagCmd::List { json } => workspace::tag_list(json),
1353
        },
135410×
        Cmd::Remote { cmd } => match cmd {
1355
            RemoteCmd::Add {
13564×
                name,
13574×
                url,
13584×
                profile,
13594×
                region,
13604×
                endpoint,
13614×
                credentials,
13624×
            } => sync::remote_add(
13634×
                &name,
13644×
                &url,
13654×
                &[
13664×
                    ("profile", profile),
13674×
                    ("region", region),
13684×
                    ("endpoint", endpoint),
13694×
                    ("credentials", credentials),
13704×
                ],
1371
            ),
13723×
            RemoteCmd::Check { name } => sync::remote_check(&name),
13731×
            RemoteCmd::Remove { name } => sync::remote_remove(&name),
13742×
            RemoteCmd::List { json } => sync::remote_list(json),
1375
        },
13761×
        Cmd::Fetch { remote, json } => sync::fetch(remote.as_deref(), json),
13774×
        Cmd::Pull { remote, json } => sync::pull(remote.as_deref(), json),
1378
        Cmd::Push {
13797×
            remote,
13807×
            force,
13817×
            bookmark,
13827×
            delete,
13837×
            json,
13847×
        } => match delete {
13850×
            Some(name) => sync::push_delete(remote.as_deref(), &name, json),
13867×
            None => sync::push(remote.as_deref(), force, bookmark.as_deref(), json),
1387
        },
1388
        Cmd::Serve {
13890×
            root,
13900×
            bind,
13910×
            tokens,
13920×
            tls_cert,
13930×
            tls_key,
13940×
        } => sync::serve(root, &bind, tokens, tls_cert.zip(tls_key)),
13953×
        Cmd::Identity { cmd } => match cmd {
1396
            IdentityCmd::Create {
13972×
                name,
13982×
                email,
13992×
                local,
14002×
                expires,
14012×
            } => identity::create(name, email, local, expires),
14020×
            IdentityCmd::Show => identity::show(),
14031×
            IdentityCmd::Export { path, pem } => identity::export(path, pem),
14040×
            IdentityCmd::SignChallenge { challenge, json } => {
14050×
                identity::sign_challenge(&challenge, json)
1406
            }
14070×
            IdentityCmd::Rotate => identity::rotate(),
14080×
            IdentityCmd::Renew { expires } => identity::renew(expires),
14090×
            IdentityCmd::Revoke { key, reason } => identity::revoke(key.as_deref(), &reason),
14100×
            IdentityCmd::Delegate { cmd } => match cmd {
1411
                DelegateCmd::Add {
14120×
                    identity_file,
14130×
                    scope,
14140×
                    expires,
14150×
                } => identity::delegate_add(&identity_file, &scope, expires.as_deref()),
14160×
                DelegateCmd::Remove { key } => identity::delegate_remove(&key),
14170×
                DelegateCmd::List => identity::delegate_list(),
1418
            },
1419
        },
1420
        Cmd::Git {
14210×
            cmd: GitCmd::Export { git_dir, branch },
14220×
        } => sync::git_export(&git_dir, branch.as_deref()),
1423
        Cmd::Git {
14240×
            cmd: GitCmd::Fetch { url, branch, claim },
14250×
        } => sync::git_fetch(&url, &branch, claim),
1426
        Cmd::Git {
14270×
            cmd: GitCmd::Push { url, branch },
14280×
        } => sync::git_push(&url, &branch),
1429
        Cmd::Git {
1430
            cmd: GitCmd::Recover,
14310×
        } => sync::git_recover(),
1432
        Cmd::Git {
1433
            cmd:
1434
                GitCmd::Import {
14350×
                    git_dir,
14360×
                    dest,
14370×
                    branch,
14380×
                    claim,
1439
                },
14400×
        } => sync::git_import(&git_dir, &dest, &branch, claim),
1441
        Cmd::Git {
1442
            cmd:
1443
                GitCmd::Verify {
14440×
                    git_dir,
14450×
                    branch,
14460×
                    last,
14470×
                    max_differences,
1448
                },
14490×
        } => sync::git_verify(&git_dir, &branch, last, max_differences),
14505×
        Cmd::Policy { cmd } => match cmd {
14511×
            PolicyCmd::Init => identity::policy_init(),
14523×
            PolicyCmd::Show { json } => identity::policy_show(json),
1453
            PolicyCmd::Grant {
14540×
                identity_file,
14550×
                pattern,
14560×
                out,
14570×
            } => identity::policy_grant(&identity_file, pattern.as_deref(), out),
1458
            PolicyCmd::GrantSubject {
14591×
                subject,
14601×
                issuer,
14611×
                scope,
14621×
                pattern,
14631×
                out,
14641×
            } => identity::policy_grant_subject(&subject, &issuer, &scope, pattern.as_deref(), out),
14650×
            PolicyCmd::Revoke { key, out } => identity::policy_revoke(&key, out),
14660×
            PolicyCmd::Root { cmd } => match cmd {
14670×
                RootCmd::Add { identity_file, out } => {
14680×
                    identity::policy_root_add(&identity_file, out)
1469
                }
14700×
                RootCmd::Remove { key, out } => identity::policy_root_remove(&key, out),
14710×
                RootCmd::Threshold { n, out } => identity::policy_threshold(n, out),
1472
            },
14730×
            PolicyCmd::Sign { proposal, out } => identity::policy_sign(&proposal, out),
1474
        },
1475
        Cmd::Seal {
14760×
            flow: Some(url),
14770×
            job: Some(job),
14780×
            reject,
14790×
            json,
1480
            ..
14810×
        } => approve::seal(&url, &job, reject, json),
1482
        Cmd::Seal {
14830×
            changes,
14840×
            proposal: Some(url),
14850×
            json,
1486
            ..
14870×
        } if changes.is_empty() => proposal::seal(&url, json),
14880×
        Cmd::Seal { changes, json, .. } => identity::seal(&changes, json),
14890×
        Cmd::Proposal { cmd } => match cmd {
14900×
            ProposalCmd::Show { url, json } => proposal::show(&url, json),
14910×
            ProposalCmd::Land { url, force } => proposal::land(&url, force),
1492
        },
1493
        Cmd::Verify {
14941×
            change,
14951×
            revset,
14961×
            json,
14971×
        } => identity::verify(change.as_deref(), revset.as_deref(), json),
1498
        Cmd::Config {
14991×
            key,
15001×
            value,
15011×
            user,
15021×
            unset,
15031×
        } => identity::config(&key, value.as_deref().unwrap_or(""), user, unset),
1504
    }
1505151×
}
1506
1507
#[cfg(test)]
1508
mod help_tests {
1509
    use super::Cli;
1510
    use clap::CommandFactory;
1511
1512
    /// Every command and every argument explains itself, so `--help`,
1513
    /// completions and the man pages are complete.
1514
    #[test]
15151×
    fn every_command_and_argument_has_help() {
1516122×
        fn walk(cmd: &clap::Command, path: &str, missing: &mut Vec<String>) {
1517122×
            let here = format!("{path} {}", cmd.get_name()).trim().to_string();
1518122×
            if cmd.get_about().is_none() && !path.is_empty() {
15190×
                missing.push(format!("{here} (command)"));
1520122×
            }
1521221×
            for a in cmd.get_arguments() {
1522221×
                let id = a.get_id().as_str();
1523221×
                if id == "help" || id == "version" || (a.is_global_set() && !path.is_empty()) {
15240×
                    continue;
1525221×
                }
1526221×
                if a.get_help().is_none() && a.get_long_help().is_none() {
15270×
                    missing.push(format!("{here} {id}"));
1528221×
                }
1529
            }
1530122×
            for sub in cmd.get_subcommands() {
1531121×
                walk(sub, &here, missing);
1532121×
            }
1533122×
        }
15341×
        let mut missing = Vec::new();
15351×
        walk(&Cli::command(), "", &mut missing);
15361×
        assert!(
15371×
            missing.is_empty(),
1538
            "{} without help:\n{}",
15390×
            missing.len(),
15400×
            missing.join("\n")
1541
        );
15421×
    }
1543
}