OXYGENHUB

Coverage / src/cli/mod.rs 60.8%

200 of 329 lines run, 9 of 18 functions · run #292 on main · run missed

1
//! Command-line definitions and dispatch.
2
3
mod auth;
4
mod format;
5
mod identity;
6
mod json;
7
mod proposal;
8
mod receipt;
9
mod sync;
10
pub mod ui;
11
mod workspace;
12
13
use anyhow::{Context, Result};
14
use clap::{Parser, Subcommand};
15
use oxy_core::repo::Repo;
16
use std::path::PathBuf;
17
18
#[derive(Parser)]
19
#[command(
20
    name = "oxy",
21
    version = env!("OXY_VERSION_LONG"),
22
    about = "Oxygen: breathing fresh air into version control"
23
)]
24
struct Cli {
25
    /// Plain output: no colour, no spinner (also implied by NO_COLOR or a non-terminal)
26
    #[arg(long, global = true)]
27
    plain: bool,
28
    /// Read the repository as it was after operation OP (an ID from oxy op log, @ or @-); commands that would change it are refused
29
    #[arg(long, global = true, value_name = "OP")]
30
    at_op: Option<String>,
31
    #[command(subcommand)]
32
    cmd: Cmd,
33
}
34
35
/// `--at-op`, for `open` to apply.
36
static AT_OP: std::sync::OnceLock<Option<String>> = std::sync::OnceLock::new();
37
38
#[derive(Subcommand)]
39
enum Cmd {
40
    /// Create a repository in PATH (default: current directory)
41
    Init {
42
        /// Directory to create the repository in (default: the current directory)
43
        path: Option<PathBuf>,
44
        /// No working copy: an object store and references only, for hosting
45
        #[arg(long)]
46
        bare: bool,
47
        /// Keep the objects and the operation log on this store
48
        /// (dir://PATH, s3://BUCKET/PREFIX, gs://…, az://…) instead of
49
        /// in .oxy, with a local cache in front (storage.cache, 2 GiB)
50
        #[arg(long, value_name = "URL")]
51
        store: Option<String>,
52
    },
53
    /// Clone a repository from a local path or an http(s) URL
54
    Clone {
55
        /// Local path or http(s) URL of the repository
56
        url: String,
57
        /// Directory to clone into (default: the last part of the URL)
58
        dest: Option<PathBuf>,
59
        /// Leave blobs larger than this (e.g. 1M) to be fetched on first read
60
        #[arg(long)]
61
        max_blob: Option<String>,
62
        /// Materialize only these paths (repeatable); implies lazy blobs
63
        #[arg(long = "sparse")]
64
        sparse: Vec<String>,
65
        /// Shallow clone: fetch only this many levels of history below the heads
66
        #[arg(long)]
67
        depth: Option<u32>,
68
        /// Clone the subrepos too (as oxy submodule update --init)
69
        #[arg(long)]
70
        recursive: bool,
71
    },
72
    /// Fetch more history below a shallow clone's boundary
73
    Deepen {
74
        /// Levels of history to add below the boundary
75
        #[arg(default_value_t = 10)]
76
        depth: u32,
77
        /// Remote to fetch the history from
78
        #[arg(long, default_value = "origin")]
79
        remote: String,
80
    },
81
    /// Show or set the sparse filter (paths to materialize); re-checks out the bookmark
82
    Sparse {
83
        /// Paths to materialize; none prints the current filter
84
        paths: Vec<String>,
85
    },
86
    /// Show the working copy: changed paths and conflicts
87
    Status {
88
        /// Machine-readable output: paths, and every conflict with its kind and contributing changes
89
        #[arg(long)]
90
        json: bool,
91
    },
92
    /// One-line summary for shell prompts; fast and records nothing
93
    Prompt {
94
        /// 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
95
        #[arg(long, default_value = oxy_core::repo::DEFAULT_PROMPT_FORMAT)]
96
        format: String,
97
        /// Glyph format (%i %b %c %s%U%O) instead of the plain default
98
        #[arg(long)]
99
        glyphs: bool,
100
        /// Colour by state (cyan clean, yellow dirty, red conflicted): raw escapes, or guarded for a bash or zsh PS1
101
        #[arg(long, value_parser = ["raw", "bash", "zsh"])]
102
        color: Option<String>,
103
    },
104
    /// Record the working copy as a change on the current bookmark
105
    Commit {
106
        /// The change's message: a subject line, then optionally a blank line and a body
107
        #[arg(short, long, required_unless_present = "file", conflicts_with = "file")]
108
        message: Option<String>,
109
        /// Read the message from FILE (`-` for standard input)
110
        #[arg(short = 'F', long, value_name = "FILE")]
111
        file: Option<PathBuf>,
112
        /// Extra explicit dependencies (ChangeId prefix, #hash prefix)
113
        #[arg(long = "depends-on")]
114
        depends_on: Vec<String>,
115
        /// Commit only these paths; the rest stays as uncommitted work
116
        paths: Vec<String>,
117
        /// Choose hunks one by one
118
        #[arg(short, long)]
119
        interactive: bool,
120
        /// Commit these hunks (as `oxy hunks` numbers them), comma separated
121
        #[arg(long, value_delimiter = ',')]
122
        hunks: Vec<usize>,
123
    },
124
    /// Fold CHANGE into one of its dependencies (keeps that change's id)
125
    Squash {
126
        /// The change to fold (ChangeId prefix, #hash prefix)
127
        change: String,
128
        /// The dependency that absorbs it
129
        #[arg(long)]
130
        into: String,
131
    },
132
    /// Re-express CHANGE against another base state
133
    Rebase {
134
        /// The change to re-express (ChangeId prefix, #hash prefix)
135
        change: String,
136
        /// The changes, bookmark or tag whose state becomes the new base
137
        #[arg(long, required = true, num_args = 1..)]
138
        onto: Vec<String>,
139
        /// Where the rebase would be conflicted, merge the target into the
140
        /// current bookmark instead, leaving the conflict in the working
141
        /// copy to fix and commit
142
        #[arg(long)]
143
        into_working_copy: bool,
144
    },
145
    /// Show which change introduced each line of a file
146
    Blame {
147
        /// File to annotate, relative to the repository root
148
        path: String,
149
        /// Machine-readable output: one JSON document on stdout
150
        #[arg(long)]
151
        json: bool,
152
    },
153
    /// Find the change that introduced a regression
154
    Bisect {
155
        #[command(subcommand)]
156
        cmd: BisectCmd,
157
    },
158
    /// List changes reachable from the bookmark and the working copy
159
    Log {
160
        /// Show the changes a revset selects: `main` (a bookmark name means its
161
        /// heads; `bookmark(main)` only ever the bookmark), `main..feature &
162
        /// author(andy)`, `touches("src/**") & date(-7d..)` (see
163
        /// docs/revset_query_language.md)
164
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with_all = ["path", "lines"])]
165
        revset: Option<String>,
166
        /// Show at most this many changes
167
        #[arg(short = 'n', long)]
168
        limit: Option<usize>,
169
        /// Show full messages, dependencies, and signatures
170
        #[arg(short, long)]
171
        verbose: bool,
172
        /// Only changes touching this path (renames followed)
173
        #[arg(long)]
174
        path: Option<String>,
175
        /// Only changes that wrote or deleted lines START to END of PATH
176
        /// (numbered as in the working copy's base), or deleted lines from
177
        /// between them: the history of a function
178
        #[arg(short = 'L', value_name = "START,END:PATH", conflicts_with = "path")]
179
        lines: Option<String>,
180
        /// Machine-readable output: one JSON document on stdout
181
        #[arg(long)]
182
        json: bool,
183
    },
184
    /// Show what the working copy changes against its base
185
    Diff {
186
        /// A change instead of the working copy
187
        change: Option<String>,
188
        /// Machine-readable output: one JSON document on stdout
189
        #[arg(long)]
190
        json: bool,
191
    },
192
    /// Print a file as it is in a state (default: the working copy's base)
193
    Cat {
194
        /// File to print, relative to the repository root
195
        path: String,
196
        /// A bookmark or tag (its state), or a change: a change means its
197
        /// dependency closure, the change and what it depends on, so files
198
        /// only later changes touched are absent or at older versions
199
        #[arg(short = 'r', long)]
200
        change: Option<String>,
201
    },
202
    /// Print the repository root, workspace, and bookmark
203
    Root {
204
        /// Machine-readable output: one JSON document on stdout
205
        #[arg(long)]
206
        json: bool,
207
    },
208
    /// Print the version of oxy, its repository format, and protocol
209
    Version {
210
        /// Machine-readable output: one JSON document on stdout
211
        #[arg(long)]
212
        json: bool,
213
    },
214
    /// Restore paths to the working copy's base, or undo chosen hunks
215
    Discard {
216
        /// Paths to restore; none with --hunks, or everything with neither
217
        paths: Vec<String>,
218
        /// Hunk indices as `oxy hunks` numbers them, comma separated
219
        #[arg(long, value_delimiter = ',')]
220
        hunks: Vec<usize>,
221
    },
222
    /// List the working copy's hunks, numbered as commit --hunks expects
223
    Hunks {
224
        /// Machine-readable output: one JSON document on stdout
225
        #[arg(long)]
226
        json: bool,
227
    },
228
    /// With -m, change the message of a head; without, name the working
229
    /// copy for a build: its tag, or the nearest tag plus distance and
230
    /// change, or the bookmark and change, and -dirty
231
    Describe {
232
        /// The new message
233
        #[arg(short, long)]
234
        message: Option<String>,
235
        /// The head to describe (default: the one the working copy sits on)
236
        change: Option<String>,
237
        /// Machine-readable output (naming only)
238
        #[arg(long, conflicts_with = "message")]
239
        json: bool,
240
    },
241
    /// Fold the working copy into the head it sits on, or into CHANGE with --into
242
    Amend {
243
        /// Replace the message too
244
        #[arg(short, long)]
245
        message: Option<String>,
246
        /// Amend an older change; the edits must touch only lines it already knows
247
        #[arg(long)]
248
        into: Option<String>,
249
    },
250
    /// Split a head: the named paths become a separate first change
251
    Split {
252
        /// The head to split
253
        change: String,
254
        /// Paths whose edits become the first change
255
        paths: Vec<String>,
256
    },
257
    /// Drop a change from the bookmark; its content stays on disk as uncommitted work
258
    Abandon {
259
        /// The change to drop (ChangeId prefix, #hash prefix)
260
        #[arg(required_unless_present = "revset")]
261
        change: Option<String>,
262
        /// Drop every change a revset selects, newest first
263
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
264
        revset: Option<String>,
265
        /// Drop more than five changes without asking
266
        #[arg(long, short = 'y')]
267
        yes: bool,
268
    },
269
    /// Show one change (ChangeId prefix, #hash prefix, or @), or those a revset selects
270
    Show {
271
        /// ChangeId prefix, #hash prefix, or @ for the working copy
272
        #[arg(required_unless_present = "revset")]
273
        change: Option<String>,
274
        /// Show every change a revset selects
275
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
276
        revset: Option<String>,
277
        /// Machine-readable output: one JSON document on stdout
278
        #[arg(long)]
279
        json: bool,
280
    },
281
    /// Move the working copy to the state formed by CHANGE... (default: the bookmark heads)
282
    Checkout {
283
        /// Changes whose state to check out (default: the bookmark heads)
284
        changes: Vec<String>,
285
        /// Throw away uncommitted working-copy changes
286
        #[arg(long)]
287
        discard: bool,
288
        /// Take uncommitted changes along; refused when the target has
289
        /// other versions of the files they touch
290
        #[arg(long, conflicts_with = "discard")]
291
        carry: bool,
292
    },
293
    /// Report which conflicts of the working copy's base are resolved by the current files
294
    Resolve {
295
        /// Machine-readable output: one JSON document on stdout
296
        #[arg(long)]
297
        json: bool,
298
    },
299
    /// Undo the last operation
300
    Undo,
301
    /// Write a checkpoint of the current bookmark's state now
302
    Checkpoint,
303
    /// Print a shell completion script: `oxy completions bash > ~/.local/share/bash-completion/completions/oxy`
304
    Completions {
305
        /// bash, zsh, fish, elvish or powershell
306
        shell: clap_complete::Shell,
307
    },
308
    /// Write man pages (oxy.1 and one per command) into DIR, or print oxy.1
309
    Man {
310
        /// Directory to write every page into, e.g. ~/.local/share/man/man1
311
        #[arg(long)]
312
        dir: Option<PathBuf>,
313
    },
314
    /// Check the identity, configuration and remotes, and say what to do about any problem
315
    Doctor {
316
        /// Do not contact the remotes
317
        #[arg(long)]
318
        offline: bool,
319
        /// Machine-readable output: one JSON document on stdout
320
        #[arg(long)]
321
        json: bool,
322
    },
323
    /// Check the repository's integrity: objects, operation log, references, signatures, checkpoints
324
    Fsck {
325
        /// Machine-readable output: one JSON document on stdout
326
        #[arg(long)]
327
        json: bool,
328
    },
329
    /// Prune unreachable objects older than the grace period and repack everything into one pack
330
    Gc {
331
        /// Ignore the grace period (core.gc-grace) and prune immediately
332
        #[arg(long)]
333
        now: bool,
334
        /// Keep no past working-copy snapshots, only each workspace's current one, so files only they held go (core.snapshot-retention, default 7 days)
335
        #[arg(long)]
336
        expire_snapshots: bool,
337
        /// 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)
338
        #[arg(long, value_name = "NAME")]
339
        remote: Option<String>,
340
    },
341
    /// List operations
342
    #[command(name = "op")]
343
    Op {
344
        #[command(subcommand)]
345
        cmd: OpCmd,
346
    },
347
    /// Take the advisory local lock on a lockable file, making it writable
348
    Lock {
349
        /// The lockable file
350
        path: String,
351
    },
352
    /// Release the local lock and make the file read-only again
353
    Unlock {
354
        /// The locked file
355
        path: String,
356
    },
357
    /// Workspaces: extra checkout directories sharing this repository
358
    Workspace {
359
        #[command(subcommand)]
360
        cmd: WorkspaceCmd,
361
    },
362
    /// Bookmarks: named states; each workspace works on one
363
    Bookmark {
364
        #[command(subcommand)]
365
        cmd: BookmarkCmd,
366
    },
367
    /// Union another bookmark's heads into the current one (no merge change)
368
    Merge {
369
        /// The bookmark whose heads to add
370
        bookmark: String,
371
    },
372
    /// Sign in to a hub once, for every repository on it
373
    Auth {
374
        #[command(subcommand)]
375
        cmd: AuthCmd,
376
    },
377
    /// Subrepositories: nested repositories pinned to a state
378
    Submodule {
379
        #[command(subcommand)]
380
        cmd: SubmoduleCmd,
381
    },
382
    /// Execution receipts: signed records of what a runner ran on a state
383
    Receipt {
384
        #[command(subcommand)]
385
        cmd: ReceiptCmd,
386
    },
387
    /// Tags: immutable named states
388
    Tag {
389
        #[command(subcommand)]
390
        cmd: TagCmd,
391
    },
392
    /// Manage remotes
393
    Remote {
394
        #[command(subcommand)]
395
        cmd: RemoteCmd,
396
    },
397
    /// Fetch every bookmark of a remote into its tracking references
398
    Fetch {
399
        /// Remote name (default: origin)
400
        remote: Option<String>,
401
        /// Machine-readable output: one JSON document on stdout
402
        #[arg(long)]
403
        json: bool,
404
    },
405
    /// Fetch, then union the remote bookmark into the local one (no merge change)
406
    Pull {
407
        /// Remote name (default: origin)
408
        remote: Option<String>,
409
        /// Machine-readable output: one JSON document on stdout
410
        #[arg(long)]
411
        json: bool,
412
    },
413
    /// Push the current bookmark to a remote
414
    Push {
415
        /// Remote name (default: origin)
416
        remote: Option<String>,
417
        /// Allow dropping heads the remote has
418
        #[arg(long)]
419
        force: bool,
420
        /// Push this bookmark instead of the workspace's current one
421
        #[arg(short = 'b', long)]
422
        bookmark: Option<String>,
423
        /// Delete this bookmark on the remote (never its default bookmark);
424
        /// the local bookmark is kept
425
        #[arg(long, value_name = "NAME", conflicts_with_all = ["bookmark", "force"])]
426
        delete: Option<String>,
427
        /// Machine-readable output: one JSON document on stdout
428
        #[arg(long)]
429
        json: bool,
430
    },
431
    /// Serve repositories under ROOT over HTTPS (with --tls-cert/--tls-key) or plain HTTP
432
    Serve {
433
        /// Directory with one repository per subdirectory
434
        #[arg(long, default_value = ".")]
435
        root: PathBuf,
436
        /// Address and port to listen on
437
        #[arg(long, default_value = "127.0.0.1:8890")]
438
        bind: String,
439
        /// Bearer token allowed to push (repeatable); none means open
440
        #[arg(long = "token")]
441
        tokens: Vec<String>,
442
        /// PEM certificate chain; enables HTTPS together with --tls-key
443
        #[arg(long, requires = "tls_key")]
444
        tls_cert: Option<PathBuf>,
445
        /// PEM private key
446
        #[arg(long, requires = "tls_cert")]
447
        tls_key: Option<PathBuf>,
448
    },
449
    /// Manage the signing identity
450
    Identity {
451
        #[command(subcommand)]
452
        cmd: IdentityCmd,
453
    },
454
    /// Seal changes with your key: named ones, or every change on the current bookmark you can authenticate but have not
455
    Seal {
456
        /// Changes to seal (default: every change on the bookmark you can authenticate and have not sealed)
457
        changes: Vec<String>,
458
        /// Seal every change of a hub proposal and push the seal (your approval)
459
        #[arg(long, conflicts_with = "changes")]
460
        proposal: Option<String>,
461
        /// Machine-readable output: one JSON document on stdout
462
        #[arg(long)]
463
        json: bool,
464
    },
465
    /// Hub proposals: show one, or land it from this client
466
    Proposal {
467
        #[command(subcommand)]
468
        cmd: ProposalCmd,
469
    },
470
    /// Verify the signatures on a change (default: every change in the log)
471
    Verify {
472
        /// The change to verify (default: every change in the log)
473
        change: Option<String>,
474
        /// Verify every change a revset selects: `release..main & unsigned()`
475
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
476
        revset: Option<String>,
477
        /// Machine-readable output: one JSON document on stdout
478
        #[arg(long)]
479
        json: bool,
480
    },
481
    /// Git interoperability
482
    Git {
483
        #[command(subcommand)]
484
        cmd: GitCmd,
485
    },
486
    /// Manage the trust policy (who may update which bookmarks)
487
    Policy {
488
        #[command(subcommand)]
489
        cmd: PolicyCmd,
490
    },
491
    /// 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)
492
    Config {
493
        /// The key, such as author.name or remote.origin.token
494
        key: String,
495
        /// The value to set (none with --unset); `-` reads it from standard input, out of the shell's history
496
        #[arg(required_unless_present = "unset")]
497
        value: Option<String>,
498
        /// Write to the user file (~/.config/oxy/config.toml) instead of this repository
499
        #[arg(long)]
500
        user: bool,
501
        /// Remove the key from this repository's file (or the user file with --user)
502
        #[arg(long)]
503
        unset: bool,
504
    },
505
}
506
507
#[derive(Subcommand)]
508
enum OpCmd {
509
    /// List operations, newest first, with what each changed
510
    Log {
511
        /// Show only the latest N (snapshots folded together count as one)
512
        #[arg(short = 'n', long)]
513
        limit: Option<usize>,
514
        /// Machine-readable output: one JSON document on stdout
515
        #[arg(long)]
516
        json: bool,
517
    },
518
    /// Go back to the bookmarks and working copy as they were after OP (recorded as a new operation, so it can be undone)
519
    Restore {
520
        /// The operation: an ID prefix from oxy op log, @ or @-
521
        op: String,
522
        /// Throw away uncommitted working-copy changes
523
        #[arg(long)]
524
        discard: bool,
525
    },
526
    /// Undo OP alone, keeping every operation after it: the bookmarks it moved go back
527
    Revert {
528
        /// The operation: an ID prefix from oxy op log
529
        op: String,
530
    },
531
}
532
533
#[derive(Subcommand)]
534
enum WorkspaceCmd {
535
    /// Create a workspace at PATH checked out on CHANGE... (default: the bookmark heads)
536
    Add {
537
        /// Directory for the new workspace (must be empty or absent)
538
        path: PathBuf,
539
        /// Changes whose state to check out there
540
        changes: Vec<String>,
541
    },
542
    /// List workspaces and their working-copy changes
543
    List {
544
        /// Machine-readable output: one JSON document on stdout
545
        #[arg(long)]
546
        json: bool,
547
    },
548
    /// Stop tracking a workspace (by id prefix or path); its files stay
549
    Forget {
550
        /// Workspace id prefix or path
551
        workspace: String,
552
    },
553
}
554
555
#[derive(Subcommand)]
556
enum BisectCmd {
557
    /// Begin; remembers where the working copy was
558
    Start,
559
    /// Mark CHANGE... (or the state under test) as good
560
    Good {
561
        /// Changes known to be good (default: the state under test)
562
        changes: Vec<String>,
563
    },
564
    /// Mark CHANGE... (or the state under test) as bad
565
    Bad {
566
        /// Changes known to be bad (default: the state under test)
567
        changes: Vec<String>,
568
    },
569
    /// The state under test cannot be tested; try another
570
    Skip,
571
    /// Run a command for each step: exit 0 good, 125 skip, else bad
572
    Run {
573
        /// Command and arguments to run at each step
574
        #[arg(required = true, trailing_var_arg = true)]
575
        command: Vec<String>,
576
    },
577
    /// Where the search stands
578
    Status {
579
        /// Machine-readable output: one JSON document on stdout
580
        #[arg(long)]
581
        json: bool,
582
    },
583
    /// Restore the working copy and forget the search
584
    Reset,
585
}
586
587
#[derive(Subcommand)]
588
enum BookmarkCmd {
589
    /// Create a bookmark at CHANGE... (default: the working copy's base)
590
    Create {
591
        /// Name of the new bookmark
592
        name: String,
593
        /// Its heads (default: the working copy's base). A state is its
594
        /// heads and what they depend on: a change alone may leave out
595
        /// earlier changes of the current state, which is refused unless
596
        /// --upto or --only says which is meant
597
        changes: Vec<String>,
598
        /// Everything of the current state up to CHANGE..., as a Git
599
        /// branch at a commit would hold
600
        #[arg(long, conflicts_with = "only")]
601
        upto: bool,
602
        /// Just CHANGE... and what they depend on. Other changes to the
603
        /// same files are left out, so a file can come out partly edited;
604
        /// to add one change to a bookmark's work, give the bookmark's
605
        /// heads with it instead: `bookmark set NAME <its heads> CHANGE`
606
        #[arg(long)]
607
        only: bool,
608
    },
609
    /// Point an existing bookmark at CHANGE...
610
    Set {
611
        /// The bookmark to move
612
        name: String,
613
        /// Its new heads. A change alone may leave out changes the
614
        /// bookmark now holds that were recorded before it, which is
615
        /// refused unless --upto or --only says which is meant
616
        changes: Vec<String>,
617
        /// Everything the bookmark holds up to CHANGE..., as a Git branch
618
        /// moved to a commit would hold
619
        #[arg(long, conflicts_with = "only")]
620
        upto: bool,
621
        /// Just CHANGE... and what they depend on. Other changes to the
622
        /// same files are left out, so a file can come out partly edited;
623
        /// to add one change to a bookmark's work, give the bookmark's
624
        /// heads with it instead: `bookmark set NAME <its heads> CHANGE`
625
        #[arg(long)]
626
        only: bool,
627
    },
628
    /// Remove a bookmark; its changes stay
629
    Delete {
630
        /// The bookmark to remove
631
        name: String,
632
    },
633
    /// List bookmarks with their heads and difference from origin
634
    List {
635
        /// Also list remotes' bookmarks that have no local bookmark
636
        #[arg(long, short)]
637
        all: bool,
638
        /// Each head of every bookmark, as `bookmark show` prints them
639
        #[arg(long, short)]
640
        verbose: bool,
641
        /// Machine-readable output: one JSON document on stdout
642
        #[arg(long)]
643
        json: bool,
644
    },
645
    /// A bookmark's heads: each change nothing else on it depends on,
646
    /// newest first. A bookmark name is also a revset for its heads
647
    /// (`oxy log -r NAME`, or `bookmark(NAME)` to mean only the bookmark)
648
    Show {
649
        /// The bookmark, or REMOTE/NAME (default: the current one)
650
        name: Option<String>,
651
        /// Machine-readable output: one JSON document on stdout
652
        #[arg(long)]
653
        json: bool,
654
    },
655
    /// Make NAME this workspace's bookmark and check it out. Uncommitted work stops it; --carry takes the work along, --discard drops it
656
    Switch {
657
        /// The bookmark to work on; one only a remote has (NAME or REMOTE/NAME) is created from it
658
        name: String,
659
        /// Throw away uncommitted working-copy changes
660
        #[arg(long)]
661
        discard: bool,
662
        /// Take uncommitted changes along; refused when NAME has other
663
        /// versions of the files they touch
664
        #[arg(long, conflicts_with = "discard")]
665
        carry: bool,
666
    },
667
}
668
669
#[derive(Subcommand)]
670
enum AuthCmd {
671
    /// Sign in to HUB in the browser (device sign-in) and keep the token for
672
    /// every repository there
673
    Login {
674
        /// The hub, as https://oxygenhub.io or oxygenhub.io (default: this checkout's origin)
675
        hub: Option<String>,
676
        /// Read a token from standard input instead (for CI and scripts)
677
        #[arg(long)]
678
        with_token: bool,
679
        /// PEM file of extra roots to trust (a hub with a self-signed certificate)
680
        #[arg(long)]
681
        ca: Option<PathBuf>,
682
    },
683
    /// List the hubs you are signed in to, checking each token with its hub
684
    Status,
685
    /// Forget HUB's token and revoke it on the hub
686
    Logout {
687
        /// The hub (default: this checkout's origin, or the only one)
688
        hub: Option<String>,
689
    },
690
}
691
692
#[derive(Subcommand)]
693
enum SubmoduleCmd {
694
    /// Clone URL (Oxygen or Git) into PATH and register it in .oxymodules
695
    Add {
696
        /// URL or path of the Oxygen or Git repository
697
        url: String,
698
        /// Where to put it, relative to the repository root
699
        path: String,
700
        /// Bookmark (Oxygen) or branch (Git) to check out and track
701
        #[arg(long)]
702
        bookmark: Option<String>,
703
    },
704
    /// Bring nested repositories to their pins
705
    Update {
706
        /// Clone nested repositories that are absent
707
        #[arg(long)]
708
        init: bool,
709
        /// Subrepos to update (default: all)
710
        paths: Vec<String>,
711
    },
712
    /// List subrepos with their pins and on-disk state
713
    Status {
714
        /// Machine-readable output: one JSON document on stdout
715
        #[arg(long)]
716
        json: bool,
717
    },
718
    /// Unregister PATH; the directory stays, the node goes with the next commit
719
    Remove {
720
        /// The subrepo to unregister
721
        path: String,
722
    },
723
}
724
725
#[derive(Subcommand)]
726
enum ReceiptCmd {
727
    /// The receipts kept for a state (default: the bookmark heads)
728
    List {
729
        /// Change, bookmark or tag whose state to look at
730
        rev: Option<String>,
731
        /// Machine-readable output: one JSON document on stdout
732
        #[arg(long)]
733
        json: bool,
734
    },
735
    /// One receipt in full, and whether its signature verifies
736
    Show {
737
        /// The receipt (a prefix of its hash, as `list` shows it)
738
        receipt: String,
739
        /// Change, bookmark or tag whose state holds it
740
        #[arg(long)]
741
        rev: Option<String>,
742
        /// Machine-readable output: one JSON document on stdout
743
        #[arg(long)]
744
        json: bool,
745
    },
746
    /// Write a signed receipt to FILE
747
    Export {
748
        /// The receipt (a prefix of its hash, as `list` shows it)
749
        receipt: String,
750
        /// Where to write it
751
        file: String,
752
        /// Change, bookmark or tag whose state holds it
753
        #[arg(long)]
754
        rev: Option<String>,
755
    },
756
    /// Check a signed receipt in FILE without keeping it
757
    Verify {
758
        /// A signed receipt, as a runner or `export` writes it
759
        file: String,
760
        /// Machine-readable output: one JSON document on stdout
761
        #[arg(long)]
762
        json: bool,
763
    },
764
    /// Verify a signed receipt in FILE and keep it with its state
765
    Import {
766
        /// A signed receipt, as a runner or `export` writes it
767
        file: String,
768
    },
769
}
770
771
#[derive(Subcommand)]
772
enum TagCmd {
773
    /// Tag the state of CHANGE... (default: the bookmark heads)
774
    Create {
775
        /// Name of the tag; tags never move
776
        name: String,
777
        /// Changes whose state to tag (default: the bookmark heads)
778
        changes: Vec<String>,
779
        /// A message recorded with the tag
780
        #[arg(short, long, default_value = "")]
781
        message: String,
782
    },
783
    /// List tags and the states they name
784
    List {
785
        /// Machine-readable output: one JSON document on stdout
786
        #[arg(long)]
787
        json: bool,
788
    },
789
}
790
791
#[derive(Subcommand)]
792
enum RemoteCmd {
793
    /// Add a remote
794
    Add {
795
        /// Name to refer to the remote by, such as origin
796
        name: String,
797
        /// 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
798
        url: String,
799
        /// For an s3:// store: the AWS profile to use (default: AWS_PROFILE, else "default")
800
        #[arg(long)]
801
        profile: Option<String>,
802
        /// For an s3:// store: its region (default: the environment, the profile, else asked of S3)
803
        #[arg(long)]
804
        region: Option<String>,
805
        /// For an s3://, gs:// or az:// store: another endpoint, such as an S3-compatible service
806
        #[arg(long)]
807
        endpoint: Option<String>,
808
        /// For a gs:// store: a service account key file, or application default credentials
809
        #[arg(long)]
810
        credentials: Option<String>,
811
    },
812
    /// Check a remote: that it is reachable with the credentials in hand, what it holds, and (for a store) that it behaves
813
    Check {
814
        /// The remote to check
815
        name: String,
816
    },
817
    /// Remove a remote
818
    Remove {
819
        /// The remote to remove
820
        name: String,
821
    },
822
    /// List remotes and their URLs
823
    List {
824
        /// Machine-readable output: one JSON document on stdout
825
        #[arg(long)]
826
        json: bool,
827
    },
828
}
829
830
#[derive(Subcommand)]
831
enum ProposalCmd {
832
    /// Show a proposal by its hub URL
833
    Show {
834
        /// The proposal's URL on the hub
835
        url: String,
836
        /// Machine-readable output: one JSON document on stdout
837
        #[arg(long)]
838
        json: bool,
839
    },
840
    /// Fetch the proposal's changes, set the target bookmark to the projected state, and push with your key
841
    Land {
842
        /// The proposal's URL on the hub
843
        url: String,
844
        /// Land even when the hub reports blockers
845
        #[arg(long)]
846
        force: bool,
847
    },
848
}
849
850
#[derive(Subcommand)]
851
enum IdentityCmd {
852
    /// Generate a composite Ed25519 + ML-DSA-65 key pair and make it your author identity
853
    Create {
854
        /// Your name (default: author.name)
855
        #[arg(long)]
856
        name: Option<String>,
857
        /// Your email (default: author.email)
858
        #[arg(long)]
859
        email: Option<String>,
860
        /// Record the author in this repository only, not in the user config
861
        #[arg(long)]
862
        local: bool,
863
        /// Expire the identity this many days from now
864
        #[arg(long)]
865
        expires: Option<u64>,
866
    },
867
    /// Show the configured identity
868
    Show,
869
    /// Write your identity object to a file, to hand to a policy holder
870
    Export {
871
        /// File to write (default: <key>.identity in the current directory)
872
        path: Option<PathBuf>,
873
    },
874
    /// Sign a host's challenge (hex, at least 16 bytes) to prove you hold your key; prints the signature as hex
875
    SignChallenge {
876
        /// The host's challenge, as hex
877
        challenge: String,
878
        /// Machine-readable output: one JSON document on stdout
879
        #[arg(long)]
880
        json: bool,
881
    },
882
    /// Move to a fresh key pair; the policy follows if it names your key
883
    Rotate,
884
    /// Re-issue your identity with a new expiry (in days from now; 0 = never)
885
    Renew {
886
        /// Days from now until it expires; 0 for never
887
        #[arg(long)]
888
        expires: u64,
889
    },
890
    /// Revoke a key: yours by default, or any key if you hold a policy root
891
    Revoke {
892
        /// KeyId prefix (default: your own key)
893
        key: Option<String>,
894
        /// Why, recorded in the revocation
895
        #[arg(long, default_value = "")]
896
        reason: String,
897
    },
898
    /// Keys allowed to sign or seal on your behalf
899
    Delegate {
900
        #[command(subcommand)]
901
        cmd: DelegateCmd,
902
    },
903
}
904
905
#[derive(Subcommand)]
906
enum DelegateCmd {
907
    /// Add a delegate from an exported identity file
908
    Add {
909
        /// The delegates' exported identity files: one rotation for all of them
910
        #[arg(required = true)]
911
        identity_file: Vec<PathBuf>,
912
        /// What it may do for you: changes, refs, seal (comma-separated) or all.
913
        /// An agent gets `changes`; a host that lands for you needs `changes,refs`
914
        #[arg(long, default_value = "changes")]
915
        scope: String,
916
        /// How long for: 30m, 8h, 7d, or a number of days (default: until removed)
917
        #[arg(long)]
918
        expires: Option<String>,
919
    },
920
    /// Remove a delegate by KeyId prefix
921
    Remove {
922
        /// KeyId prefix of the delegate
923
        key: String,
924
    },
925
    /// List delegates
926
    List,
927
}
928
929
#[derive(Subcommand)]
930
enum GitCmd {
931
    /// Export the current bookmark to a Git repository (created bare if absent)
932
    Export {
933
        /// Git repository to write to (created bare if absent)
934
        git_dir: PathBuf,
935
        /// Git branch to write (default: the bookmark name)
936
        #[arg(long)]
937
        branch: Option<String>,
938
    },
939
    /// Fetch a branch from a Git remote (path or URL) into the current bookmark
940
    Fetch {
941
        /// Git remote: a path or URL
942
        url: String,
943
        /// Branch to fetch
944
        #[arg(long, default_value = "main")]
945
        branch: String,
946
        /// Author your own commits (Git author email = your identity's) with your key; sets git.claim
947
        #[arg(long)]
948
        claim: bool,
949
    },
950
    /// Push the current bookmark to a branch of a Git remote (fetch first)
951
    Push {
952
        /// Git remote: a path or URL
953
        url: String,
954
        /// Branch to push to
955
        #[arg(long, default_value = "main")]
956
        branch: String,
957
    },
958
    /// 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
959
    Recover,
960
    /// Check this repository's import of a Git branch: every commit's tree must be reproduced exactly
961
    Verify {
962
        /// The Git repository the import came from
963
        git_dir: PathBuf,
964
        /// Branch that was imported
965
        #[arg(long, default_value = "main")]
966
        branch: String,
967
        /// Rebuild only the last N commits (the others are followed, not checked)
968
        #[arg(long, value_name = "N")]
969
        last: Option<usize>,
970
        /// Stop after N differences (0: check every commit whatever it finds)
971
        #[arg(long, value_name = "N", default_value_t = 50)]
972
        max_differences: usize,
973
    },
974
    /// Import a Git branch into a new Oxygen repository at DEST
975
    Import {
976
        /// Git repository to read
977
        git_dir: PathBuf,
978
        /// Directory for the new Oxygen repository
979
        dest: PathBuf,
980
        /// Branch to import
981
        #[arg(long, default_value = "main")]
982
        branch: String,
983
        /// Author your own commits (Git author email = your identity's) with your key; sets git.claim
984
        #[arg(long)]
985
        claim: bool,
986
    },
987
}
988
989
#[derive(Subcommand)]
990
enum PolicyCmd {
991
    /// Create the initial policy with your identity as the only root
992
    Init,
993
    /// Show the current policy
994
    Show {
995
        /// Machine-readable output: one JSON document on stdout
996
        #[arg(long)]
997
        json: bool,
998
    },
999
    /// Allow an identity (from `oxy identity export`) to update bookmarks
1000
    Grant {
1001
        /// The identity to grant, exported with `oxy identity export`
1002
        identity_file: PathBuf,
1003
        /// Reference pattern the grant applies to (default: every bookmark)
1004
        #[arg(long)]
1005
        pattern: Option<String>,
1006
        /// Where to write the proposal when more root signatures are needed
1007
        #[arg(long)]
1008
        out: Option<PathBuf>,
1009
    },
1010
    /// Revoke a key (KeyId prefix of an identity in the policy)
1011
    Revoke {
1012
        /// KeyId prefix of the identity
1013
        key: String,
1014
        /// Where to write the proposal when more root signatures are needed
1015
        #[arg(long)]
1016
        out: Option<PathBuf>,
1017
    },
1018
    /// Manage root keys and the signature threshold for policy updates
1019
    Root {
1020
        #[command(subcommand)]
1021
        cmd: RootCmd,
1022
    },
1023
    /// Add your root signature to a proposal file; applies it once the threshold is met
1024
    Sign {
1025
        /// The proposal file to sign
1026
        proposal: PathBuf,
1027
        /// Where to write the proposal if it still needs signatures (default: in place)
1028
        #[arg(long)]
1029
        out: Option<PathBuf>,
1030
    },
1031
}
1032
1033
#[derive(Subcommand)]
1034
enum RootCmd {
1035
    /// Make an exported identity a root key
1036
    Add {
1037
        /// The identity to make a root, exported with `oxy identity export`
1038
        identity_file: PathBuf,
1039
        /// Where to write the proposal when more root signatures are needed
1040
        #[arg(long)]
1041
        out: Option<PathBuf>,
1042
    },
1043
    /// Remove a root key by KeyId prefix
1044
    Remove {
1045
        /// KeyId prefix of the root key
1046
        key: String,
1047
        /// Where to write the proposal when more root signatures are needed
1048
        #[arg(long)]
1049
        out: Option<PathBuf>,
1050
    },
1051
    /// Require this many root signatures on policy updates
1052
    Threshold {
1053
        /// Number of root signatures
1054
        n: u32,
1055
        /// Where to write the proposal when more root signatures are needed
1056
        #[arg(long)]
1057
        out: Option<PathBuf>,
1058
    },
1059
}
1060
1061
/// Open the repository containing the current directory.
1062115×
fn open() -> Result<Repo> {
1063115×
    let repo = Repo::open(&std::env::current_dir()?).context("opening repository")?;
1064115×
    match AT_OP.get().and_then(|o| o.as_deref()) {
10650×
        Some(op) => Ok(repo.at_op(op)?),
1066115×
        None => Ok(repo),
1067
    }
1068115×
}
1069
1070
/// `oxy man`: every page into `dir`, or the top-level page on stdout.
10712×
fn man(dir: Option<PathBuf>) -> Result<i32> {
1072
    use clap::CommandFactory;
10732×
    let cmd = Cli::command();
10742×
    match dir {
10751×
        Some(dir) => {
10761×
            std::fs::create_dir_all(&dir)?;
10771×
            clap_mangen::generate_to(cmd, &dir)?;
10781×
            let pages = std::fs::read_dir(&dir)?
1079120×
                .filter(|e| {
1080120×
                    e.as_ref()
1081120×
                        .is_ok_and(|e| e.path().extension().is_some_and(|x| x == "1"))
1082120×
                })
10831×
                .count();
10841×
            println!(
1085
                "{}",
10861×
                ui::done(format!("Wrote {pages} man pages to {}", dir.display()))
1087
            );
1088
        }
10891×
        None => clap_mangen::Man::new(cmd).render(&mut std::io::stdout())?,
1090
    }
10912×
    Ok(0)
10922×
}
1093
1094
/// Parse arguments and run; returns the process exit code.
1095145×
pub fn run() -> Result<i32> {
1096
    // The cloud stores (s3://, gs://, az://) for remotes kept on them.
1097145×
    oxy_strata::register();
1098145×
    let cli = Cli::parse();
1099145×
    ui::init(cli.plain);
1100145×
    AT_OP.set(cli.at_op.clone()).ok();
11010×
    match cli.cmd {
11024×
        Cmd::Completions { shell } => {
1103
            use clap::CommandFactory;
11044×
            clap_complete::generate(shell, &mut Cli::command(), "oxy", &mut std::io::stdout());
11054×
            Ok(0)
1106
        }
11072×
        Cmd::Man { dir } => man(dir),
110814×
        Cmd::Init { path, bare, store } => workspace::init(path, bare, store.as_deref()),
11098×
        Cmd::Status { json } => workspace::status(json),
1110
        Cmd::Prompt {
11110×
            format,
11120×
            glyphs,
11130×
            color,
11140×
        } => workspace::prompt(&format, glyphs, color.as_deref()),
1115
        Cmd::Commit {
111626×
            message,
111726×
            file,
111826×
            depends_on,
111926×
            paths,
112026×
            interactive,
112126×
            hunks,
1122
        } => {
112326×
            let message = match (message, file) {
112425×
                (Some(m), _) => m,
11251×
                (None, Some(f)) if f.as_os_str() == "-" => {
11260×
                    let mut s = String::new();
11270×
                    std::io::Read::read_to_string(&mut std::io::stdin(), &mut s)?;
11280×
                    s
1129
                }
11301×
                (None, Some(f)) => std::fs::read_to_string(&f).map_err(|e| {
11310×
                    anyhow::anyhow!("reading the message from {}: {e}", f.display())
11320×
                })?,
11330×
                (None, None) => anyhow::bail!("a commit message is required (-m or -F)"),
1134
            };
113526×
            workspace::commit(&message, &depends_on, &paths, interactive, &hunks)
1136
        }
11372×
        Cmd::Cat { path, change } => workspace::cat(&path, change.as_deref()),
11381×
        Cmd::Root { json } => workspace::root(json),
11391×
        Cmd::Version { json } => workspace::version(json),
11402×
        Cmd::Discard { paths, hunks } => workspace::discard(&paths, &hunks),
11412×
        Cmd::Hunks { json } => workspace::hunks(json),
11420×
        Cmd::Squash { change, into } => workspace::squash(&change, &into),
1143
        Cmd::Rebase {
11440×
            change,
11450×
            onto,
11460×
            into_working_copy,
11470×
        } => workspace::rebase(&change, &onto, into_working_copy),
11480×
        Cmd::Blame { path, json } => workspace::blame(&path, json),
11491×
        Cmd::Bisect { cmd } => match cmd {
11500×
            BisectCmd::Start => workspace::bisect_start(),
11510×
            BisectCmd::Good { changes } => workspace::bisect_mark(Some(true), &changes),
11520×
            BisectCmd::Bad { changes } => workspace::bisect_mark(Some(false), &changes),
11530×
            BisectCmd::Skip => workspace::bisect_mark(None, &[]),
11540×
            BisectCmd::Run { command } => workspace::bisect_run(&command),
11551×
            BisectCmd::Status { json } => workspace::bisect_status(json),
11560×
            BisectCmd::Reset => workspace::bisect_reset(),
1157
        },
1158
        Cmd::Log {
11598×
            revset,
11608×
            limit,
11618×
            verbose,
11628×
            path,
11638×
            lines,
11648×
            json,
11658×
        } => workspace::log(
11668×
            revset.as_deref(),
11678×
            limit,
11688×
            verbose,
11698×
            path.as_deref(),
11708×
            lines.as_deref(),
11718×
            json,
1172
        ),
11731×
        Cmd::Diff { change, json } => workspace::diff(change.as_deref(), json),
1174
        Cmd::Describe {
11754×
            message,
11764×
            change,
11774×
            json,
11784×
        } => match message {
11790×
            Some(m) => workspace::describe(&m, change.as_deref()),
11804×
            None if change.is_some() => {
11810×
                anyhow::bail!(
1182
                    "naming works on the working copy; to change a head's message pass -m"
1183
                )
1184
            }
11854×
            None => workspace::describe_name(json),
1186
        },
11870×
        Cmd::Amend { message, into } => workspace::amend(message.as_deref(), into.as_deref()),
11880×
        Cmd::Split { change, paths } => workspace::split(&change, &paths),
1189
        Cmd::Abandon {
11900×
            change,
11910×
            revset,
11920×
            yes,
11930×
        } => workspace::abandon(change.as_deref(), revset.as_deref(), yes),
1194
        Cmd::Show {
11952×
            change,
11962×
            revset,
11972×
            json,
11982×
        } => workspace::show(change.as_deref(), revset.as_deref(), json),
1199
        Cmd::Checkout {
12000×
            changes,
12010×
            discard,
12020×
            carry,
12030×
        } => workspace::checkout(&changes, discard, carry),
12041×
        Cmd::Resolve { json } => workspace::resolve(json),
12050×
        Cmd::Undo => workspace::undo(),
1206
        Cmd::Gc {
12072×
            now,
12082×
            expire_snapshots,
12092×
            remote,
12102×
        } => match remote {
12112×
            Some(name) => workspace::gc_remote(&name, now),
12120×
            None => workspace::gc(now, expire_snapshots),
1213
        },
12140×
        Cmd::Fsck { json } => workspace::fsck(json),
12150×
        Cmd::Doctor { offline, json } => workspace::doctor(offline, json),
12160×
        Cmd::Checkpoint => workspace::checkpoint(),
12171×
        Cmd::Op { cmd } => match cmd {
12181×
            OpCmd::Log { limit, json } => workspace::op_log(limit, json),
12190×
            OpCmd::Restore { op, discard } => workspace::op_restore(&op, discard),
12200×
            OpCmd::Revert { op } => workspace::op_revert(&op),
1221
        },
1222
        Cmd::Clone {
12235×
            url,
12245×
            dest,
12255×
            max_blob,
12265×
            sparse,
12275×
            depth,
12285×
            recursive,
12295×
        } => sync::clone(&url, dest, max_blob.as_deref(), &sparse, depth, recursive),
12300×
        Cmd::Deepen { depth, remote } => sync::deepen(&remote, depth),
12310×
        Cmd::Sparse { paths } => workspace::sparse(&paths),
12320×
        Cmd::Lock { path } => workspace::lock(&path),
12330×
        Cmd::Unlock { path } => workspace::unlock(&path),
12341×
        Cmd::Workspace { cmd } => match cmd {
12350×
            WorkspaceCmd::Add { path, changes } => workspace::workspace_add(&path, &changes),
12361×
            WorkspaceCmd::List { json } => workspace::workspace_list(json),
12370×
            WorkspaceCmd::Forget { workspace } => workspace::workspace_forget(&workspace),
1238
        },
123917×
        Cmd::Bookmark { cmd } => match cmd {
1240
            BookmarkCmd::Create {
12416×
                name,
12426×
                changes,
12436×
                upto,
12446×
                only,
12456×
            } => workspace::bookmark_create(&name, &changes, upto, only),
1246
            BookmarkCmd::Set {
12473×
                name,
12483×
                changes,
12493×
                upto,
12503×
                only,
12513×
            } => workspace::bookmark_set(&name, &changes, upto, only),
12520×
            BookmarkCmd::Delete { name } => workspace::bookmark_delete(&name),
12535×
            BookmarkCmd::List { all, verbose, json } => {
12545×
                workspace::bookmark_list(all, verbose, json)
1255
            }
12560×
            BookmarkCmd::Show { name, json } => workspace::bookmark_show(name.as_deref(), json),
1257
            BookmarkCmd::Switch {
12583×
                name,
12593×
                discard,
12603×
                carry,
12613×
            } => workspace::bookmark_switch(&name, discard, carry),
1262
        },
12630×
        Cmd::Merge { bookmark } => workspace::merge(&bookmark),
12640×
        Cmd::Auth { cmd } => match cmd {
1265
            AuthCmd::Login {
12660×
                hub,
12670×
                with_token,
12680×
                ca,
12690×
            } => auth::login(hub.as_deref(), with_token, ca),
12700×
            AuthCmd::Status => auth::status(),
12710×
            AuthCmd::Logout { hub } => auth::logout(hub.as_deref()),
1272
        },
12731×
        Cmd::Submodule { cmd } => match cmd {
1274
            SubmoduleCmd::Add {
12750×
                url,
12760×
                path,
12770×
                bookmark,
12780×
            } => sync::submodule_add(&url, &path, bookmark.as_deref()),
12790×
            SubmoduleCmd::Update { init, paths } => sync::submodule_update(init, &paths),
12801×
            SubmoduleCmd::Status { json } => sync::submodule_status(json),
12810×
            SubmoduleCmd::Remove { path } => sync::submodule_remove(&path),
1282
        },
12838×
        Cmd::Receipt { cmd } => match cmd {
12842×
            ReceiptCmd::List { rev, json } => receipt::list(rev.as_deref(), json),
1285
            ReceiptCmd::Show {
12861×
                receipt: r,
12871×
                rev,
12881×
                json,
12891×
            } => receipt::show(&r, rev.as_deref(), json),
1290
            ReceiptCmd::Export {
12911×
                receipt: r,
12921×
                file,
12931×
                rev,
12941×
            } => receipt::export(&r, &file, rev.as_deref()),
12952×
            ReceiptCmd::Verify { file, json } => receipt::verify(&file, json),
12962×
            ReceiptCmd::Import { file } => receipt::import(&file),
1297
        },
12983×
        Cmd::Tag { cmd } => match cmd {
1299
            TagCmd::Create {
13002×
                name,
13012×
                changes,
13022×
                message,
13032×
            } => workspace::tag_create(&name, &changes, &message),
13041×
            TagCmd::List { json } => workspace::tag_list(json),
1305
        },
130610×
        Cmd::Remote { cmd } => match cmd {
1307
            RemoteCmd::Add {
13084×
                name,
13094×
                url,
13104×
                profile,
13114×
                region,
13124×
                endpoint,
13134×
                credentials,
13144×
            } => sync::remote_add(
13154×
                &name,
13164×
                &url,
13174×
                &[
13184×
                    ("profile", profile),
13194×
                    ("region", region),
13204×
                    ("endpoint", endpoint),
13214×
                    ("credentials", credentials),
13224×
                ],
1323
            ),
13243×
            RemoteCmd::Check { name } => sync::remote_check(&name),
13251×
            RemoteCmd::Remove { name } => sync::remote_remove(&name),
13262×
            RemoteCmd::List { json } => sync::remote_list(json),
1327
        },
13281×
        Cmd::Fetch { remote, json } => sync::fetch(remote.as_deref(), json),
13294×
        Cmd::Pull { remote, json } => sync::pull(remote.as_deref(), json),
1330
        Cmd::Push {
13317×
            remote,
13327×
            force,
13337×
            bookmark,
13347×
            delete,
13357×
            json,
13367×
        } => match delete {
13370×
            Some(name) => sync::push_delete(remote.as_deref(), &name, json),
13387×
            None => sync::push(remote.as_deref(), force, bookmark.as_deref(), json),
1339
        },
1340
        Cmd::Serve {
13410×
            root,
13420×
            bind,
13430×
            tokens,
13440×
            tls_cert,
13450×
            tls_key,
13460×
        } => sync::serve(root, &bind, tokens, tls_cert.zip(tls_key)),
13471×
        Cmd::Identity { cmd } => match cmd {
1348
            IdentityCmd::Create {
13491×
                name,
13501×
                email,
13511×
                local,
13521×
                expires,
13531×
            } => identity::create(name, email, local, expires),
13540×
            IdentityCmd::Show => identity::show(),
13550×
            IdentityCmd::Export { path } => identity::export(path),
13560×
            IdentityCmd::SignChallenge { challenge, json } => {
13570×
                identity::sign_challenge(&challenge, json)
1358
            }
13590×
            IdentityCmd::Rotate => identity::rotate(),
13600×
            IdentityCmd::Renew { expires } => identity::renew(expires),
13610×
            IdentityCmd::Revoke { key, reason } => identity::revoke(key.as_deref(), &reason),
13620×
            IdentityCmd::Delegate { cmd } => match cmd {
1363
                DelegateCmd::Add {
13640×
                    identity_file,
13650×
                    scope,
13660×
                    expires,
13670×
                } => identity::delegate_add(&identity_file, &scope, expires.as_deref()),
13680×
                DelegateCmd::Remove { key } => identity::delegate_remove(&key),
13690×
                DelegateCmd::List => identity::delegate_list(),
1370
            },
1371
        },
1372
        Cmd::Git {
13730×
            cmd: GitCmd::Export { git_dir, branch },
13740×
        } => sync::git_export(&git_dir, branch.as_deref()),
1375
        Cmd::Git {
13760×
            cmd: GitCmd::Fetch { url, branch, claim },
13770×
        } => sync::git_fetch(&url, &branch, claim),
1378
        Cmd::Git {
13790×
            cmd: GitCmd::Push { url, branch },
13800×
        } => sync::git_push(&url, &branch),
1381
        Cmd::Git {
1382
            cmd: GitCmd::Recover,
13830×
        } => sync::git_recover(),
1384
        Cmd::Git {
1385
            cmd:
1386
                GitCmd::Import {
13870×
                    git_dir,
13880×
                    dest,
13890×
                    branch,
13900×
                    claim,
1391
                },
13920×
        } => sync::git_import(&git_dir, &dest, &branch, claim),
1393
        Cmd::Git {
1394
            cmd:
1395
                GitCmd::Verify {
13960×
                    git_dir,
13970×
                    branch,
13980×
                    last,
13990×
                    max_differences,
1400
                },
14010×
        } => sync::git_verify(&git_dir, &branch, last, max_differences),
14023×
        Cmd::Policy { cmd } => match cmd {
14031×
            PolicyCmd::Init => identity::policy_init(),
14042×
            PolicyCmd::Show { json } => identity::policy_show(json),
1405
            PolicyCmd::Grant {
14060×
                identity_file,
14070×
                pattern,
14080×
                out,
14090×
            } => identity::policy_grant(&identity_file, pattern.as_deref(), out),
14100×
            PolicyCmd::Revoke { key, out } => identity::policy_revoke(&key, out),
14110×
            PolicyCmd::Root { cmd } => match cmd {
14120×
                RootCmd::Add { identity_file, out } => {
14130×
                    identity::policy_root_add(&identity_file, out)
1414
                }
14150×
                RootCmd::Remove { key, out } => identity::policy_root_remove(&key, out),
14160×
                RootCmd::Threshold { n, out } => identity::policy_threshold(n, out),
1417
            },
14180×
            PolicyCmd::Sign { proposal, out } => identity::policy_sign(&proposal, out),
1419
        },
1420
        Cmd::Seal {
14210×
            changes,
14220×
            proposal: Some(url),
14230×
            json,
14240×
        } if changes.is_empty() => proposal::seal(&url, json),
14250×
        Cmd::Seal { changes, json, .. } => identity::seal(&changes, json),
14260×
        Cmd::Proposal { cmd } => match cmd {
14270×
            ProposalCmd::Show { url, json } => proposal::show(&url, json),
14280×
            ProposalCmd::Land { url, force } => proposal::land(&url, force),
1429
        },
1430
        Cmd::Verify {
14311×
            change,
14321×
            revset,
14331×
            json,
14341×
        } => identity::verify(change.as_deref(), revset.as_deref(), json),
1435
        Cmd::Config {
14361×
            key,
14371×
            value,
14381×
            user,
14391×
            unset,
14401×
        } => identity::config(&key, value.as_deref().unwrap_or(""), user, unset),
1441
    }
1442145×
}
1443
1444
#[cfg(test)]
1445
mod help_tests {
1446
    use super::Cli;
1447
    use clap::CommandFactory;
1448
1449
    /// Every command and every argument explains itself, so `--help`,
1450
    /// completions and the man pages are complete.
1451
    #[test]
14521×
    fn every_command_and_argument_has_help() {
1453120×
        fn walk(cmd: &clap::Command, path: &str, missing: &mut Vec<String>) {
1454120×
            let here = format!("{path} {}", cmd.get_name()).trim().to_string();
1455120×
            if cmd.get_about().is_none() && !path.is_empty() {
14560×
                missing.push(format!("{here} (command)"));
1457120×
            }
1458210×
            for a in cmd.get_arguments() {
1459210×
                let id = a.get_id().as_str();
1460210×
                if id == "help" || id == "version" || (a.is_global_set() && !path.is_empty()) {
14610×
                    continue;
1462210×
                }
1463210×
                if a.get_help().is_none() && a.get_long_help().is_none() {
14640×
                    missing.push(format!("{here} {id}"));
1465210×
                }
1466
            }
1467120×
            for sub in cmd.get_subcommands() {
1468119×
                walk(sub, &here, missing);
1469119×
            }
1470120×
        }
14711×
        let mut missing = Vec::new();
14721×
        walk(&Cli::command(), "", &mut missing);
14731×
        assert!(
14741×
            missing.is_empty(),
1475
            "{} without help:\n{}",
14760×
            missing.len(),
14770×
            missing.join("\n")
1478
        );
14791×
    }
1480
}