OXYGENHUB

Coverage / src/cli/mod.rs 58.6%

208 of 355 lines run, 9 of 18 functions · run #326 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
mod tlog;
12
pub mod ui;
13
mod workspace;
14
15
use anyhow::{Context, Result};
16
use clap::{Parser, Subcommand};
17
use oxy_core::repo::Repo;
18
use std::path::PathBuf;
19
20
#[derive(Parser)]
21
#[command(
22
    name = "oxy",
23
    version = env!("OXY_VERSION_LONG"),
24
    about = "Oxygen: breathing fresh air into version control"
25
)]
26
struct Cli {
27
    /// Plain output: no colour, no spinner (also implied by NO_COLOR or a non-terminal)
28
    #[arg(long, global = true)]
29
    plain: bool,
30
    /// Read the repository as it was after operation OP (an ID from oxy op log, @ or @-); commands that would change it are refused
31
    #[arg(long, global = true, value_name = "OP")]
32
    at_op: Option<String>,
33
    #[command(subcommand)]
34
    cmd: Cmd,
35
}
36
37
/// `--at-op`, for `open` to apply.
38
static AT_OP: std::sync::OnceLock<Option<String>> = std::sync::OnceLock::new();
39
40
#[derive(Subcommand)]
41
enum Cmd {
42
    /// Create a repository in PATH (default: current directory)
43
    Init {
44
        /// Directory to create the repository in (default: the current directory)
45
        path: Option<PathBuf>,
46
        /// No working copy: an object store and references only, for hosting
47
        #[arg(long)]
48
        bare: bool,
49
        /// Keep the objects and the operation log on this store
50
        /// (dir://PATH, s3://BUCKET/PREFIX, gs://…, az://…) instead of
51
        /// in .oxy, with a local cache in front (storage.cache, 2 GiB)
52
        #[arg(long, value_name = "URL")]
53
        store: Option<String>,
54
    },
55
    /// Clone a repository from a local path or an http(s) URL
56
    Clone {
57
        /// Local path or http(s) URL of the repository
58
        url: String,
59
        /// Directory to clone into (default: the last part of the URL)
60
        dest: Option<PathBuf>,
61
        /// Leave blobs larger than this (e.g. 1M) to be fetched on first read
62
        #[arg(long)]
63
        max_blob: Option<String>,
64
        /// Materialize only these paths (repeatable); implies lazy blobs
65
        #[arg(long = "sparse")]
66
        sparse: Vec<String>,
67
        /// Shallow clone: fetch only this many levels of history below the heads
68
        #[arg(long)]
69
        depth: Option<u32>,
70
        /// Clone the subrepos too (as oxy submodule update --init)
71
        #[arg(long)]
72
        recursive: bool,
73
    },
74
    /// Fetch more history below a shallow clone's boundary
75
    Deepen {
76
        /// Levels of history to add below the boundary
77
        #[arg(default_value_t = 10)]
78
        depth: u32,
79
        /// Remote to fetch the history from
80
        #[arg(long, default_value = "origin")]
81
        remote: String,
82
    },
83
    /// Show or set the sparse filter (paths to materialize); re-checks out the bookmark
84
    Sparse {
85
        /// Paths to materialize; none prints the current filter
86
        paths: Vec<String>,
87
    },
88
    /// Show the working copy: changed paths and conflicts
89
    Status {
90
        /// Machine-readable output: paths, and every conflict with its kind and contributing changes
91
        #[arg(long)]
92
        json: bool,
93
    },
94
    /// One-line summary for shell prompts; fast and records nothing
95
    Prompt {
96
        /// 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
97
        #[arg(long, default_value = oxy_core::repo::DEFAULT_PROMPT_FORMAT)]
98
        format: String,
99
        /// Glyph format (%i %b %c %s%U%O) instead of the plain default
100
        #[arg(long)]
101
        glyphs: bool,
102
        /// Colour by state (cyan clean, yellow dirty, red conflicted): raw escapes, or guarded for a bash or zsh PS1
103
        #[arg(long, value_parser = ["raw", "bash", "zsh"])]
104
        color: Option<String>,
105
    },
106
    /// Record the working copy as a change on the current bookmark
107
    Commit {
108
        /// The change's message: a subject line, then optionally a blank line and a body
109
        #[arg(short, long, required_unless_present = "file", conflicts_with = "file")]
110
        message: Option<String>,
111
        /// Read the message from FILE (`-` for standard input)
112
        #[arg(short = 'F', long, value_name = "FILE")]
113
        file: Option<PathBuf>,
114
        /// Extra explicit dependencies (ChangeId prefix, #hash prefix)
115
        #[arg(long = "depends-on")]
116
        depends_on: Vec<String>,
117
        /// Commit only these paths; the rest stays as uncommitted work
118
        paths: Vec<String>,
119
        /// Choose hunks one by one
120
        #[arg(short, long)]
121
        interactive: bool,
122
        /// Commit these hunks (as `oxy hunks` numbers them), comma separated
123
        #[arg(long, value_delimiter = ',')]
124
        hunks: Vec<usize>,
125
    },
126
    /// Fold CHANGE into one of its dependencies (keeps that change's id)
127
    Squash {
128
        /// The change to fold (ChangeId prefix, #hash prefix)
129
        change: String,
130
        /// The dependency that absorbs it
131
        #[arg(long)]
132
        into: String,
133
    },
134
    /// Re-express CHANGE against another base state
135
    Rebase {
136
        /// The change to re-express (ChangeId prefix, #hash prefix)
137
        change: String,
138
        /// The changes, bookmark or tag whose state becomes the new base
139
        #[arg(long, required = true, num_args = 1..)]
140
        onto: Vec<String>,
141
        /// Where the rebase would be conflicted, merge the target into the
142
        /// current bookmark instead, leaving the conflict in the working
143
        /// copy to fix and commit
144
        #[arg(long)]
145
        into_working_copy: bool,
146
    },
147
    /// Show which change introduced each line of a file
148
    Blame {
149
        /// File to annotate, relative to the repository root
150
        path: String,
151
        /// Machine-readable output: one JSON document on stdout
152
        #[arg(long)]
153
        json: bool,
154
    },
155
    /// Find the change that introduced a regression
156
    Bisect {
157
        #[command(subcommand)]
158
        cmd: BisectCmd,
159
    },
160
    /// List changes reachable from the bookmark and the working copy
161
    Log {
162
        /// Show the changes a revset selects: `main` (a bookmark name means its
163
        /// heads; `bookmark(main)` only ever the bookmark), `main..feature &
164
        /// author(andy)`, `touches("src/**") & date(-7d..)` (see
165
        /// docs/revset_query_language.md)
166
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with_all = ["path", "lines"])]
167
        revset: Option<String>,
168
        /// Show at most this many changes
169
        #[arg(short = 'n', long)]
170
        limit: Option<usize>,
171
        /// Show full messages, dependencies, and signatures
172
        #[arg(short, long)]
173
        verbose: bool,
174
        /// Only changes touching this path (renames followed)
175
        #[arg(long)]
176
        path: Option<String>,
177
        /// Only changes that wrote or deleted lines START to END of PATH
178
        /// (numbered as in the working copy's base), or deleted lines from
179
        /// between them: the history of a function
180
        #[arg(short = 'L', value_name = "START,END:PATH", conflicts_with = "path")]
181
        lines: Option<String>,
182
        /// Machine-readable output: one JSON document on stdout
183
        #[arg(long)]
184
        json: bool,
185
    },
186
    /// Show what the working copy changes against its base
187
    Diff {
188
        /// A change instead of the working copy
189
        change: Option<String>,
190
        /// Machine-readable output: one JSON document on stdout
191
        #[arg(long)]
192
        json: bool,
193
    },
194
    /// Print a file as it is in a state (default: the working copy's base)
195
    Cat {
196
        /// File to print, relative to the repository root
197
        path: String,
198
        /// A bookmark or tag (its state), or a change: a change means its
199
        /// dependency closure, the change and what it depends on, so files
200
        /// only later changes touched are absent or at older versions
201
        #[arg(short = 'r', long)]
202
        change: Option<String>,
203
    },
204
    /// Print the repository root, workspace, and bookmark
205
    Root {
206
        /// Machine-readable output: one JSON document on stdout
207
        #[arg(long)]
208
        json: bool,
209
    },
210
    /// Print the version of oxy, its repository format, and protocol
211
    Version {
212
        /// Machine-readable output: one JSON document on stdout
213
        #[arg(long)]
214
        json: bool,
215
    },
216
    /// Restore paths to the working copy's base, or undo chosen hunks
217
    Discard {
218
        /// Paths to restore; none with --hunks, or everything with neither
219
        paths: Vec<String>,
220
        /// Hunk indices as `oxy hunks` numbers them, comma separated
221
        #[arg(long, value_delimiter = ',')]
222
        hunks: Vec<usize>,
223
    },
224
    /// List the working copy's hunks, numbered as commit --hunks expects
225
    Hunks {
226
        /// Machine-readable output: one JSON document on stdout
227
        #[arg(long)]
228
        json: bool,
229
    },
230
    /// With -m, change the message of a head; without, name the working
231
    /// copy for a build: its tag, or the nearest tag plus distance and
232
    /// change, or the bookmark and change, and -dirty
233
    Describe {
234
        /// The new message
235
        #[arg(short, long)]
236
        message: Option<String>,
237
        /// The head to describe (default: the one the working copy sits on)
238
        change: Option<String>,
239
        /// Machine-readable output (naming only)
240
        #[arg(long, conflicts_with = "message")]
241
        json: bool,
242
    },
243
    /// Fold the working copy into the head it sits on, or into CHANGE with --into
244
    Amend {
245
        /// Replace the message too
246
        #[arg(short, long)]
247
        message: Option<String>,
248
        /// Amend an older change; the edits must touch only lines it already knows
249
        #[arg(long)]
250
        into: Option<String>,
251
    },
252
    /// Split a head: the named paths become a separate first change
253
    Split {
254
        /// The head to split
255
        change: String,
256
        /// Paths whose edits become the first change
257
        paths: Vec<String>,
258
    },
259
    /// Drop a change from the bookmark; its content stays on disk as uncommitted work
260
    Abandon {
261
        /// The change to drop (ChangeId prefix, #hash prefix)
262
        #[arg(required_unless_present = "revset")]
263
        change: Option<String>,
264
        /// Drop every change a revset selects, newest first
265
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
266
        revset: Option<String>,
267
        /// Drop more than five changes without asking
268
        #[arg(long, short = 'y')]
269
        yes: bool,
270
    },
271
    /// Show one change (ChangeId prefix, #hash prefix, or @), or those a revset selects
272
    Show {
273
        /// ChangeId prefix, #hash prefix, or @ for the working copy
274
        #[arg(required_unless_present = "revset")]
275
        change: Option<String>,
276
        /// Show every change a revset selects
277
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
278
        revset: Option<String>,
279
        /// Machine-readable output: one JSON document on stdout
280
        #[arg(long)]
281
        json: bool,
282
    },
283
    /// Move the working copy to the state formed by CHANGE... (default: the bookmark heads)
284
    Checkout {
285
        /// Changes whose state to check out (default: the bookmark heads)
286
        changes: Vec<String>,
287
        /// Throw away uncommitted working-copy changes
288
        #[arg(long)]
289
        discard: bool,
290
        /// Take uncommitted changes along; refused when the target has
291
        /// other versions of the files they touch
292
        #[arg(long, conflicts_with = "discard")]
293
        carry: bool,
294
    },
295
    /// Report which conflicts of the working copy's base are resolved by the current files
296
    Resolve {
297
        /// Machine-readable output: one JSON document on stdout
298
        #[arg(long)]
299
        json: bool,
300
    },
301
    /// Undo the last operation
302
    Undo,
303
    /// Write a checkpoint of the current bookmark's state now
304
    Checkpoint,
305
    /// Print a shell completion script: `oxy completions bash > ~/.local/share/bash-completion/completions/oxy`
306
    Completions {
307
        /// bash, zsh, fish, elvish or powershell
308
        shell: clap_complete::Shell,
309
    },
310
    /// Write man pages (oxy.1 and one per command) into DIR, or print oxy.1
311
    Man {
312
        /// Directory to write every page into, e.g. ~/.local/share/man/man1
313
        #[arg(long)]
314
        dir: Option<PathBuf>,
315
    },
316
    /// Check the identity, configuration and remotes, and say what to do about any problem
317
    Doctor {
318
        /// Do not contact the remotes
319
        #[arg(long)]
320
        offline: bool,
321
        /// Machine-readable output: one JSON document on stdout
322
        #[arg(long)]
323
        json: bool,
324
    },
325
    /// Check the repository's integrity: objects, operation log, references, signatures, checkpoints
326
    Fsck {
327
        /// Machine-readable output: one JSON document on stdout
328
        #[arg(long)]
329
        json: bool,
330
    },
331
    /// Prune unreachable objects older than the grace period and repack everything into one pack
332
    Gc {
333
        /// Ignore the grace period (core.gc-grace) and prune immediately
334
        #[arg(long)]
335
        now: bool,
336
        /// Keep no past working-copy snapshots, only each workspace's current one, so files only they held go (core.snapshot-retention, default 7 days)
337
        #[arg(long)]
338
        expire_snapshots: bool,
339
        /// 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)
340
        #[arg(long, value_name = "NAME")]
341
        remote: Option<String>,
342
    },
343
    /// List operations
344
    #[command(name = "op")]
345
    Op {
346
        #[command(subcommand)]
347
        cmd: OpCmd,
348
    },
349
    /// Take the advisory local lock on a lockable file, making it writable
350
    Lock {
351
        /// The lockable file
352
        path: String,
353
    },
354
    /// Release the local lock and make the file read-only again
355
    Unlock {
356
        /// The locked file
357
        path: String,
358
    },
359
    /// Workspaces: extra checkout directories sharing this repository
360
    Workspace {
361
        #[command(subcommand)]
362
        cmd: WorkspaceCmd,
363
    },
364
    /// Bookmarks: named states; each workspace works on one
365
    Bookmark {
366
        #[command(subcommand)]
367
        cmd: BookmarkCmd,
368
    },
369
    /// Union another bookmark's heads into the current one (no merge change)
370
    Merge {
371
        /// The bookmark whose heads to add
372
        bookmark: String,
373
    },
374
    /// Sign in to a hub once, for every repository on it
375
    Auth {
376
        #[command(subcommand)]
377
        cmd: AuthCmd,
378
    },
379
    /// Subrepositories: nested repositories pinned to a state
380
    Submodule {
381
        #[command(subcommand)]
382
        cmd: SubmoduleCmd,
383
    },
384
    /// Witness hubs' transparency logs: cosign each checkpoint that extends
385
    /// the last one cosigned (spec §14.8)
386
    Witness {
387
        #[command(subcommand)]
388
        cmd: WitnessCmd,
389
    },
390
    /// Hubs' transparency logs: check that a hub shows everyone the same
391
    /// history (spec §14.8)
392
    Tlog {
393
        #[command(subcommand)]
394
        cmd: TlogCmd,
395
    },
396
    /// Execution receipts: signed records of what a runner ran on a state
397
    Receipt {
398
        #[command(subcommand)]
399
        cmd: ReceiptCmd,
400
    },
401
    /// Tags: immutable named states
402
    Tag {
403
        #[command(subcommand)]
404
        cmd: TagCmd,
405
    },
406
    /// Manage remotes
407
    Remote {
408
        #[command(subcommand)]
409
        cmd: RemoteCmd,
410
    },
411
    /// Fetch every bookmark of a remote into its tracking references
412
    Fetch {
413
        /// Remote name (default: origin)
414
        remote: Option<String>,
415
        /// Machine-readable output: one JSON document on stdout
416
        #[arg(long)]
417
        json: bool,
418
    },
419
    /// Fetch, then union the remote bookmark into the local one (no merge change)
420
    Pull {
421
        /// Remote name (default: origin)
422
        remote: Option<String>,
423
        /// Machine-readable output: one JSON document on stdout
424
        #[arg(long)]
425
        json: bool,
426
    },
427
    /// Push the current bookmark to a remote
428
    Push {
429
        /// Remote name (default: origin)
430
        remote: Option<String>,
431
        /// Allow dropping heads the remote has
432
        #[arg(long)]
433
        force: bool,
434
        /// Push this bookmark instead of the workspace's current one
435
        #[arg(short = 'b', long)]
436
        bookmark: Option<String>,
437
        /// Delete this bookmark on the remote (never its default bookmark);
438
        /// the local bookmark is kept
439
        #[arg(long, value_name = "NAME", conflicts_with_all = ["bookmark", "force"])]
440
        delete: Option<String>,
441
        /// Machine-readable output: one JSON document on stdout
442
        #[arg(long)]
443
        json: bool,
444
    },
445
    /// Serve repositories under ROOT over HTTPS (with --tls-cert/--tls-key) or plain HTTP
446
    Serve {
447
        /// Directory with one repository per subdirectory
448
        #[arg(long, default_value = ".")]
449
        root: PathBuf,
450
        /// Address and port to listen on
451
        #[arg(long, default_value = "127.0.0.1:8890")]
452
        bind: String,
453
        /// Bearer token allowed to push (repeatable); none means open
454
        #[arg(long = "token")]
455
        tokens: Vec<String>,
456
        /// PEM certificate chain; enables HTTPS together with --tls-key
457
        #[arg(long, requires = "tls_key")]
458
        tls_cert: Option<PathBuf>,
459
        /// PEM private key
460
        #[arg(long, requires = "tls_cert")]
461
        tls_key: Option<PathBuf>,
462
    },
463
    /// Manage the signing identity
464
    Identity {
465
        #[command(subcommand)]
466
        cmd: IdentityCmd,
467
    },
468
    /// Seal changes with your key: named ones, or every change on the current bookmark you can authenticate but have not
469
    Seal {
470
        /// Changes to seal (default: every change on the bookmark you can authenticate and have not sealed)
471
        changes: Vec<String>,
472
        /// Seal every change of a hub proposal and push the seal (your approval)
473
        #[arg(long, conflicts_with = "changes")]
474
        proposal: Option<String>,
475
        /// Approve a job of a hub run that waits for a sealed approval: `--flow https://hub/OWNER/NAME/flow/N --job apply`
476
        #[arg(long, conflicts_with_all = ["changes", "proposal"], requires = "job")]
477
        flow: Option<String>,
478
        /// The job to approve, with --flow
479
        #[arg(long, requires = "flow")]
480
        job: Option<String>,
481
        /// Reject the job instead of approving it, with --flow
482
        #[arg(long, requires = "flow")]
483
        reject: bool,
484
        /// Machine-readable output: one JSON document on stdout
485
        #[arg(long)]
486
        json: bool,
487
    },
488
    /// Hub proposals: show one, or land it from this client
489
    Proposal {
490
        #[command(subcommand)]
491
        cmd: ProposalCmd,
492
    },
493
    /// Verify the signatures on a change (default: every change in the log)
494
    Verify {
495
        /// The change to verify (default: every change in the log)
496
        change: Option<String>,
497
        /// Verify every change a revset selects: `release..main & unsigned()`
498
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
499
        revset: Option<String>,
500
        /// Machine-readable output: one JSON document on stdout
501
        #[arg(long)]
502
        json: bool,
503
    },
504
    /// Git interoperability
505
    Git {
506
        #[command(subcommand)]
507
        cmd: GitCmd,
508
    },
509
    /// Manage the trust policy (who may update which bookmarks)
510
    Policy {
511
        #[command(subcommand)]
512
        cmd: PolicyCmd,
513
    },
514
    /// 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)
515
    Config {
516
        /// The key, such as author.name or remote.origin.token
517
        key: String,
518
        /// The value to set (none with --unset); `-` reads it from standard input, out of the shell's history
519
        #[arg(required_unless_present = "unset")]
520
        value: Option<String>,
521
        /// Write to the user file (~/.config/oxy/config.toml) instead of this repository
522
        #[arg(long)]
523
        user: bool,
524
        /// Remove the key from this repository's file (or the user file with --user)
525
        #[arg(long)]
526
        unset: bool,
527
    },
528
}
529
530
#[derive(Subcommand)]
531
enum OpCmd {
532
    /// List operations, newest first, with what each changed
533
    Log {
534
        /// Show only the latest N (snapshots folded together count as one)
535
        #[arg(short = 'n', long)]
536
        limit: Option<usize>,
537
        /// Machine-readable output: one JSON document on stdout
538
        #[arg(long)]
539
        json: bool,
540
    },
541
    /// Go back to the bookmarks and working copy as they were after OP (recorded as a new operation, so it can be undone)
542
    Restore {
543
        /// The operation: an ID prefix from oxy op log, @ or @-
544
        op: String,
545
        /// Throw away uncommitted working-copy changes
546
        #[arg(long)]
547
        discard: bool,
548
    },
549
    /// Undo OP alone, keeping every operation after it: the bookmarks it moved go back
550
    Revert {
551
        /// The operation: an ID prefix from oxy op log
552
        op: String,
553
    },
554
}
555
556
#[derive(Subcommand)]
557
enum WorkspaceCmd {
558
    /// Create a workspace at PATH checked out on CHANGE... (default: the bookmark heads)
559
    Add {
560
        /// Directory for the new workspace (must be empty or absent)
561
        path: PathBuf,
562
        /// Changes whose state to check out there
563
        changes: Vec<String>,
564
    },
565
    /// List workspaces and their working-copy changes
566
    List {
567
        /// Machine-readable output: one JSON document on stdout
568
        #[arg(long)]
569
        json: bool,
570
    },
571
    /// Stop tracking a workspace (by id prefix or path); its files stay
572
    Forget {
573
        /// Workspace id prefix or path
574
        workspace: String,
575
    },
576
}
577
578
#[derive(Subcommand)]
579
enum BisectCmd {
580
    /// Begin; remembers where the working copy was
581
    Start,
582
    /// Mark CHANGE... (or the state under test) as good
583
    Good {
584
        /// Changes known to be good (default: the state under test)
585
        changes: Vec<String>,
586
    },
587
    /// Mark CHANGE... (or the state under test) as bad
588
    Bad {
589
        /// Changes known to be bad (default: the state under test)
590
        changes: Vec<String>,
591
    },
592
    /// The state under test cannot be tested; try another
593
    Skip,
594
    /// Run a command for each step: exit 0 good, 125 skip, else bad
595
    Run {
596
        /// Command and arguments to run at each step
597
        #[arg(required = true, trailing_var_arg = true)]
598
        command: Vec<String>,
599
    },
600
    /// Where the search stands
601
    Status {
602
        /// Machine-readable output: one JSON document on stdout
603
        #[arg(long)]
604
        json: bool,
605
    },
606
    /// Restore the working copy and forget the search
607
    Reset,
608
}
609
610
#[derive(Subcommand)]
611
enum BookmarkCmd {
612
    /// Create a bookmark at CHANGE... (default: the working copy's base)
613
    Create {
614
        /// Name of the new bookmark
615
        name: String,
616
        /// Its heads (default: the working copy's base). A state is its
617
        /// heads and what they depend on: a change alone may leave out
618
        /// earlier changes of the current state, which is refused unless
619
        /// --upto or --only says which is meant
620
        changes: Vec<String>,
621
        /// Everything of the current state up to CHANGE..., as a Git
622
        /// branch at a commit would hold
623
        #[arg(long, conflicts_with = "only")]
624
        upto: bool,
625
        /// Just CHANGE... and what they depend on. Other changes to the
626
        /// same files are left out, so a file can come out partly edited;
627
        /// to add one change to a bookmark's work, give the bookmark's
628
        /// heads with it instead: `bookmark set NAME <its heads> CHANGE`
629
        #[arg(long)]
630
        only: bool,
631
    },
632
    /// Point an existing bookmark at CHANGE...
633
    Set {
634
        /// The bookmark to move
635
        name: String,
636
        /// Its new heads. A change alone may leave out changes the
637
        /// bookmark now holds that were recorded before it, which is
638
        /// refused unless --upto or --only says which is meant
639
        changes: Vec<String>,
640
        /// Everything the bookmark holds up to CHANGE..., as a Git branch
641
        /// moved to a commit would hold
642
        #[arg(long, conflicts_with = "only")]
643
        upto: bool,
644
        /// Just CHANGE... and what they depend on. Other changes to the
645
        /// same files are left out, so a file can come out partly edited;
646
        /// to add one change to a bookmark's work, give the bookmark's
647
        /// heads with it instead: `bookmark set NAME <its heads> CHANGE`
648
        #[arg(long)]
649
        only: bool,
650
    },
651
    /// Remove a bookmark; its changes stay
652
    Delete {
653
        /// The bookmark to remove
654
        name: String,
655
    },
656
    /// List bookmarks with their heads and difference from origin
657
    List {
658
        /// Also list remotes' bookmarks that have no local bookmark
659
        #[arg(long, short)]
660
        all: bool,
661
        /// Each head of every bookmark, as `bookmark show` prints them
662
        #[arg(long, short)]
663
        verbose: bool,
664
        /// Machine-readable output: one JSON document on stdout
665
        #[arg(long)]
666
        json: bool,
667
    },
668
    /// A bookmark's heads: each change nothing else on it depends on,
669
    /// newest first. A bookmark name is also a revset for its heads
670
    /// (`oxy log -r NAME`, or `bookmark(NAME)` to mean only the bookmark)
671
    Show {
672
        /// The bookmark, or REMOTE/NAME (default: the current one)
673
        name: Option<String>,
674
        /// Machine-readable output: one JSON document on stdout
675
        #[arg(long)]
676
        json: bool,
677
    },
678
    /// Make NAME this workspace's bookmark and check it out. Uncommitted work stops it; --carry takes the work along, --discard drops it
679
    Switch {
680
        /// The bookmark to work on; one only a remote has (NAME or REMOTE/NAME) is created from it
681
        name: String,
682
        /// Throw away uncommitted working-copy changes
683
        #[arg(long)]
684
        discard: bool,
685
        /// Take uncommitted changes along; refused when NAME has other
686
        /// versions of the files they touch
687
        #[arg(long, conflicts_with = "discard")]
688
        carry: bool,
689
    },
690
}
691
692
#[derive(Subcommand)]
693
enum WitnessCmd {
694
    /// Serve a witness (C2SP tlog-witness: POST /add-checkpoint), signing
695
    /// with this oxy home's key (author.key)
696
    Serve {
697
        /// The witness's name in cosignatures: a host name
698
        #[arg(long)]
699
        name: String,
700
        /// A log to witness, as ORIGIN=FILE: its origin (HOST/log) and its
701
        /// key's identity file (a hub's /.well-known/oxyhub-key); repeatable
702
        #[arg(long = "log", required = true)]
703
        logs: Vec<String>,
704
        /// Where to keep what it cosigned
705
        #[arg(long, default_value = "witness-state")]
706
        state: PathBuf,
707
        /// Address and port to listen on
708
        #[arg(long, default_value = "127.0.0.1:8891")]
709
        bind: String,
710
        /// PEM certificate chain; enables HTTPS together with --tls-key
711
        #[arg(long, requires = "tls_key")]
712
        tls_cert: Option<PathBuf>,
713
        /// PEM private key for --tls-cert
714
        #[arg(long, requires = "tls_cert")]
715
        tls_key: Option<PathBuf>,
716
    },
717
}
718
719
#[derive(Subcommand)]
720
enum TlogCmd {
721
    /// Check a hub's whole log: its checkpoint against the log key and the
722
    /// last checkpoint seen, and every entry against the root it signed;
723
    /// then list this repository's entries (or a key's, or all)
724
    Verify {
725
        /// The hub, as https://oxygenhub.io (default: this checkout's remote)
726
        hub: Option<String>,
727
        /// List the entries a key signed (a KeyId) instead
728
        #[arg(long, conflicts_with = "all")]
729
        key: Option<String>,
730
        /// List every entry
731
        #[arg(long)]
732
        all: bool,
733
        /// Machine-readable output
734
        #[arg(long)]
735
        json: bool,
736
    },
737
}
738
739
#[derive(Subcommand)]
740
enum AuthCmd {
741
    /// Sign in to HUB in the browser (device sign-in) and keep the token for
742
    /// every repository there
743
    Login {
744
        /// The hub, as https://oxygenhub.io or oxygenhub.io (default: this checkout's origin)
745
        hub: Option<String>,
746
        /// Read a token from standard input instead (for CI and scripts)
747
        #[arg(long)]
748
        with_token: bool,
749
        /// PEM file of extra roots to trust (a hub with a self-signed certificate)
750
        #[arg(long)]
751
        ca: Option<PathBuf>,
752
    },
753
    /// List the hubs you are signed in to, checking each token with its hub
754
    Status,
755
    /// Forget HUB's token and revoke it on the hub
756
    Logout {
757
        /// The hub (default: this checkout's origin, or the only one)
758
        hub: Option<String>,
759
    },
760
    /// Keep an agent grant token (from `oh agent grant`) for keyless
761
    /// signing: with `author.signer = keyless`, commits and pushes are
762
    /// signed by fresh keys the hub certifies, in the grantor's name
763
    /// (the token is read from standard input, so it stays out of the
764
    /// shell's history)
765
    Grant {
766
        /// The hub (default: this checkout's origin)
767
        hub: Option<String>,
768
    },
769
}
770
771
#[derive(Subcommand)]
772
enum SubmoduleCmd {
773
    /// Clone URL (Oxygen or Git) into PATH and register it in .oxymodules
774
    Add {
775
        /// URL or path of the Oxygen or Git repository
776
        url: String,
777
        /// Where to put it, relative to the repository root
778
        path: String,
779
        /// Bookmark (Oxygen) or branch (Git) to check out and track
780
        #[arg(long)]
781
        bookmark: Option<String>,
782
    },
783
    /// Bring nested repositories to their pins
784
    Update {
785
        /// Clone nested repositories that are absent
786
        #[arg(long)]
787
        init: bool,
788
        /// Subrepos to update (default: all)
789
        paths: Vec<String>,
790
    },
791
    /// List subrepos with their pins and on-disk state
792
    Status {
793
        /// Machine-readable output: one JSON document on stdout
794
        #[arg(long)]
795
        json: bool,
796
    },
797
    /// Unregister PATH; the directory stays, the node goes with the next commit
798
    Remove {
799
        /// The subrepo to unregister
800
        path: String,
801
    },
802
}
803
804
#[derive(Subcommand)]
805
enum ReceiptCmd {
806
    /// The receipts kept for a state (default: the bookmark heads)
807
    List {
808
        /// Change, bookmark or tag whose state to look at
809
        rev: Option<String>,
810
        /// Machine-readable output: one JSON document on stdout
811
        #[arg(long)]
812
        json: bool,
813
    },
814
    /// One receipt in full, and whether its signature verifies
815
    Show {
816
        /// The receipt (a prefix of its hash, as `list` shows it)
817
        receipt: String,
818
        /// Change, bookmark or tag whose state holds it
819
        #[arg(long)]
820
        rev: Option<String>,
821
        /// Machine-readable output: one JSON document on stdout
822
        #[arg(long)]
823
        json: bool,
824
    },
825
    /// Write a signed receipt to FILE
826
    Export {
827
        /// The receipt (a prefix of its hash, as `list` shows it)
828
        receipt: String,
829
        /// Where to write it
830
        file: String,
831
        /// Change, bookmark or tag whose state holds it
832
        #[arg(long)]
833
        rev: Option<String>,
834
        /// `oxygen`: the runner's signed receipt, as `verify` and `import`
835
        /// read it. `slsa`: SLSA provenance in a DSSE envelope, signed with
836
        /// your key, for in-toto and cosign (`oxy identity export --pem`
837
        /// gives the key they check it with)
838
        #[arg(long, default_value = "oxygen", value_parser = ["oxygen", "slsa"])]
839
        format: String,
840
    },
841
    /// Check a signed receipt in FILE without keeping it
842
    Verify {
843
        /// A signed receipt, as a runner or `export` writes it
844
        file: String,
845
        /// Machine-readable output: one JSON document on stdout
846
        #[arg(long)]
847
        json: bool,
848
    },
849
    /// Verify a signed receipt in FILE and keep it with its state
850
    Import {
851
        /// A signed receipt, as a runner or `export` writes it
852
        file: String,
853
    },
854
}
855
856
#[derive(Subcommand)]
857
enum TagCmd {
858
    /// Tag the state of CHANGE... (default: the bookmark heads)
859
    Create {
860
        /// Name of the tag; tags never move
861
        name: String,
862
        /// Changes whose state to tag (default: the bookmark heads)
863
        changes: Vec<String>,
864
        /// A message recorded with the tag
865
        #[arg(short, long, default_value = "")]
866
        message: String,
867
    },
868
    /// List tags and the states they name
869
    List {
870
        /// Machine-readable output: one JSON document on stdout
871
        #[arg(long)]
872
        json: bool,
873
    },
874
}
875
876
#[derive(Subcommand)]
877
enum RemoteCmd {
878
    /// Add a remote
879
    Add {
880
        /// Name to refer to the remote by, such as origin
881
        name: String,
882
        /// 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
883
        url: String,
884
        /// For an s3:// store: the AWS profile to use (default: AWS_PROFILE, else "default")
885
        #[arg(long)]
886
        profile: Option<String>,
887
        /// For an s3:// store: its region (default: the environment, the profile, else asked of S3)
888
        #[arg(long)]
889
        region: Option<String>,
890
        /// For an s3://, gs:// or az:// store: another endpoint, such as an S3-compatible service
891
        #[arg(long)]
892
        endpoint: Option<String>,
893
        /// For a gs:// store: a service account key file, or application default credentials
894
        #[arg(long)]
895
        credentials: Option<String>,
896
    },
897
    /// Check a remote: that it is reachable with the credentials in hand, what it holds, and (for a store) that it behaves
898
    Check {
899
        /// The remote to check
900
        name: String,
901
    },
902
    /// Remove a remote
903
    Remove {
904
        /// The remote to remove
905
        name: String,
906
    },
907
    /// List remotes and their URLs
908
    List {
909
        /// Machine-readable output: one JSON document on stdout
910
        #[arg(long)]
911
        json: bool,
912
    },
913
}
914
915
#[derive(Subcommand)]
916
enum ProposalCmd {
917
    /// Show a proposal by its hub URL
918
    Show {
919
        /// The proposal's URL on the hub
920
        url: String,
921
        /// Machine-readable output: one JSON document on stdout
922
        #[arg(long)]
923
        json: bool,
924
    },
925
    /// Fetch the proposal's changes, set the target bookmark to the projected state, and push with your key
926
    Land {
927
        /// The proposal's URL on the hub
928
        url: String,
929
        /// Land even when the hub reports blockers
930
        #[arg(long)]
931
        force: bool,
932
    },
933
}
934
935
#[derive(Subcommand)]
936
enum IdentityCmd {
937
    /// Generate a composite Ed25519 + ML-DSA-65 key pair and make it your author identity
938
    Create {
939
        /// Your name (default: author.name)
940
        #[arg(long)]
941
        name: Option<String>,
942
        /// Your email (default: author.email)
943
        #[arg(long)]
944
        email: Option<String>,
945
        /// Record the author in this repository only, not in the user config
946
        #[arg(long)]
947
        local: bool,
948
        /// Expire the identity this many days from now
949
        #[arg(long)]
950
        expires: Option<u64>,
951
    },
952
    /// Show the configured identity
953
    Show,
954
    /// Write your identity object to a file, to hand to a policy holder
955
    Export {
956
        /// File to write (default: <key>.identity, or <key>.pem with --pem, in the current directory)
957
        path: Option<PathBuf>,
958
        /// Write the Ed25519 public key as PEM instead, as cosign's --key and
959
        /// other DSSE verifiers take it
960
        #[arg(long)]
961
        pem: bool,
962
    },
963
    /// Sign a host's challenge (hex, at least 16 bytes) to prove you hold your key; prints the signature as hex
964
    SignChallenge {
965
        /// The host's challenge, as hex
966
        challenge: String,
967
        /// Machine-readable output: one JSON document on stdout
968
        #[arg(long)]
969
        json: bool,
970
    },
971
    /// Move to a fresh key pair; the policy follows if it names your key
972
    Rotate,
973
    /// Re-issue your identity with a new expiry (in days from now; 0 = never)
974
    Renew {
975
        /// Days from now until it expires; 0 for never
976
        #[arg(long)]
977
        expires: u64,
978
    },
979
    /// Revoke a key: yours by default, or any key if you hold a policy root
980
    Revoke {
981
        /// KeyId prefix (default: your own key)
982
        key: Option<String>,
983
        /// Why, recorded in the revocation
984
        #[arg(long, default_value = "")]
985
        reason: String,
986
    },
987
    /// Keys allowed to sign or seal on your behalf
988
    Delegate {
989
        #[command(subcommand)]
990
        cmd: DelegateCmd,
991
    },
992
}
993
994
#[derive(Subcommand)]
995
enum DelegateCmd {
996
    /// Add a delegate from an exported identity file
997
    Add {
998
        /// The delegates' exported identity files: one rotation for all of them
999
        #[arg(required = true)]
1000
        identity_file: Vec<PathBuf>,
1001
        /// What it may do for you: changes, refs, seal (comma-separated) or all.
1002
        /// An agent gets `changes`; a host that lands for you needs `changes,refs`
1003
        #[arg(long, default_value = "changes")]
1004
        scope: String,
1005
        /// How long for: 30m, 8h, 7d, or a number of days (default: until removed)
1006
        #[arg(long)]
1007
        expires: Option<String>,
1008
    },
1009
    /// Remove a delegate by KeyId prefix
1010
    Remove {
1011
        /// KeyId prefix of the delegate
1012
        key: String,
1013
    },
1014
    /// List delegates
1015
    List,
1016
}
1017
1018
#[derive(Subcommand)]
1019
enum GitCmd {
1020
    /// Export the current bookmark to a Git repository (created bare if absent)
1021
    Export {
1022
        /// Git repository to write to (created bare if absent)
1023
        git_dir: PathBuf,
1024
        /// Git branch to write (default: the bookmark name)
1025
        #[arg(long)]
1026
        branch: Option<String>,
1027
    },
1028
    /// Fetch a branch from a Git remote (path or URL) into the current bookmark
1029
    Fetch {
1030
        /// Git remote: a path or URL
1031
        url: String,
1032
        /// Branch to fetch
1033
        #[arg(long, default_value = "main")]
1034
        branch: String,
1035
        /// Author your own commits (Git author email = your identity's) with your key; sets git.claim
1036
        #[arg(long)]
1037
        claim: bool,
1038
    },
1039
    /// Push the current bookmark to a branch of a Git remote (fetch first)
1040
    Push {
1041
        /// Git remote: a path or URL
1042
        url: String,
1043
        /// Branch to push to
1044
        #[arg(long, default_value = "main")]
1045
        branch: String,
1046
    },
1047
    /// 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
1048
    Recover,
1049
    /// Check this repository's import of a Git branch: every commit's tree must be reproduced exactly
1050
    Verify {
1051
        /// The Git repository the import came from
1052
        git_dir: PathBuf,
1053
        /// Branch that was imported
1054
        #[arg(long, default_value = "main")]
1055
        branch: String,
1056
        /// Rebuild only the last N commits (the others are followed, not checked)
1057
        #[arg(long, value_name = "N")]
1058
        last: Option<usize>,
1059
        /// Stop after N differences (0: check every commit whatever it finds)
1060
        #[arg(long, value_name = "N", default_value_t = 50)]
1061
        max_differences: usize,
1062
    },
1063
    /// Import a Git branch into a new Oxygen repository at DEST
1064
    Import {
1065
        /// Git repository to read
1066
        git_dir: PathBuf,
1067
        /// Directory for the new Oxygen repository
1068
        dest: PathBuf,
1069
        /// Branch to import
1070
        #[arg(long, default_value = "main")]
1071
        branch: String,
1072
        /// Author your own commits (Git author email = your identity's) with your key; sets git.claim
1073
        #[arg(long)]
1074
        claim: bool,
1075
    },
1076
}
1077
1078
#[derive(Subcommand)]
1079
enum PolicyCmd {
1080
    /// Create the initial policy with your identity as the only root
1081
    Init,
1082
    /// Show the current policy
1083
    Show {
1084
        /// Machine-readable output: one JSON document on stdout
1085
        #[arg(long)]
1086
        json: bool,
1087
    },
1088
    /// Allow an identity (from `oxy identity export`) to update bookmarks
1089
    Grant {
1090
        /// The identity to grant, exported with `oxy identity export`
1091
        identity_file: PathBuf,
1092
        /// Reference pattern the grant applies to (default: every bookmark)
1093
        #[arg(long)]
1094
        pattern: Option<String>,
1095
        /// Where to write the proposal when more root signatures are needed
1096
        #[arg(long)]
1097
        out: Option<PathBuf>,
1098
    },
1099
    /// Allow holders of an issuer's certificates for SUBJECT to sign (keyless)
1100
    GrantSubject {
1101
        /// Who: `repo:OWNER/NAME:bookmark:main`, `agent:NAME@ACCOUNT`; `*` matches any run of characters
1102
        subject: String,
1103
        /// The issuer's identity file, e.g. a hub's /.well-known/oxyhub-key
1104
        #[arg(long)]
1105
        issuer: PathBuf,
1106
        /// What its keys may sign: changes, refs, seal
1107
        #[arg(long, default_value = "changes,refs")]
1108
        scope: String,
1109
        /// Reference pattern the grant applies to (default: every bookmark)
1110
        #[arg(long)]
1111
        pattern: Option<String>,
1112
        /// Where to write the proposal when more root signatures are needed
1113
        #[arg(long)]
1114
        out: Option<PathBuf>,
1115
    },
1116
    /// Revoke a key (KeyId prefix of an identity in the policy)
1117
    Revoke {
1118
        /// KeyId prefix of the identity
1119
        key: String,
1120
        /// Where to write the proposal when more root signatures are needed
1121
        #[arg(long)]
1122
        out: Option<PathBuf>,
1123
    },
1124
    /// Manage root keys and the signature threshold for policy updates
1125
    Root {
1126
        #[command(subcommand)]
1127
        cmd: RootCmd,
1128
    },
1129
    /// Add your root signature to a proposal file; applies it once the threshold is met
1130
    Sign {
1131
        /// The proposal file to sign
1132
        proposal: PathBuf,
1133
        /// Where to write the proposal if it still needs signatures (default: in place)
1134
        #[arg(long)]
1135
        out: Option<PathBuf>,
1136
    },
1137
}
1138
1139
#[derive(Subcommand)]
1140
enum RootCmd {
1141
    /// Make an exported identity a root key
1142
    Add {
1143
        /// The identity to make a root, exported with `oxy identity export`
1144
        identity_file: PathBuf,
1145
        /// Where to write the proposal when more root signatures are needed
1146
        #[arg(long)]
1147
        out: Option<PathBuf>,
1148
    },
1149
    /// Remove a root key by KeyId prefix
1150
    Remove {
1151
        /// KeyId prefix of the root key
1152
        key: String,
1153
        /// Where to write the proposal when more root signatures are needed
1154
        #[arg(long)]
1155
        out: Option<PathBuf>,
1156
    },
1157
    /// Require this many root signatures on policy updates
1158
    Threshold {
1159
        /// Number of root signatures
1160
        n: u32,
1161
        /// Where to write the proposal when more root signatures are needed
1162
        #[arg(long)]
1163
        out: Option<PathBuf>,
1164
    },
1165
}
1166
1167
/// Open the repository containing the current directory.
1168121×
fn open() -> Result<Repo> {
1169121×
    let repo = Repo::open(&std::env::current_dir()?).context("opening repository")?;
1170121×
    match AT_OP.get().and_then(|o| o.as_deref()) {
11710×
        Some(op) => Ok(repo.at_op(op)?),
1172121×
        None => Ok(repo),
1173
    }
1174121×
}
1175
1176
/// `oxy man`: every page into `dir`, or the top-level page on stdout.
11772×
fn man(dir: Option<PathBuf>) -> Result<i32> {
1178
    use clap::CommandFactory;
11792×
    let cmd = Cli::command();
11802×
    match dir {
11811×
        Some(dir) => {
11821×
            std::fs::create_dir_all(&dir)?;
11831×
            clap_mangen::generate_to(cmd, &dir)?;
11841×
            let pages = std::fs::read_dir(&dir)?
1185126×
                .filter(|e| {
1186126×
                    e.as_ref()
1187126×
                        .is_ok_and(|e| e.path().extension().is_some_and(|x| x == "1"))
1188126×
                })
11891×
                .count();
11901×
            println!(
1191
                "{}",
11921×
                ui::done(format!("Wrote {pages} man pages to {}", dir.display()))
1193
            );
1194
        }
11951×
        None => clap_mangen::Man::new(cmd).render(&mut std::io::stdout())?,
1196
    }
11972×
    Ok(0)
11982×
}
1199
1200
/// Parse arguments and run; returns the process exit code.
1201151×
pub fn run() -> Result<i32> {
1202
    // The cloud stores (s3://, gs://, az://) for remotes kept on them.
1203151×
    oxy_strata::register();
1204151×
    let cli = Cli::parse();
1205151×
    ui::init(cli.plain);
1206151×
    AT_OP.set(cli.at_op.clone()).ok();
12070×
    match cli.cmd {
12084×
        Cmd::Completions { shell } => {
1209
            use clap::CommandFactory;
12104×
            clap_complete::generate(shell, &mut Cli::command(), "oxy", &mut std::io::stdout());
12114×
            Ok(0)
1212
        }
12132×
        Cmd::Man { dir } => man(dir),
121414×
        Cmd::Init { path, bare, store } => workspace::init(path, bare, store.as_deref()),
12158×
        Cmd::Status { json } => workspace::status(json),
1216
        Cmd::Prompt {
12170×
            format,
12180×
            glyphs,
12190×
            color,
12200×
        } => workspace::prompt(&format, glyphs, color.as_deref()),
1221
        Cmd::Commit {
122226×
            message,
122326×
            file,
122426×
            depends_on,
122526×
            paths,
122626×
            interactive,
122726×
            hunks,
1228
        } => {
122926×
            let message = match (message, file) {
123025×
                (Some(m), _) => m,
12311×
                (None, Some(f)) if f.as_os_str() == "-" => {
12320×
                    let mut s = String::new();
12330×
                    std::io::Read::read_to_string(&mut std::io::stdin(), &mut s)?;
12340×
                    s
1235
                }
12361×
                (None, Some(f)) => std::fs::read_to_string(&f).map_err(|e| {
12370×
                    anyhow::anyhow!("reading the message from {}: {e}", f.display())
12380×
                })?,
12390×
                (None, None) => anyhow::bail!("a commit message is required (-m or -F)"),
1240
            };
124126×
            workspace::commit(&message, &depends_on, &paths, interactive, &hunks)
1242
        }
12432×
        Cmd::Cat { path, change } => workspace::cat(&path, change.as_deref()),
12441×
        Cmd::Root { json } => workspace::root(json),
12451×
        Cmd::Version { json } => workspace::version(json),
12462×
        Cmd::Discard { paths, hunks } => workspace::discard(&paths, &hunks),
12472×
        Cmd::Hunks { json } => workspace::hunks(json),
12480×
        Cmd::Squash { change, into } => workspace::squash(&change, &into),
1249
        Cmd::Rebase {
12500×
            change,
12510×
            onto,
12520×
            into_working_copy,
12530×
        } => workspace::rebase(&change, &onto, into_working_copy),
12540×
        Cmd::Blame { path, json } => workspace::blame(&path, json),
12551×
        Cmd::Bisect { cmd } => match cmd {
12560×
            BisectCmd::Start => workspace::bisect_start(),
12570×
            BisectCmd::Good { changes } => workspace::bisect_mark(Some(true), &changes),
12580×
            BisectCmd::Bad { changes } => workspace::bisect_mark(Some(false), &changes),
12590×
            BisectCmd::Skip => workspace::bisect_mark(None, &[]),
12600×
            BisectCmd::Run { command } => workspace::bisect_run(&command),
12611×
            BisectCmd::Status { json } => workspace::bisect_status(json),
12620×
            BisectCmd::Reset => workspace::bisect_reset(),
1263
        },
1264
        Cmd::Log {
12658×
            revset,
12668×
            limit,
12678×
            verbose,
12688×
            path,
12698×
            lines,
12708×
            json,
12718×
        } => workspace::log(
12728×
            revset.as_deref(),
12738×
            limit,
12748×
            verbose,
12758×
            path.as_deref(),
12768×
            lines.as_deref(),
12778×
            json,
1278
        ),
12791×
        Cmd::Diff { change, json } => workspace::diff(change.as_deref(), json),
1280
        Cmd::Describe {
12814×
            message,
12824×
            change,
12834×
            json,
12844×
        } => match message {
12850×
            Some(m) => workspace::describe(&m, change.as_deref()),
12864×
            None if change.is_some() => {
12870×
                anyhow::bail!(
1288
                    "naming works on the working copy; to change a head's message pass -m"
1289
                )
1290
            }
12914×
            None => workspace::describe_name(json),
1292
        },
12930×
        Cmd::Amend { message, into } => workspace::amend(message.as_deref(), into.as_deref()),
12940×
        Cmd::Split { change, paths } => workspace::split(&change, &paths),
1295
        Cmd::Abandon {
12960×
            change,
12970×
            revset,
12980×
            yes,
12990×
        } => workspace::abandon(change.as_deref(), revset.as_deref(), yes),
1300
        Cmd::Show {
13012×
            change,
13022×
            revset,
13032×
            json,
13042×
        } => workspace::show(change.as_deref(), revset.as_deref(), json),
1305
        Cmd::Checkout {
13060×
            changes,
13070×
            discard,
13080×
            carry,
13090×
        } => workspace::checkout(&changes, discard, carry),
13101×
        Cmd::Resolve { json } => workspace::resolve(json),
13110×
        Cmd::Undo => workspace::undo(),
1312
        Cmd::Gc {
13132×
            now,
13142×
            expire_snapshots,
13152×
            remote,
13162×
        } => match remote {
13172×
            Some(name) => workspace::gc_remote(&name, now),
13180×
            None => workspace::gc(now, expire_snapshots),
1319
        },
13200×
        Cmd::Fsck { json } => workspace::fsck(json),
13210×
        Cmd::Doctor { offline, json } => workspace::doctor(offline, json),
13220×
        Cmd::Checkpoint => workspace::checkpoint(),
13231×
        Cmd::Op { cmd } => match cmd {
13241×
            OpCmd::Log { limit, json } => workspace::op_log(limit, json),
13250×
            OpCmd::Restore { op, discard } => workspace::op_restore(&op, discard),
13260×
            OpCmd::Revert { op } => workspace::op_revert(&op),
1327
        },
1328
        Cmd::Clone {
13295×
            url,
13305×
            dest,
13315×
            max_blob,
13325×
            sparse,
13335×
            depth,
13345×
            recursive,
13355×
        } => sync::clone(&url, dest, max_blob.as_deref(), &sparse, depth, recursive),
13360×
        Cmd::Deepen { depth, remote } => sync::deepen(&remote, depth),
13370×
        Cmd::Sparse { paths } => workspace::sparse(&paths),
13380×
        Cmd::Lock { path } => workspace::lock(&path),
13390×
        Cmd::Unlock { path } => workspace::unlock(&path),
13401×
        Cmd::Workspace { cmd } => match cmd {
13410×
            WorkspaceCmd::Add { path, changes } => workspace::workspace_add(&path, &changes),
13421×
            WorkspaceCmd::List { json } => workspace::workspace_list(json),
13430×
            WorkspaceCmd::Forget { workspace } => workspace::workspace_forget(&workspace),
1344
        },
134517×
        Cmd::Bookmark { cmd } => match cmd {
1346
            BookmarkCmd::Create {
13476×
                name,
13486×
                changes,
13496×
                upto,
13506×
                only,
13516×
            } => workspace::bookmark_create(&name, &changes, upto, only),
1352
            BookmarkCmd::Set {
13533×
                name,
13543×
                changes,
13553×
                upto,
13563×
                only,
13573×
            } => workspace::bookmark_set(&name, &changes, upto, only),
13580×
            BookmarkCmd::Delete { name } => workspace::bookmark_delete(&name),
13595×
            BookmarkCmd::List { all, verbose, json } => {
13605×
                workspace::bookmark_list(all, verbose, json)
1361
            }
13620×
            BookmarkCmd::Show { name, json } => workspace::bookmark_show(name.as_deref(), json),
1363
            BookmarkCmd::Switch {
13643×
                name,
13653×
                discard,
13663×
                carry,
13673×
            } => workspace::bookmark_switch(&name, discard, carry),
1368
        },
13690×
        Cmd::Merge { bookmark } => workspace::merge(&bookmark),
13700×
        Cmd::Auth { cmd } => match cmd {
1371
            AuthCmd::Login {
13720×
                hub,
13730×
                with_token,
13740×
                ca,
13750×
            } => auth::login(hub.as_deref(), with_token, ca),
13760×
            AuthCmd::Status => auth::status(),
13770×
            AuthCmd::Logout { hub } => auth::logout(hub.as_deref()),
13780×
            AuthCmd::Grant { hub } => auth::grant(hub.as_deref()),
1379
        },
13801×
        Cmd::Submodule { cmd } => match cmd {
1381
            SubmoduleCmd::Add {
13820×
                url,
13830×
                path,
13840×
                bookmark,
13850×
            } => sync::submodule_add(&url, &path, bookmark.as_deref()),
13860×
            SubmoduleCmd::Update { init, paths } => sync::submodule_update(init, &paths),
13871×
            SubmoduleCmd::Status { json } => sync::submodule_status(json),
13880×
            SubmoduleCmd::Remove { path } => sync::submodule_remove(&path),
1389
        },
1390
        Cmd::Witness {
1391
            cmd:
1392
                WitnessCmd::Serve {
13930×
                    name,
13940×
                    logs,
13950×
                    state,
13960×
                    bind,
13970×
                    tls_cert,
13980×
                    tls_key,
1399
                },
14000×
        } => tlog::witness_serve(&name, &logs, state, &bind, tls_cert.zip(tls_key)),
14010×
        Cmd::Tlog { cmd } => match cmd {
1402
            TlogCmd::Verify {
14030×
                hub,
14040×
                key,
14050×
                all,
14060×
                json,
14070×
            } => tlog::verify(hub.as_deref(), key.as_deref(), all, json),
1408
        },
140910×
        Cmd::Receipt { cmd } => match cmd {
14102×
            ReceiptCmd::List { rev, json } => receipt::list(rev.as_deref(), json),
1411
            ReceiptCmd::Show {
14121×
                receipt: r,
14131×
                rev,
14141×
                json,
14151×
            } => receipt::show(&r, rev.as_deref(), json),
1416
            ReceiptCmd::Export {
14173×
                receipt: r,
14183×
                file,
14193×
                rev,
14203×
                format,
14213×
            } => receipt::export(&r, &file, rev.as_deref(), &format),
14222×
            ReceiptCmd::Verify { file, json } => receipt::verify(&file, json),
14232×
            ReceiptCmd::Import { file } => receipt::import(&file),
1424
        },
14253×
        Cmd::Tag { cmd } => match cmd {
1426
            TagCmd::Create {
14272×
                name,
14282×
                changes,
14292×
                message,
14302×
            } => workspace::tag_create(&name, &changes, &message),
14311×
            TagCmd::List { json } => workspace::tag_list(json),
1432
        },
143310×
        Cmd::Remote { cmd } => match cmd {
1434
            RemoteCmd::Add {
14354×
                name,
14364×
                url,
14374×
                profile,
14384×
                region,
14394×
                endpoint,
14404×
                credentials,
14414×
            } => sync::remote_add(
14424×
                &name,
14434×
                &url,
14444×
                &[
14454×
                    ("profile", profile),
14464×
                    ("region", region),
14474×
                    ("endpoint", endpoint),
14484×
                    ("credentials", credentials),
14494×
                ],
1450
            ),
14513×
            RemoteCmd::Check { name } => sync::remote_check(&name),
14521×
            RemoteCmd::Remove { name } => sync::remote_remove(&name),
14532×
            RemoteCmd::List { json } => sync::remote_list(json),
1454
        },
14551×
        Cmd::Fetch { remote, json } => sync::fetch(remote.as_deref(), json),
14564×
        Cmd::Pull { remote, json } => sync::pull(remote.as_deref(), json),
1457
        Cmd::Push {
14587×
            remote,
14597×
            force,
14607×
            bookmark,
14617×
            delete,
14627×
            json,
14637×
        } => match delete {
14640×
            Some(name) => sync::push_delete(remote.as_deref(), &name, json),
14657×
            None => sync::push(remote.as_deref(), force, bookmark.as_deref(), json),
1466
        },
1467
        Cmd::Serve {
14680×
            root,
14690×
            bind,
14700×
            tokens,
14710×
            tls_cert,
14720×
            tls_key,
14730×
        } => sync::serve(root, &bind, tokens, tls_cert.zip(tls_key)),
14743×
        Cmd::Identity { cmd } => match cmd {
1475
            IdentityCmd::Create {
14762×
                name,
14772×
                email,
14782×
                local,
14792×
                expires,
14802×
            } => identity::create(name, email, local, expires),
14810×
            IdentityCmd::Show => identity::show(),
14821×
            IdentityCmd::Export { path, pem } => identity::export(path, pem),
14830×
            IdentityCmd::SignChallenge { challenge, json } => {
14840×
                identity::sign_challenge(&challenge, json)
1485
            }
14860×
            IdentityCmd::Rotate => identity::rotate(),
14870×
            IdentityCmd::Renew { expires } => identity::renew(expires),
14880×
            IdentityCmd::Revoke { key, reason } => identity::revoke(key.as_deref(), &reason),
14890×
            IdentityCmd::Delegate { cmd } => match cmd {
1490
                DelegateCmd::Add {
14910×
                    identity_file,
14920×
                    scope,
14930×
                    expires,
14940×
                } => identity::delegate_add(&identity_file, &scope, expires.as_deref()),
14950×
                DelegateCmd::Remove { key } => identity::delegate_remove(&key),
14960×
                DelegateCmd::List => identity::delegate_list(),
1497
            },
1498
        },
1499
        Cmd::Git {
15000×
            cmd: GitCmd::Export { git_dir, branch },
15010×
        } => sync::git_export(&git_dir, branch.as_deref()),
1502
        Cmd::Git {
15030×
            cmd: GitCmd::Fetch { url, branch, claim },
15040×
        } => sync::git_fetch(&url, &branch, claim),
1505
        Cmd::Git {
15060×
            cmd: GitCmd::Push { url, branch },
15070×
        } => sync::git_push(&url, &branch),
1508
        Cmd::Git {
1509
            cmd: GitCmd::Recover,
15100×
        } => sync::git_recover(),
1511
        Cmd::Git {
1512
            cmd:
1513
                GitCmd::Import {
15140×
                    git_dir,
15150×
                    dest,
15160×
                    branch,
15170×
                    claim,
1518
                },
15190×
        } => sync::git_import(&git_dir, &dest, &branch, claim),
1520
        Cmd::Git {
1521
            cmd:
1522
                GitCmd::Verify {
15230×
                    git_dir,
15240×
                    branch,
15250×
                    last,
15260×
                    max_differences,
1527
                },
15280×
        } => sync::git_verify(&git_dir, &branch, last, max_differences),
15295×
        Cmd::Policy { cmd } => match cmd {
15301×
            PolicyCmd::Init => identity::policy_init(),
15313×
            PolicyCmd::Show { json } => identity::policy_show(json),
1532
            PolicyCmd::Grant {
15330×
                identity_file,
15340×
                pattern,
15350×
                out,
15360×
            } => identity::policy_grant(&identity_file, pattern.as_deref(), out),
1537
            PolicyCmd::GrantSubject {
15381×
                subject,
15391×
                issuer,
15401×
                scope,
15411×
                pattern,
15421×
                out,
15431×
            } => identity::policy_grant_subject(&subject, &issuer, &scope, pattern.as_deref(), out),
15440×
            PolicyCmd::Revoke { key, out } => identity::policy_revoke(&key, out),
15450×
            PolicyCmd::Root { cmd } => match cmd {
15460×
                RootCmd::Add { identity_file, out } => {
15470×
                    identity::policy_root_add(&identity_file, out)
1548
                }
15490×
                RootCmd::Remove { key, out } => identity::policy_root_remove(&key, out),
15500×
                RootCmd::Threshold { n, out } => identity::policy_threshold(n, out),
1551
            },
15520×
            PolicyCmd::Sign { proposal, out } => identity::policy_sign(&proposal, out),
1553
        },
1554
        Cmd::Seal {
15550×
            flow: Some(url),
15560×
            job: Some(job),
15570×
            reject,
15580×
            json,
1559
            ..
15600×
        } => approve::seal(&url, &job, reject, json),
1561
        Cmd::Seal {
15620×
            changes,
15630×
            proposal: Some(url),
15640×
            json,
1565
            ..
15660×
        } if changes.is_empty() => proposal::seal(&url, json),
15670×
        Cmd::Seal { changes, json, .. } => identity::seal(&changes, json),
15680×
        Cmd::Proposal { cmd } => match cmd {
15690×
            ProposalCmd::Show { url, json } => proposal::show(&url, json),
15700×
            ProposalCmd::Land { url, force } => proposal::land(&url, force),
1571
        },
1572
        Cmd::Verify {
15731×
            change,
15741×
            revset,
15751×
            json,
15761×
        } => identity::verify(change.as_deref(), revset.as_deref(), json),
1577
        Cmd::Config {
15781×
            key,
15791×
            value,
15801×
            user,
15811×
            unset,
15821×
        } => identity::config(&key, value.as_deref().unwrap_or(""), user, unset),
1583
    }
1584151×
}
1585
1586
#[cfg(test)]
1587
mod help_tests {
1588
    use super::Cli;
1589
    use clap::CommandFactory;
1590
1591
    /// Every command and every argument explains itself, so `--help`,
1592
    /// completions and the man pages are complete.
1593
    #[test]
15941×
    fn every_command_and_argument_has_help() {
1595126×
        fn walk(cmd: &clap::Command, path: &str, missing: &mut Vec<String>) {
1596126×
            let here = format!("{path} {}", cmd.get_name()).trim().to_string();
1597126×
            if cmd.get_about().is_none() && !path.is_empty() {
15980×
                missing.push(format!("{here} (command)"));
1599126×
            }
1600231×
            for a in cmd.get_arguments() {
1601231×
                let id = a.get_id().as_str();
1602231×
                if id == "help" || id == "version" || (a.is_global_set() && !path.is_empty()) {
16030×
                    continue;
1604231×
                }
1605231×
                if a.get_help().is_none() && a.get_long_help().is_none() {
16060×
                    missing.push(format!("{here} {id}"));
1607231×
                }
1608
            }
1609126×
            for sub in cmd.get_subcommands() {
1610125×
                walk(sub, &here, missing);
1611125×
            }
1612126×
        }
16131×
        let mut missing = Vec::new();
16141×
        walk(&Cli::command(), "", &mut missing);
16151×
        assert!(
16161×
            missing.is_empty(),
1617
            "{} without help:\n{}",
16180×
            missing.len(),
16190×
            missing.join("\n")
1620
        );
16211×
    }
1622
}