OXYGENHUB

Coverage / src/cli/mod.rs 59.9%

200 of 334 lines run, 9 of 18 functions · run #294 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
}
701
702
#[derive(Subcommand)]
703
enum SubmoduleCmd {
704
    /// Clone URL (Oxygen or Git) into PATH and register it in .oxymodules
705
    Add {
706
        /// URL or path of the Oxygen or Git repository
707
        url: String,
708
        /// Where to put it, relative to the repository root
709
        path: String,
710
        /// Bookmark (Oxygen) or branch (Git) to check out and track
711
        #[arg(long)]
712
        bookmark: Option<String>,
713
    },
714
    /// Bring nested repositories to their pins
715
    Update {
716
        /// Clone nested repositories that are absent
717
        #[arg(long)]
718
        init: bool,
719
        /// Subrepos to update (default: all)
720
        paths: Vec<String>,
721
    },
722
    /// List subrepos with their pins and on-disk state
723
    Status {
724
        /// Machine-readable output: one JSON document on stdout
725
        #[arg(long)]
726
        json: bool,
727
    },
728
    /// Unregister PATH; the directory stays, the node goes with the next commit
729
    Remove {
730
        /// The subrepo to unregister
731
        path: String,
732
    },
733
}
734
735
#[derive(Subcommand)]
736
enum ReceiptCmd {
737
    /// The receipts kept for a state (default: the bookmark heads)
738
    List {
739
        /// Change, bookmark or tag whose state to look at
740
        rev: Option<String>,
741
        /// Machine-readable output: one JSON document on stdout
742
        #[arg(long)]
743
        json: bool,
744
    },
745
    /// One receipt in full, and whether its signature verifies
746
    Show {
747
        /// The receipt (a prefix of its hash, as `list` shows it)
748
        receipt: String,
749
        /// Change, bookmark or tag whose state holds it
750
        #[arg(long)]
751
        rev: Option<String>,
752
        /// Machine-readable output: one JSON document on stdout
753
        #[arg(long)]
754
        json: bool,
755
    },
756
    /// Write a signed receipt to FILE
757
    Export {
758
        /// The receipt (a prefix of its hash, as `list` shows it)
759
        receipt: String,
760
        /// Where to write it
761
        file: String,
762
        /// Change, bookmark or tag whose state holds it
763
        #[arg(long)]
764
        rev: Option<String>,
765
    },
766
    /// Check a signed receipt in FILE without keeping it
767
    Verify {
768
        /// A signed receipt, as a runner or `export` writes it
769
        file: String,
770
        /// Machine-readable output: one JSON document on stdout
771
        #[arg(long)]
772
        json: bool,
773
    },
774
    /// Verify a signed receipt in FILE and keep it with its state
775
    Import {
776
        /// A signed receipt, as a runner or `export` writes it
777
        file: String,
778
    },
779
}
780
781
#[derive(Subcommand)]
782
enum TagCmd {
783
    /// Tag the state of CHANGE... (default: the bookmark heads)
784
    Create {
785
        /// Name of the tag; tags never move
786
        name: String,
787
        /// Changes whose state to tag (default: the bookmark heads)
788
        changes: Vec<String>,
789
        /// A message recorded with the tag
790
        #[arg(short, long, default_value = "")]
791
        message: String,
792
    },
793
    /// List tags and the states they name
794
    List {
795
        /// Machine-readable output: one JSON document on stdout
796
        #[arg(long)]
797
        json: bool,
798
    },
799
}
800
801
#[derive(Subcommand)]
802
enum RemoteCmd {
803
    /// Add a remote
804
    Add {
805
        /// Name to refer to the remote by, such as origin
806
        name: String,
807
        /// 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
808
        url: String,
809
        /// For an s3:// store: the AWS profile to use (default: AWS_PROFILE, else "default")
810
        #[arg(long)]
811
        profile: Option<String>,
812
        /// For an s3:// store: its region (default: the environment, the profile, else asked of S3)
813
        #[arg(long)]
814
        region: Option<String>,
815
        /// For an s3://, gs:// or az:// store: another endpoint, such as an S3-compatible service
816
        #[arg(long)]
817
        endpoint: Option<String>,
818
        /// For a gs:// store: a service account key file, or application default credentials
819
        #[arg(long)]
820
        credentials: Option<String>,
821
    },
822
    /// Check a remote: that it is reachable with the credentials in hand, what it holds, and (for a store) that it behaves
823
    Check {
824
        /// The remote to check
825
        name: String,
826
    },
827
    /// Remove a remote
828
    Remove {
829
        /// The remote to remove
830
        name: String,
831
    },
832
    /// List remotes and their URLs
833
    List {
834
        /// Machine-readable output: one JSON document on stdout
835
        #[arg(long)]
836
        json: bool,
837
    },
838
}
839
840
#[derive(Subcommand)]
841
enum ProposalCmd {
842
    /// Show a proposal by its hub URL
843
    Show {
844
        /// The proposal's URL on the hub
845
        url: String,
846
        /// Machine-readable output: one JSON document on stdout
847
        #[arg(long)]
848
        json: bool,
849
    },
850
    /// Fetch the proposal's changes, set the target bookmark to the projected state, and push with your key
851
    Land {
852
        /// The proposal's URL on the hub
853
        url: String,
854
        /// Land even when the hub reports blockers
855
        #[arg(long)]
856
        force: bool,
857
    },
858
}
859
860
#[derive(Subcommand)]
861
enum IdentityCmd {
862
    /// Generate a composite Ed25519 + ML-DSA-65 key pair and make it your author identity
863
    Create {
864
        /// Your name (default: author.name)
865
        #[arg(long)]
866
        name: Option<String>,
867
        /// Your email (default: author.email)
868
        #[arg(long)]
869
        email: Option<String>,
870
        /// Record the author in this repository only, not in the user config
871
        #[arg(long)]
872
        local: bool,
873
        /// Expire the identity this many days from now
874
        #[arg(long)]
875
        expires: Option<u64>,
876
    },
877
    /// Show the configured identity
878
    Show,
879
    /// Write your identity object to a file, to hand to a policy holder
880
    Export {
881
        /// File to write (default: <key>.identity in the current directory)
882
        path: Option<PathBuf>,
883
    },
884
    /// Sign a host's challenge (hex, at least 16 bytes) to prove you hold your key; prints the signature as hex
885
    SignChallenge {
886
        /// The host's challenge, as hex
887
        challenge: String,
888
        /// Machine-readable output: one JSON document on stdout
889
        #[arg(long)]
890
        json: bool,
891
    },
892
    /// Move to a fresh key pair; the policy follows if it names your key
893
    Rotate,
894
    /// Re-issue your identity with a new expiry (in days from now; 0 = never)
895
    Renew {
896
        /// Days from now until it expires; 0 for never
897
        #[arg(long)]
898
        expires: u64,
899
    },
900
    /// Revoke a key: yours by default, or any key if you hold a policy root
901
    Revoke {
902
        /// KeyId prefix (default: your own key)
903
        key: Option<String>,
904
        /// Why, recorded in the revocation
905
        #[arg(long, default_value = "")]
906
        reason: String,
907
    },
908
    /// Keys allowed to sign or seal on your behalf
909
    Delegate {
910
        #[command(subcommand)]
911
        cmd: DelegateCmd,
912
    },
913
}
914
915
#[derive(Subcommand)]
916
enum DelegateCmd {
917
    /// Add a delegate from an exported identity file
918
    Add {
919
        /// The delegates' exported identity files: one rotation for all of them
920
        #[arg(required = true)]
921
        identity_file: Vec<PathBuf>,
922
        /// What it may do for you: changes, refs, seal (comma-separated) or all.
923
        /// An agent gets `changes`; a host that lands for you needs `changes,refs`
924
        #[arg(long, default_value = "changes")]
925
        scope: String,
926
        /// How long for: 30m, 8h, 7d, or a number of days (default: until removed)
927
        #[arg(long)]
928
        expires: Option<String>,
929
    },
930
    /// Remove a delegate by KeyId prefix
931
    Remove {
932
        /// KeyId prefix of the delegate
933
        key: String,
934
    },
935
    /// List delegates
936
    List,
937
}
938
939
#[derive(Subcommand)]
940
enum GitCmd {
941
    /// Export the current bookmark to a Git repository (created bare if absent)
942
    Export {
943
        /// Git repository to write to (created bare if absent)
944
        git_dir: PathBuf,
945
        /// Git branch to write (default: the bookmark name)
946
        #[arg(long)]
947
        branch: Option<String>,
948
    },
949
    /// Fetch a branch from a Git remote (path or URL) into the current bookmark
950
    Fetch {
951
        /// Git remote: a path or URL
952
        url: String,
953
        /// Branch to fetch
954
        #[arg(long, default_value = "main")]
955
        branch: String,
956
        /// Author your own commits (Git author email = your identity's) with your key; sets git.claim
957
        #[arg(long)]
958
        claim: bool,
959
    },
960
    /// Push the current bookmark to a branch of a Git remote (fetch first)
961
    Push {
962
        /// Git remote: a path or URL
963
        url: String,
964
        /// Branch to push to
965
        #[arg(long, default_value = "main")]
966
        branch: String,
967
    },
968
    /// 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
969
    Recover,
970
    /// Check this repository's import of a Git branch: every commit's tree must be reproduced exactly
971
    Verify {
972
        /// The Git repository the import came from
973
        git_dir: PathBuf,
974
        /// Branch that was imported
975
        #[arg(long, default_value = "main")]
976
        branch: String,
977
        /// Rebuild only the last N commits (the others are followed, not checked)
978
        #[arg(long, value_name = "N")]
979
        last: Option<usize>,
980
        /// Stop after N differences (0: check every commit whatever it finds)
981
        #[arg(long, value_name = "N", default_value_t = 50)]
982
        max_differences: usize,
983
    },
984
    /// Import a Git branch into a new Oxygen repository at DEST
985
    Import {
986
        /// Git repository to read
987
        git_dir: PathBuf,
988
        /// Directory for the new Oxygen repository
989
        dest: PathBuf,
990
        /// Branch to import
991
        #[arg(long, default_value = "main")]
992
        branch: String,
993
        /// Author your own commits (Git author email = your identity's) with your key; sets git.claim
994
        #[arg(long)]
995
        claim: bool,
996
    },
997
}
998
999
#[derive(Subcommand)]
1000
enum PolicyCmd {
1001
    /// Create the initial policy with your identity as the only root
1002
    Init,
1003
    /// Show the current policy
1004
    Show {
1005
        /// Machine-readable output: one JSON document on stdout
1006
        #[arg(long)]
1007
        json: bool,
1008
    },
1009
    /// Allow an identity (from `oxy identity export`) to update bookmarks
1010
    Grant {
1011
        /// The identity to grant, exported with `oxy identity export`
1012
        identity_file: PathBuf,
1013
        /// Reference pattern the grant applies to (default: every bookmark)
1014
        #[arg(long)]
1015
        pattern: Option<String>,
1016
        /// Where to write the proposal when more root signatures are needed
1017
        #[arg(long)]
1018
        out: Option<PathBuf>,
1019
    },
1020
    /// Revoke a key (KeyId prefix of an identity in the policy)
1021
    Revoke {
1022
        /// KeyId prefix of the identity
1023
        key: String,
1024
        /// Where to write the proposal when more root signatures are needed
1025
        #[arg(long)]
1026
        out: Option<PathBuf>,
1027
    },
1028
    /// Manage root keys and the signature threshold for policy updates
1029
    Root {
1030
        #[command(subcommand)]
1031
        cmd: RootCmd,
1032
    },
1033
    /// Add your root signature to a proposal file; applies it once the threshold is met
1034
    Sign {
1035
        /// The proposal file to sign
1036
        proposal: PathBuf,
1037
        /// Where to write the proposal if it still needs signatures (default: in place)
1038
        #[arg(long)]
1039
        out: Option<PathBuf>,
1040
    },
1041
}
1042
1043
#[derive(Subcommand)]
1044
enum RootCmd {
1045
    /// Make an exported identity a root key
1046
    Add {
1047
        /// The identity to make a root, exported with `oxy identity export`
1048
        identity_file: PathBuf,
1049
        /// Where to write the proposal when more root signatures are needed
1050
        #[arg(long)]
1051
        out: Option<PathBuf>,
1052
    },
1053
    /// Remove a root key by KeyId prefix
1054
    Remove {
1055
        /// KeyId prefix of the root key
1056
        key: String,
1057
        /// Where to write the proposal when more root signatures are needed
1058
        #[arg(long)]
1059
        out: Option<PathBuf>,
1060
    },
1061
    /// Require this many root signatures on policy updates
1062
    Threshold {
1063
        /// Number of root signatures
1064
        n: u32,
1065
        /// Where to write the proposal when more root signatures are needed
1066
        #[arg(long)]
1067
        out: Option<PathBuf>,
1068
    },
1069
}
1070
1071
/// Open the repository containing the current directory.
1072115×
fn open() -> Result<Repo> {
1073115×
    let repo = Repo::open(&std::env::current_dir()?).context("opening repository")?;
1074115×
    match AT_OP.get().and_then(|o| o.as_deref()) {
10750×
        Some(op) => Ok(repo.at_op(op)?),
1076115×
        None => Ok(repo),
1077
    }
1078115×
}
1079
1080
/// `oxy man`: every page into `dir`, or the top-level page on stdout.
10812×
fn man(dir: Option<PathBuf>) -> Result<i32> {
1082
    use clap::CommandFactory;
10832×
    let cmd = Cli::command();
10842×
    match dir {
10851×
        Some(dir) => {
10861×
            std::fs::create_dir_all(&dir)?;
10871×
            clap_mangen::generate_to(cmd, &dir)?;
10881×
            let pages = std::fs::read_dir(&dir)?
1089120×
                .filter(|e| {
1090120×
                    e.as_ref()
1091120×
                        .is_ok_and(|e| e.path().extension().is_some_and(|x| x == "1"))
1092120×
                })
10931×
                .count();
10941×
            println!(
1095
                "{}",
10961×
                ui::done(format!("Wrote {pages} man pages to {}", dir.display()))
1097
            );
1098
        }
10991×
        None => clap_mangen::Man::new(cmd).render(&mut std::io::stdout())?,
1100
    }
11012×
    Ok(0)
11022×
}
1103
1104
/// Parse arguments and run; returns the process exit code.
1105145×
pub fn run() -> Result<i32> {
1106
    // The cloud stores (s3://, gs://, az://) for remotes kept on them.
1107145×
    oxy_strata::register();
1108145×
    let cli = Cli::parse();
1109145×
    ui::init(cli.plain);
1110145×
    AT_OP.set(cli.at_op.clone()).ok();
11110×
    match cli.cmd {
11124×
        Cmd::Completions { shell } => {
1113
            use clap::CommandFactory;
11144×
            clap_complete::generate(shell, &mut Cli::command(), "oxy", &mut std::io::stdout());
11154×
            Ok(0)
1116
        }
11172×
        Cmd::Man { dir } => man(dir),
111814×
        Cmd::Init { path, bare, store } => workspace::init(path, bare, store.as_deref()),
11198×
        Cmd::Status { json } => workspace::status(json),
1120
        Cmd::Prompt {
11210×
            format,
11220×
            glyphs,
11230×
            color,
11240×
        } => workspace::prompt(&format, glyphs, color.as_deref()),
1125
        Cmd::Commit {
112626×
            message,
112726×
            file,
112826×
            depends_on,
112926×
            paths,
113026×
            interactive,
113126×
            hunks,
1132
        } => {
113326×
            let message = match (message, file) {
113425×
                (Some(m), _) => m,
11351×
                (None, Some(f)) if f.as_os_str() == "-" => {
11360×
                    let mut s = String::new();
11370×
                    std::io::Read::read_to_string(&mut std::io::stdin(), &mut s)?;
11380×
                    s
1139
                }
11401×
                (None, Some(f)) => std::fs::read_to_string(&f).map_err(|e| {
11410×
                    anyhow::anyhow!("reading the message from {}: {e}", f.display())
11420×
                })?,
11430×
                (None, None) => anyhow::bail!("a commit message is required (-m or -F)"),
1144
            };
114526×
            workspace::commit(&message, &depends_on, &paths, interactive, &hunks)
1146
        }
11472×
        Cmd::Cat { path, change } => workspace::cat(&path, change.as_deref()),
11481×
        Cmd::Root { json } => workspace::root(json),
11491×
        Cmd::Version { json } => workspace::version(json),
11502×
        Cmd::Discard { paths, hunks } => workspace::discard(&paths, &hunks),
11512×
        Cmd::Hunks { json } => workspace::hunks(json),
11520×
        Cmd::Squash { change, into } => workspace::squash(&change, &into),
1153
        Cmd::Rebase {
11540×
            change,
11550×
            onto,
11560×
            into_working_copy,
11570×
        } => workspace::rebase(&change, &onto, into_working_copy),
11580×
        Cmd::Blame { path, json } => workspace::blame(&path, json),
11591×
        Cmd::Bisect { cmd } => match cmd {
11600×
            BisectCmd::Start => workspace::bisect_start(),
11610×
            BisectCmd::Good { changes } => workspace::bisect_mark(Some(true), &changes),
11620×
            BisectCmd::Bad { changes } => workspace::bisect_mark(Some(false), &changes),
11630×
            BisectCmd::Skip => workspace::bisect_mark(None, &[]),
11640×
            BisectCmd::Run { command } => workspace::bisect_run(&command),
11651×
            BisectCmd::Status { json } => workspace::bisect_status(json),
11660×
            BisectCmd::Reset => workspace::bisect_reset(),
1167
        },
1168
        Cmd::Log {
11698×
            revset,
11708×
            limit,
11718×
            verbose,
11728×
            path,
11738×
            lines,
11748×
            json,
11758×
        } => workspace::log(
11768×
            revset.as_deref(),
11778×
            limit,
11788×
            verbose,
11798×
            path.as_deref(),
11808×
            lines.as_deref(),
11818×
            json,
1182
        ),
11831×
        Cmd::Diff { change, json } => workspace::diff(change.as_deref(), json),
1184
        Cmd::Describe {
11854×
            message,
11864×
            change,
11874×
            json,
11884×
        } => match message {
11890×
            Some(m) => workspace::describe(&m, change.as_deref()),
11904×
            None if change.is_some() => {
11910×
                anyhow::bail!(
1192
                    "naming works on the working copy; to change a head's message pass -m"
1193
                )
1194
            }
11954×
            None => workspace::describe_name(json),
1196
        },
11970×
        Cmd::Amend { message, into } => workspace::amend(message.as_deref(), into.as_deref()),
11980×
        Cmd::Split { change, paths } => workspace::split(&change, &paths),
1199
        Cmd::Abandon {
12000×
            change,
12010×
            revset,
12020×
            yes,
12030×
        } => workspace::abandon(change.as_deref(), revset.as_deref(), yes),
1204
        Cmd::Show {
12052×
            change,
12062×
            revset,
12072×
            json,
12082×
        } => workspace::show(change.as_deref(), revset.as_deref(), json),
1209
        Cmd::Checkout {
12100×
            changes,
12110×
            discard,
12120×
            carry,
12130×
        } => workspace::checkout(&changes, discard, carry),
12141×
        Cmd::Resolve { json } => workspace::resolve(json),
12150×
        Cmd::Undo => workspace::undo(),
1216
        Cmd::Gc {
12172×
            now,
12182×
            expire_snapshots,
12192×
            remote,
12202×
        } => match remote {
12212×
            Some(name) => workspace::gc_remote(&name, now),
12220×
            None => workspace::gc(now, expire_snapshots),
1223
        },
12240×
        Cmd::Fsck { json } => workspace::fsck(json),
12250×
        Cmd::Doctor { offline, json } => workspace::doctor(offline, json),
12260×
        Cmd::Checkpoint => workspace::checkpoint(),
12271×
        Cmd::Op { cmd } => match cmd {
12281×
            OpCmd::Log { limit, json } => workspace::op_log(limit, json),
12290×
            OpCmd::Restore { op, discard } => workspace::op_restore(&op, discard),
12300×
            OpCmd::Revert { op } => workspace::op_revert(&op),
1231
        },
1232
        Cmd::Clone {
12335×
            url,
12345×
            dest,
12355×
            max_blob,
12365×
            sparse,
12375×
            depth,
12385×
            recursive,
12395×
        } => sync::clone(&url, dest, max_blob.as_deref(), &sparse, depth, recursive),
12400×
        Cmd::Deepen { depth, remote } => sync::deepen(&remote, depth),
12410×
        Cmd::Sparse { paths } => workspace::sparse(&paths),
12420×
        Cmd::Lock { path } => workspace::lock(&path),
12430×
        Cmd::Unlock { path } => workspace::unlock(&path),
12441×
        Cmd::Workspace { cmd } => match cmd {
12450×
            WorkspaceCmd::Add { path, changes } => workspace::workspace_add(&path, &changes),
12461×
            WorkspaceCmd::List { json } => workspace::workspace_list(json),
12470×
            WorkspaceCmd::Forget { workspace } => workspace::workspace_forget(&workspace),
1248
        },
124917×
        Cmd::Bookmark { cmd } => match cmd {
1250
            BookmarkCmd::Create {
12516×
                name,
12526×
                changes,
12536×
                upto,
12546×
                only,
12556×
            } => workspace::bookmark_create(&name, &changes, upto, only),
1256
            BookmarkCmd::Set {
12573×
                name,
12583×
                changes,
12593×
                upto,
12603×
                only,
12613×
            } => workspace::bookmark_set(&name, &changes, upto, only),
12620×
            BookmarkCmd::Delete { name } => workspace::bookmark_delete(&name),
12635×
            BookmarkCmd::List { all, verbose, json } => {
12645×
                workspace::bookmark_list(all, verbose, json)
1265
            }
12660×
            BookmarkCmd::Show { name, json } => workspace::bookmark_show(name.as_deref(), json),
1267
            BookmarkCmd::Switch {
12683×
                name,
12693×
                discard,
12703×
                carry,
12713×
            } => workspace::bookmark_switch(&name, discard, carry),
1272
        },
12730×
        Cmd::Merge { bookmark } => workspace::merge(&bookmark),
12740×
        Cmd::Auth { cmd } => match cmd {
1275
            AuthCmd::Login {
12760×
                hub,
12770×
                with_token,
12780×
                ca,
12790×
            } => auth::login(hub.as_deref(), with_token, ca),
12800×
            AuthCmd::Status => auth::status(),
12810×
            AuthCmd::Logout { hub } => auth::logout(hub.as_deref()),
1282
        },
12831×
        Cmd::Submodule { cmd } => match cmd {
1284
            SubmoduleCmd::Add {
12850×
                url,
12860×
                path,
12870×
                bookmark,
12880×
            } => sync::submodule_add(&url, &path, bookmark.as_deref()),
12890×
            SubmoduleCmd::Update { init, paths } => sync::submodule_update(init, &paths),
12901×
            SubmoduleCmd::Status { json } => sync::submodule_status(json),
12910×
            SubmoduleCmd::Remove { path } => sync::submodule_remove(&path),
1292
        },
12938×
        Cmd::Receipt { cmd } => match cmd {
12942×
            ReceiptCmd::List { rev, json } => receipt::list(rev.as_deref(), json),
1295
            ReceiptCmd::Show {
12961×
                receipt: r,
12971×
                rev,
12981×
                json,
12991×
            } => receipt::show(&r, rev.as_deref(), json),
1300
            ReceiptCmd::Export {
13011×
                receipt: r,
13021×
                file,
13031×
                rev,
13041×
            } => receipt::export(&r, &file, rev.as_deref()),
13052×
            ReceiptCmd::Verify { file, json } => receipt::verify(&file, json),
13062×
            ReceiptCmd::Import { file } => receipt::import(&file),
1307
        },
13083×
        Cmd::Tag { cmd } => match cmd {
1309
            TagCmd::Create {
13102×
                name,
13112×
                changes,
13122×
                message,
13132×
            } => workspace::tag_create(&name, &changes, &message),
13141×
            TagCmd::List { json } => workspace::tag_list(json),
1315
        },
131610×
        Cmd::Remote { cmd } => match cmd {
1317
            RemoteCmd::Add {
13184×
                name,
13194×
                url,
13204×
                profile,
13214×
                region,
13224×
                endpoint,
13234×
                credentials,
13244×
            } => sync::remote_add(
13254×
                &name,
13264×
                &url,
13274×
                &[
13284×
                    ("profile", profile),
13294×
                    ("region", region),
13304×
                    ("endpoint", endpoint),
13314×
                    ("credentials", credentials),
13324×
                ],
1333
            ),
13343×
            RemoteCmd::Check { name } => sync::remote_check(&name),
13351×
            RemoteCmd::Remove { name } => sync::remote_remove(&name),
13362×
            RemoteCmd::List { json } => sync::remote_list(json),
1337
        },
13381×
        Cmd::Fetch { remote, json } => sync::fetch(remote.as_deref(), json),
13394×
        Cmd::Pull { remote, json } => sync::pull(remote.as_deref(), json),
1340
        Cmd::Push {
13417×
            remote,
13427×
            force,
13437×
            bookmark,
13447×
            delete,
13457×
            json,
13467×
        } => match delete {
13470×
            Some(name) => sync::push_delete(remote.as_deref(), &name, json),
13487×
            None => sync::push(remote.as_deref(), force, bookmark.as_deref(), json),
1349
        },
1350
        Cmd::Serve {
13510×
            root,
13520×
            bind,
13530×
            tokens,
13540×
            tls_cert,
13550×
            tls_key,
13560×
        } => sync::serve(root, &bind, tokens, tls_cert.zip(tls_key)),
13571×
        Cmd::Identity { cmd } => match cmd {
1358
            IdentityCmd::Create {
13591×
                name,
13601×
                email,
13611×
                local,
13621×
                expires,
13631×
            } => identity::create(name, email, local, expires),
13640×
            IdentityCmd::Show => identity::show(),
13650×
            IdentityCmd::Export { path } => identity::export(path),
13660×
            IdentityCmd::SignChallenge { challenge, json } => {
13670×
                identity::sign_challenge(&challenge, json)
1368
            }
13690×
            IdentityCmd::Rotate => identity::rotate(),
13700×
            IdentityCmd::Renew { expires } => identity::renew(expires),
13710×
            IdentityCmd::Revoke { key, reason } => identity::revoke(key.as_deref(), &reason),
13720×
            IdentityCmd::Delegate { cmd } => match cmd {
1373
                DelegateCmd::Add {
13740×
                    identity_file,
13750×
                    scope,
13760×
                    expires,
13770×
                } => identity::delegate_add(&identity_file, &scope, expires.as_deref()),
13780×
                DelegateCmd::Remove { key } => identity::delegate_remove(&key),
13790×
                DelegateCmd::List => identity::delegate_list(),
1380
            },
1381
        },
1382
        Cmd::Git {
13830×
            cmd: GitCmd::Export { git_dir, branch },
13840×
        } => sync::git_export(&git_dir, branch.as_deref()),
1385
        Cmd::Git {
13860×
            cmd: GitCmd::Fetch { url, branch, claim },
13870×
        } => sync::git_fetch(&url, &branch, claim),
1388
        Cmd::Git {
13890×
            cmd: GitCmd::Push { url, branch },
13900×
        } => sync::git_push(&url, &branch),
1391
        Cmd::Git {
1392
            cmd: GitCmd::Recover,
13930×
        } => sync::git_recover(),
1394
        Cmd::Git {
1395
            cmd:
1396
                GitCmd::Import {
13970×
                    git_dir,
13980×
                    dest,
13990×
                    branch,
14000×
                    claim,
1401
                },
14020×
        } => sync::git_import(&git_dir, &dest, &branch, claim),
1403
        Cmd::Git {
1404
            cmd:
1405
                GitCmd::Verify {
14060×
                    git_dir,
14070×
                    branch,
14080×
                    last,
14090×
                    max_differences,
1410
                },
14110×
        } => sync::git_verify(&git_dir, &branch, last, max_differences),
14123×
        Cmd::Policy { cmd } => match cmd {
14131×
            PolicyCmd::Init => identity::policy_init(),
14142×
            PolicyCmd::Show { json } => identity::policy_show(json),
1415
            PolicyCmd::Grant {
14160×
                identity_file,
14170×
                pattern,
14180×
                out,
14190×
            } => identity::policy_grant(&identity_file, pattern.as_deref(), out),
14200×
            PolicyCmd::Revoke { key, out } => identity::policy_revoke(&key, out),
14210×
            PolicyCmd::Root { cmd } => match cmd {
14220×
                RootCmd::Add { identity_file, out } => {
14230×
                    identity::policy_root_add(&identity_file, out)
1424
                }
14250×
                RootCmd::Remove { key, out } => identity::policy_root_remove(&key, out),
14260×
                RootCmd::Threshold { n, out } => identity::policy_threshold(n, out),
1427
            },
14280×
            PolicyCmd::Sign { proposal, out } => identity::policy_sign(&proposal, out),
1429
        },
1430
        Cmd::Seal {
14310×
            flow: Some(url),
14320×
            job: Some(job),
14330×
            reject,
14340×
            json,
1435
            ..
14360×
        } => approve::seal(&url, &job, reject, json),
1437
        Cmd::Seal {
14380×
            changes,
14390×
            proposal: Some(url),
14400×
            json,
1441
            ..
14420×
        } if changes.is_empty() => proposal::seal(&url, json),
14430×
        Cmd::Seal { changes, json, .. } => identity::seal(&changes, json),
14440×
        Cmd::Proposal { cmd } => match cmd {
14450×
            ProposalCmd::Show { url, json } => proposal::show(&url, json),
14460×
            ProposalCmd::Land { url, force } => proposal::land(&url, force),
1447
        },
1448
        Cmd::Verify {
14491×
            change,
14501×
            revset,
14511×
            json,
14521×
        } => identity::verify(change.as_deref(), revset.as_deref(), json),
1453
        Cmd::Config {
14541×
            key,
14551×
            value,
14561×
            user,
14571×
            unset,
14581×
        } => identity::config(&key, value.as_deref().unwrap_or(""), user, unset),
1459
    }
1460145×
}
1461
1462
#[cfg(test)]
1463
mod help_tests {
1464
    use super::Cli;
1465
    use clap::CommandFactory;
1466
1467
    /// Every command and every argument explains itself, so `--help`,
1468
    /// completions and the man pages are complete.
1469
    #[test]
14701×
    fn every_command_and_argument_has_help() {
1471120×
        fn walk(cmd: &clap::Command, path: &str, missing: &mut Vec<String>) {
1472120×
            let here = format!("{path} {}", cmd.get_name()).trim().to_string();
1473120×
            if cmd.get_about().is_none() && !path.is_empty() {
14740×
                missing.push(format!("{here} (command)"));
1475120×
            }
1476213×
            for a in cmd.get_arguments() {
1477213×
                let id = a.get_id().as_str();
1478213×
                if id == "help" || id == "version" || (a.is_global_set() && !path.is_empty()) {
14790×
                    continue;
1480213×
                }
1481213×
                if a.get_help().is_none() && a.get_long_help().is_none() {
14820×
                    missing.push(format!("{here} {id}"));
1483213×
                }
1484
            }
1485120×
            for sub in cmd.get_subcommands() {
1486119×
                walk(sub, &here, missing);
1487119×
            }
1488120×
        }
14891×
        let mut missing = Vec::new();
14901×
        walk(&Cli::command(), "", &mut missing);
14911×
        assert!(
14921×
            missing.is_empty(),
1493
            "{} without help:\n{}",
14940×
            missing.len(),
14950×
            missing.join("\n")
1496
        );
14971×
    }
1498
}