OXYGENHUB

Coverage / src/cli/mod.rs 58.1%

209 of 360 lines run, 9 of 18 functions · run #384 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, conflicts_with = "paths")]
250
        into: Option<String>,
251
        /// Fold in only these paths; the rest stays as uncommitted work
252
        paths: Vec<String>,
253
    },
254
    /// Split a head: the named paths become a separate first change
255
    Split {
256
        /// The head to split
257
        change: String,
258
        /// Paths whose edits become the first change
259
        paths: Vec<String>,
260
    },
261
    /// Drop a change from the bookmark; its content stays on disk as uncommitted work
262
    Abandon {
263
        /// The change to drop (ChangeId prefix, #hash prefix)
264
        #[arg(required_unless_present = "revset")]
265
        change: Option<String>,
266
        /// Drop every change a revset selects, newest first
267
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
268
        revset: Option<String>,
269
        /// Drop more than five changes without asking
270
        #[arg(long, short = 'y')]
271
        yes: bool,
272
    },
273
    /// Show one change (ChangeId prefix, #hash prefix, or @), or those a revset selects
274
    Show {
275
        /// ChangeId prefix, #hash prefix, or @ for the working copy
276
        #[arg(required_unless_present = "revset")]
277
        change: Option<String>,
278
        /// Show every change a revset selects
279
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
280
        revset: Option<String>,
281
        /// The files it touched with lines added and removed, instead of the diff
282
        #[arg(long)]
283
        stat: bool,
284
        /// Machine-readable output: one JSON document on stdout
285
        #[arg(long)]
286
        json: bool,
287
    },
288
    /// Move the working copy to the state formed by CHANGE... (default: the bookmark heads)
289
    Checkout {
290
        /// Changes whose state to check out (default: the bookmark heads)
291
        changes: Vec<String>,
292
        /// Throw away uncommitted working-copy changes
293
        #[arg(long)]
294
        discard: bool,
295
        /// Take uncommitted changes along; refused when the target has
296
        /// other versions of the files they touch
297
        #[arg(long, conflicts_with = "discard")]
298
        carry: bool,
299
    },
300
    /// Report which conflicts of the working copy's base are resolved by the current files;
301
    /// with paths, settle their replace conflicts (binary files, subrepo pins) with what the
302
    /// working copy holds there
303
    Resolve {
304
        /// Opaque files or subrepos whose replace conflict to settle with their current content
305
        paths: Vec<String>,
306
        /// Machine-readable output: one JSON document on stdout
307
        #[arg(long)]
308
        json: bool,
309
    },
310
    /// Undo the last operation
311
    Undo,
312
    /// Write a checkpoint of the current bookmark's state now
313
    Checkpoint,
314
    /// Print a shell completion script: `oxy completions bash > ~/.local/share/bash-completion/completions/oxy`
315
    Completions {
316
        /// bash, zsh, fish, elvish or powershell
317
        shell: clap_complete::Shell,
318
    },
319
    /// Write man pages (oxy.1 and one per command) into DIR, or print oxy.1
320
    Man {
321
        /// Directory to write every page into, e.g. ~/.local/share/man/man1
322
        #[arg(long)]
323
        dir: Option<PathBuf>,
324
    },
325
    /// Check the identity, configuration and remotes, and say what to do about any problem
326
    Doctor {
327
        /// Do not contact the remotes
328
        #[arg(long)]
329
        offline: bool,
330
        /// Machine-readable output: one JSON document on stdout
331
        #[arg(long)]
332
        json: bool,
333
    },
334
    /// Check the repository's integrity: objects, operation log, references, signatures, checkpoints
335
    Fsck {
336
        /// Machine-readable output: one JSON document on stdout
337
        #[arg(long)]
338
        json: bool,
339
    },
340
    /// Prune unreachable objects older than the grace period and repack everything into one pack
341
    Gc {
342
        /// Ignore the grace period (core.gc-grace) and prune immediately
343
        #[arg(long)]
344
        now: bool,
345
        /// Keep no past working-copy snapshots, only each workspace's current one, so files only they held go (core.snapshot-retention, default 7 days)
346
        #[arg(long)]
347
        expire_snapshots: bool,
348
        /// 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)
349
        #[arg(long, value_name = "NAME")]
350
        remote: Option<String>,
351
    },
352
    /// List operations
353
    #[command(name = "op")]
354
    Op {
355
        #[command(subcommand)]
356
        cmd: OpCmd,
357
    },
358
    /// Take the advisory local lock on a lockable file, making it writable
359
    Lock {
360
        /// The lockable file
361
        path: String,
362
    },
363
    /// Release the local lock and make the file read-only again
364
    Unlock {
365
        /// The locked file
366
        path: String,
367
    },
368
    /// Workspaces: extra checkout directories sharing this repository
369
    Workspace {
370
        #[command(subcommand)]
371
        cmd: WorkspaceCmd,
372
    },
373
    /// Bookmarks: named states; each workspace works on one
374
    Bookmark {
375
        #[command(subcommand)]
376
        cmd: BookmarkCmd,
377
    },
378
    /// Union another bookmark's heads into the current one (no merge change):
379
    /// a bookmark here, or a remote's (`origin/develop`) as last fetched
380
    Merge {
381
        /// The bookmark whose heads to add
382
        bookmark: String,
383
    },
384
    /// Sign in to a hub once, for every repository on it
385
    Auth {
386
        #[command(subcommand)]
387
        cmd: AuthCmd,
388
    },
389
    /// Subrepositories: nested repositories pinned to a state
390
    Submodule {
391
        #[command(subcommand)]
392
        cmd: SubmoduleCmd,
393
    },
394
    /// Witness hubs' transparency logs: cosign each checkpoint that extends
395
    /// the last one cosigned (spec §14.8)
396
    Witness {
397
        #[command(subcommand)]
398
        cmd: WitnessCmd,
399
    },
400
    /// Hubs' transparency logs: check that a hub shows everyone the same
401
    /// history (spec §14.8)
402
    Tlog {
403
        #[command(subcommand)]
404
        cmd: TlogCmd,
405
    },
406
    /// Execution receipts: signed records of what a runner ran on a state
407
    Receipt {
408
        #[command(subcommand)]
409
        cmd: ReceiptCmd,
410
    },
411
    /// Tags: immutable named states
412
    Tag {
413
        #[command(subcommand)]
414
        cmd: TagCmd,
415
    },
416
    /// Manage remotes
417
    Remote {
418
        #[command(subcommand)]
419
        cmd: RemoteCmd,
420
    },
421
    /// Fetch every bookmark of a remote into its tracking references
422
    Fetch {
423
        /// Remote name (default: origin)
424
        remote: Option<String>,
425
        /// Machine-readable output: one JSON document on stdout
426
        #[arg(long)]
427
        json: bool,
428
    },
429
    /// Fetch, then union the remote bookmark into the local one (no merge change)
430
    Pull {
431
        /// Remote name (default: origin)
432
        remote: Option<String>,
433
        /// Machine-readable output: one JSON document on stdout
434
        #[arg(long)]
435
        json: bool,
436
    },
437
    /// Push the current bookmark to a remote
438
    Push {
439
        /// Remote name (default: origin)
440
        remote: Option<String>,
441
        /// Allow dropping heads the remote has
442
        #[arg(long)]
443
        force: bool,
444
        /// Push this bookmark instead of the workspace's current one
445
        #[arg(short = 'b', long)]
446
        bookmark: Option<String>,
447
        /// Delete this bookmark on the remote (never its default bookmark);
448
        /// the local bookmark is kept. `tags/NAME` withdraws a tag there
449
        /// (and here, as `oxy tag delete` does)
450
        #[arg(long, value_name = "NAME", conflicts_with_all = ["bookmark", "force"])]
451
        delete: Option<String>,
452
        /// Machine-readable output: one JSON document on stdout
453
        #[arg(long)]
454
        json: bool,
455
    },
456
    /// Serve repositories under ROOT over HTTPS (with --tls-cert/--tls-key) or plain HTTP
457
    Serve {
458
        /// Directory with one repository per subdirectory
459
        #[arg(long, default_value = ".")]
460
        root: PathBuf,
461
        /// Address and port to listen on
462
        #[arg(long, default_value = "127.0.0.1:8890")]
463
        bind: String,
464
        /// Bearer token allowed to push (repeatable); none means open
465
        #[arg(long = "token")]
466
        tokens: Vec<String>,
467
        /// PEM certificate chain; enables HTTPS together with --tls-key
468
        #[arg(long, requires = "tls_key")]
469
        tls_cert: Option<PathBuf>,
470
        /// PEM private key
471
        #[arg(long, requires = "tls_cert")]
472
        tls_key: Option<PathBuf>,
473
    },
474
    /// Manage the signing identity
475
    Identity {
476
        #[command(subcommand)]
477
        cmd: IdentityCmd,
478
    },
479
    /// Seal changes with your key: named ones, or every change on the current bookmark you can authenticate but have not
480
    Seal {
481
        /// Changes to seal (default: every change on the bookmark you can authenticate and have not sealed)
482
        changes: Vec<String>,
483
        /// Seal every change of a hub proposal and push the seal (your approval)
484
        #[arg(long, conflicts_with = "changes")]
485
        proposal: Option<String>,
486
        /// Approve a job of a hub run that waits for a sealed approval: `--flow https://hub/OWNER/NAME/flow/N --job apply`
487
        #[arg(long, conflicts_with_all = ["changes", "proposal"], requires = "job")]
488
        flow: Option<String>,
489
        /// The job to approve, with --flow
490
        #[arg(long, requires = "flow")]
491
        job: Option<String>,
492
        /// Reject the job instead of approving it, with --flow
493
        #[arg(long, requires = "flow")]
494
        reject: bool,
495
        /// Machine-readable output: one JSON document on stdout
496
        #[arg(long)]
497
        json: bool,
498
    },
499
    /// Hub proposals: show one, or land it from this client
500
    Proposal {
501
        #[command(subcommand)]
502
        cmd: ProposalCmd,
503
    },
504
    /// Verify the signatures on a change (default: every change in the log)
505
    Verify {
506
        /// The change to verify (default: every change in the log)
507
        change: Option<String>,
508
        /// Verify every change a revset selects: `release..main & unsigned()`
509
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
510
        revset: Option<String>,
511
        /// Machine-readable output: one JSON document on stdout
512
        #[arg(long)]
513
        json: bool,
514
    },
515
    /// Git interoperability
516
    Git {
517
        #[command(subcommand)]
518
        cmd: GitCmd,
519
    },
520
    /// Manage the trust policy (who may update which bookmarks)
521
    Policy {
522
        #[command(subcommand)]
523
        cmd: PolicyCmd,
524
    },
525
    /// 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)
526
    Config {
527
        /// The key, such as author.name or remote.origin.token
528
        key: String,
529
        /// The value to set (none with --unset); `-` reads it from standard input, out of the shell's history
530
        #[arg(required_unless_present = "unset")]
531
        value: Option<String>,
532
        /// Write to the user file (~/.config/oxy/config.toml) instead of this repository
533
        #[arg(long)]
534
        user: bool,
535
        /// Remove the key from this repository's file (or the user file with --user)
536
        #[arg(long)]
537
        unset: bool,
538
    },
539
}
540
541
#[derive(Subcommand)]
542
enum OpCmd {
543
    /// List operations, newest first, with what each changed
544
    Log {
545
        /// Show only the latest N (snapshots folded together count as one)
546
        #[arg(short = 'n', long)]
547
        limit: Option<usize>,
548
        /// Machine-readable output: one JSON document on stdout
549
        #[arg(long)]
550
        json: bool,
551
    },
552
    /// Go back to the bookmarks and working copy as they were after OP (recorded as a new operation, so it can be undone)
553
    Restore {
554
        /// The operation: an ID prefix from oxy op log, @ or @-
555
        op: String,
556
        /// Throw away uncommitted working-copy changes
557
        #[arg(long)]
558
        discard: bool,
559
    },
560
    /// Undo OP alone, keeping every operation after it: the bookmarks it moved go back
561
    Revert {
562
        /// The operation: an ID prefix from oxy op log
563
        op: String,
564
    },
565
}
566
567
#[derive(Subcommand)]
568
enum WorkspaceCmd {
569
    /// Create a workspace at PATH checked out on CHANGE... (default: the bookmark heads)
570
    Add {
571
        /// Directory for the new workspace (must be empty or absent)
572
        path: PathBuf,
573
        /// Changes whose state to check out there
574
        changes: Vec<String>,
575
    },
576
    /// List workspaces and their working-copy changes
577
    List {
578
        /// Machine-readable output: one JSON document on stdout
579
        #[arg(long)]
580
        json: bool,
581
    },
582
    /// Stop tracking a workspace (by id prefix or path); its files stay
583
    Forget {
584
        /// Workspace id prefix or path
585
        workspace: String,
586
    },
587
}
588
589
#[derive(Subcommand)]
590
enum BisectCmd {
591
    /// Begin; remembers where the working copy was
592
    Start,
593
    /// Mark CHANGE... (or the state under test) as good
594
    Good {
595
        /// Changes known to be good (default: the state under test)
596
        changes: Vec<String>,
597
    },
598
    /// Mark CHANGE... (or the state under test) as bad
599
    Bad {
600
        /// Changes known to be bad (default: the state under test)
601
        changes: Vec<String>,
602
    },
603
    /// The state under test cannot be tested; try another
604
    Skip,
605
    /// Run a command for each step: exit 0 good, 125 skip, else bad
606
    Run {
607
        /// Command and arguments to run at each step
608
        #[arg(required = true, trailing_var_arg = true)]
609
        command: Vec<String>,
610
    },
611
    /// Where the search stands
612
    Status {
613
        /// Machine-readable output: one JSON document on stdout
614
        #[arg(long)]
615
        json: bool,
616
    },
617
    /// Restore the working copy and forget the search
618
    Reset,
619
}
620
621
#[derive(Subcommand)]
622
enum BookmarkCmd {
623
    /// Create a bookmark at CHANGE... (default: the working copy's base)
624
    Create {
625
        /// Name of the new bookmark
626
        name: String,
627
        /// Its heads (default: the working copy's base). A state is its
628
        /// heads and what they depend on: a change alone may leave out
629
        /// earlier changes of the current state, which is refused unless
630
        /// --upto or --only says which is meant
631
        changes: Vec<String>,
632
        /// Everything of the current state up to CHANGE..., as a Git
633
        /// branch at a commit would hold
634
        #[arg(long, conflicts_with = "only")]
635
        upto: bool,
636
        /// Just CHANGE... and what they depend on. Other changes to the
637
        /// same files are left out, so a file can come out partly edited;
638
        /// to add one change to a bookmark's work, give the bookmark's
639
        /// heads with it instead: `bookmark set NAME <its heads> CHANGE`
640
        #[arg(long)]
641
        only: bool,
642
    },
643
    /// Point an existing bookmark at CHANGE...
644
    Set {
645
        /// The bookmark to move
646
        name: String,
647
        /// Its new heads. A change alone may leave out changes the
648
        /// bookmark now holds that were recorded before it, which is
649
        /// refused unless --upto or --only says which is meant
650
        changes: Vec<String>,
651
        /// Everything the bookmark holds up to CHANGE..., as a Git branch
652
        /// moved to a commit would hold
653
        #[arg(long, conflicts_with = "only")]
654
        upto: bool,
655
        /// Just CHANGE... and what they depend on. Other changes to the
656
        /// same files are left out, so a file can come out partly edited;
657
        /// to add one change to a bookmark's work, give the bookmark's
658
        /// heads with it instead: `bookmark set NAME <its heads> CHANGE`
659
        #[arg(long)]
660
        only: bool,
661
    },
662
    /// Remove a bookmark; its changes stay
663
    Delete {
664
        /// The bookmark to remove
665
        name: String,
666
    },
667
    /// List bookmarks with their heads and difference from origin
668
    List {
669
        /// Also list remotes' bookmarks that have no local bookmark
670
        #[arg(long, short)]
671
        all: bool,
672
        /// Each head of every bookmark, as `bookmark show` prints them
673
        #[arg(long, short)]
674
        verbose: bool,
675
        /// Machine-readable output: one JSON document on stdout
676
        #[arg(long)]
677
        json: bool,
678
    },
679
    /// A bookmark's heads: each change nothing else on it depends on,
680
    /// newest first. A bookmark name is also a revset for its heads
681
    /// (`oxy log -r NAME`, or `bookmark(NAME)` to mean only the bookmark)
682
    Show {
683
        /// The bookmark, or REMOTE/NAME (default: the current one)
684
        name: Option<String>,
685
        /// Machine-readable output: one JSON document on stdout
686
        #[arg(long)]
687
        json: bool,
688
    },
689
    /// Make NAME this workspace's bookmark and check it out. Uncommitted work stops it; --carry takes the work along, --discard drops it
690
    Switch {
691
        /// The bookmark to work on; one only a remote has (NAME or REMOTE/NAME) is created from it
692
        name: String,
693
        /// Throw away uncommitted working-copy changes
694
        #[arg(long)]
695
        discard: bool,
696
        /// Take uncommitted changes along; refused when NAME has other
697
        /// versions of the files they touch
698
        #[arg(long, conflicts_with = "discard")]
699
        carry: bool,
700
    },
701
}
702
703
#[derive(Subcommand)]
704
enum WitnessCmd {
705
    /// Serve a witness (C2SP tlog-witness: POST /add-checkpoint), signing
706
    /// with this oxy home's key (author.key)
707
    Serve {
708
        /// The witness's name in cosignatures: a host name
709
        #[arg(long)]
710
        name: String,
711
        /// A log to witness, as ORIGIN=FILE: its origin (HOST/log) and its
712
        /// key's identity file (a hub's /.well-known/oxyhub-key); repeatable
713
        #[arg(long = "log", required = true)]
714
        logs: Vec<String>,
715
        /// Where to keep what it cosigned
716
        #[arg(long, default_value = "witness-state")]
717
        state: PathBuf,
718
        /// Address and port to listen on
719
        #[arg(long, default_value = "127.0.0.1:8891")]
720
        bind: String,
721
        /// PEM certificate chain; enables HTTPS together with --tls-key
722
        #[arg(long, requires = "tls_key")]
723
        tls_cert: Option<PathBuf>,
724
        /// PEM private key for --tls-cert
725
        #[arg(long, requires = "tls_cert")]
726
        tls_key: Option<PathBuf>,
727
    },
728
}
729
730
#[derive(Subcommand)]
731
enum TlogCmd {
732
    /// Check a hub's whole log: its checkpoint against the log key and the
733
    /// last checkpoint seen, and every entry against the root it signed;
734
    /// then list this repository's entries (or a key's, or all)
735
    Verify {
736
        /// The hub, as https://oxygenhub.io (default: this checkout's remote)
737
        hub: Option<String>,
738
        /// List the entries a key signed (a KeyId) instead
739
        #[arg(long, conflicts_with = "all")]
740
        key: Option<String>,
741
        /// List every entry
742
        #[arg(long)]
743
        all: bool,
744
        /// Machine-readable output
745
        #[arg(long)]
746
        json: bool,
747
    },
748
}
749
750
#[derive(Subcommand)]
751
enum AuthCmd {
752
    /// Sign in to HUB in the browser (device sign-in) and keep the token for
753
    /// every repository there
754
    Login {
755
        /// The hub, as https://oxygenhub.io or oxygenhub.io (default: this checkout's origin)
756
        hub: Option<String>,
757
        /// Read a token from standard input instead (for CI and scripts)
758
        #[arg(long)]
759
        with_token: bool,
760
        /// PEM file of extra roots to trust (a hub with a self-signed certificate)
761
        #[arg(long)]
762
        ca: Option<PathBuf>,
763
    },
764
    /// List the hubs you are signed in to, checking each token with its hub
765
    Status,
766
    /// Forget HUB's token and revoke it on the hub
767
    Logout {
768
        /// The hub (default: this checkout's origin, or the only one)
769
        hub: Option<String>,
770
    },
771
    /// Keep an agent grant token (from `oh agent grant`) for keyless
772
    /// signing: with `author.signer = keyless`, commits and pushes are
773
    /// signed by fresh keys the hub certifies, in the grantor's name
774
    /// (the token is read from standard input, so it stays out of the
775
    /// shell's history)
776
    Grant {
777
        /// The hub (default: this checkout's origin)
778
        hub: Option<String>,
779
    },
780
}
781
782
#[derive(Subcommand)]
783
enum SubmoduleCmd {
784
    /// Clone URL (Oxygen or Git) into PATH and register it in .oxymodules
785
    Add {
786
        /// URL or path of the Oxygen or Git repository
787
        url: String,
788
        /// Where to put it, relative to the repository root
789
        path: String,
790
        /// Bookmark (Oxygen) or branch (Git) to check out and track
791
        #[arg(long)]
792
        bookmark: Option<String>,
793
    },
794
    /// Bring nested repositories to their pins
795
    Update {
796
        /// Clone nested repositories that are absent
797
        #[arg(long)]
798
        init: bool,
799
        /// Subrepos to update (default: all)
800
        paths: Vec<String>,
801
    },
802
    /// List subrepos with their pins and on-disk state
803
    Status {
804
        /// Machine-readable output: one JSON document on stdout
805
        #[arg(long)]
806
        json: bool,
807
    },
808
    /// Unregister PATH; the directory stays, the node goes with the next commit
809
    Remove {
810
        /// The subrepo to unregister
811
        path: String,
812
    },
813
}
814
815
#[derive(Subcommand)]
816
enum ReceiptCmd {
817
    /// The receipts kept for a state (default: the bookmark heads)
818
    List {
819
        /// Change, bookmark or tag whose state to look at
820
        rev: Option<String>,
821
        /// Machine-readable output: one JSON document on stdout
822
        #[arg(long)]
823
        json: bool,
824
    },
825
    /// One receipt in full, and whether its signature verifies
826
    Show {
827
        /// The receipt (a prefix of its hash, as `list` shows it)
828
        receipt: String,
829
        /// Change, bookmark or tag whose state holds it
830
        #[arg(long)]
831
        rev: Option<String>,
832
        /// Machine-readable output: one JSON document on stdout
833
        #[arg(long)]
834
        json: bool,
835
    },
836
    /// Write a signed receipt to FILE
837
    Export {
838
        /// The receipt (a prefix of its hash, as `list` shows it)
839
        receipt: String,
840
        /// Where to write it
841
        file: String,
842
        /// Change, bookmark or tag whose state holds it
843
        #[arg(long)]
844
        rev: Option<String>,
845
        /// `oxygen`: the runner's signed receipt, as `verify` and `import`
846
        /// read it. `slsa`: SLSA provenance in a DSSE envelope, signed with
847
        /// your key, for in-toto and cosign (`oxy identity export --pem`
848
        /// gives the key they check it with)
849
        #[arg(long, default_value = "oxygen", value_parser = ["oxygen", "slsa"])]
850
        format: String,
851
    },
852
    /// Check a signed receipt in FILE without keeping it
853
    Verify {
854
        /// A signed receipt, as a runner or `export` writes it
855
        file: String,
856
        /// Machine-readable output: one JSON document on stdout
857
        #[arg(long)]
858
        json: bool,
859
    },
860
    /// Verify a signed receipt in FILE and keep it with its state
861
    Import {
862
        /// A signed receipt, as a runner or `export` writes it
863
        file: String,
864
    },
865
}
866
867
#[derive(Subcommand)]
868
enum TagCmd {
869
    /// Tag the state of CHANGE... (default: the bookmark heads)
870
    Create {
871
        /// Name of the tag; tags never move
872
        name: String,
873
        /// Changes whose state to tag (default: the bookmark heads)
874
        changes: Vec<String>,
875
        /// A message recorded with the tag
876
        #[arg(short, long, default_value = "")]
877
        message: String,
878
    },
879
    /// Withdraw a tag: a signed withdrawal, kept beside the tag's creation;
880
    /// `oxy push` sends it to a remote that has the tag (the name is never
881
    /// used again)
882
    Delete {
883
        /// Name of the tag
884
        name: String,
885
        /// Why it is withdrawn, recorded with the withdrawal
886
        #[arg(short, long, default_value = "")]
887
        reason: String,
888
    },
889
    /// List tags and the states they name
890
    List {
891
        /// Machine-readable output: one JSON document on stdout
892
        #[arg(long)]
893
        json: bool,
894
    },
895
}
896
897
#[derive(Subcommand)]
898
enum RemoteCmd {
899
    /// Add a remote
900
    Add {
901
        /// Name to refer to the remote by, such as origin
902
        name: String,
903
        /// 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
904
        url: String,
905
        /// For an s3:// store: the AWS profile to use (default: AWS_PROFILE, else "default")
906
        #[arg(long)]
907
        profile: Option<String>,
908
        /// For an s3:// store: its region (default: the environment, the profile, else asked of S3)
909
        #[arg(long)]
910
        region: Option<String>,
911
        /// For an s3://, gs:// or az:// store: another endpoint, such as an S3-compatible service
912
        #[arg(long)]
913
        endpoint: Option<String>,
914
        /// For a gs:// store: a service account key file, or application default credentials
915
        #[arg(long)]
916
        credentials: Option<String>,
917
    },
918
    /// Check a remote: that it is reachable with the credentials in hand, what it holds, and (for a store) that it behaves
919
    Check {
920
        /// The remote to check
921
        name: String,
922
    },
923
    /// Remove a remote
924
    Remove {
925
        /// The remote to remove
926
        name: String,
927
    },
928
    /// List remotes and their URLs
929
    List {
930
        /// Machine-readable output: one JSON document on stdout
931
        #[arg(long)]
932
        json: bool,
933
    },
934
}
935
936
#[derive(Subcommand)]
937
enum ProposalCmd {
938
    /// Show a proposal by its hub URL
939
    Show {
940
        /// The proposal's URL on the hub
941
        url: String,
942
        /// Machine-readable output: one JSON document on stdout
943
        #[arg(long)]
944
        json: bool,
945
    },
946
    /// Fetch the proposal's changes, set the target bookmark to the projected state, and push with your key
947
    Land {
948
        /// The proposal's URL on the hub
949
        url: String,
950
        /// Land even when the hub reports blockers
951
        #[arg(long)]
952
        force: bool,
953
    },
954
}
955
956
#[derive(Subcommand)]
957
enum IdentityCmd {
958
    /// Generate a composite Ed25519 + ML-DSA-65 key pair and make it your author identity
959
    Create {
960
        /// Your name (default: author.name)
961
        #[arg(long)]
962
        name: Option<String>,
963
        /// Your email (default: author.email)
964
        #[arg(long)]
965
        email: Option<String>,
966
        /// Record the author in this repository only, not in the user config
967
        #[arg(long)]
968
        local: bool,
969
        /// Expire the identity this many days from now
970
        #[arg(long)]
971
        expires: Option<u64>,
972
    },
973
    /// Show the configured identity
974
    Show,
975
    /// Write your identity object to a file, to hand to a policy holder
976
    Export {
977
        /// File to write (default: <key>.identity, or <key>.pem with --pem, in the current directory)
978
        path: Option<PathBuf>,
979
        /// Write the Ed25519 public key as PEM instead, as cosign's --key and
980
        /// other DSSE verifiers take it
981
        #[arg(long)]
982
        pem: bool,
983
    },
984
    /// Sign a host's challenge (hex, at least 16 bytes) to prove you hold your key; prints the signature as hex
985
    SignChallenge {
986
        /// The host's challenge, as hex
987
        challenge: String,
988
        /// Machine-readable output: one JSON document on stdout
989
        #[arg(long)]
990
        json: bool,
991
    },
992
    /// Move to a fresh key pair; the policy follows if it names your key
993
    Rotate,
994
    /// Re-issue your identity with a new expiry (in days from now; 0 = never)
995
    Renew {
996
        /// Days from now until it expires; 0 for never
997
        #[arg(long)]
998
        expires: u64,
999
    },
1000
    /// Revoke a key: yours by default, or any key if you hold a policy root
1001
    Revoke {
1002
        /// KeyId prefix (default: your own key)
1003
        key: Option<String>,
1004
        /// Why, recorded in the revocation
1005
        #[arg(long, default_value = "")]
1006
        reason: String,
1007
    },
1008
    /// Keys allowed to sign or seal on your behalf
1009
    Delegate {
1010
        #[command(subcommand)]
1011
        cmd: DelegateCmd,
1012
    },
1013
}
1014
1015
#[derive(Subcommand)]
1016
enum DelegateCmd {
1017
    /// Add a delegate from an exported identity file
1018
    Add {
1019
        /// The delegates' exported identity files: one rotation for all of them
1020
        #[arg(required = true)]
1021
        identity_file: Vec<PathBuf>,
1022
        /// What it may do for you: changes, refs, seal (comma-separated) or all.
1023
        /// An agent gets `changes`; a host that lands for you needs `changes,refs`
1024
        #[arg(long, default_value = "changes")]
1025
        scope: String,
1026
        /// How long for: 30m, 8h, 7d, or a number of days (default: until removed)
1027
        #[arg(long)]
1028
        expires: Option<String>,
1029
    },
1030
    /// Remove a delegate by KeyId prefix
1031
    Remove {
1032
        /// KeyId prefix of the delegate
1033
        key: String,
1034
    },
1035
    /// List delegates
1036
    List,
1037
}
1038
1039
#[derive(Subcommand)]
1040
enum GitCmd {
1041
    /// Export the current bookmark to a Git repository (created bare if absent)
1042
    Export {
1043
        /// Git repository to write to (created bare if absent)
1044
        git_dir: PathBuf,
1045
        /// Git branch to write (default: the bookmark name)
1046
        #[arg(long)]
1047
        branch: Option<String>,
1048
    },
1049
    /// Fetch a branch from a Git remote (path or URL) into the current bookmark
1050
    Fetch {
1051
        /// Git remote: a path or URL
1052
        url: String,
1053
        /// Branch to fetch
1054
        #[arg(long, default_value = "main")]
1055
        branch: String,
1056
        /// Author your own commits (Git author email = your identity's) with your key; sets git.claim
1057
        #[arg(long)]
1058
        claim: bool,
1059
    },
1060
    /// Push the current bookmark to a branch of a Git remote (fetch first)
1061
    Push {
1062
        /// Git remote: a path or URL
1063
        url: String,
1064
        /// Branch to push to
1065
        #[arg(long, default_value = "main")]
1066
        branch: String,
1067
    },
1068
    /// 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
1069
    Recover,
1070
    /// Check this repository's import of a Git branch: every commit's tree must be reproduced exactly
1071
    Verify {
1072
        /// The Git repository the import came from
1073
        git_dir: PathBuf,
1074
        /// Branch that was imported
1075
        #[arg(long, default_value = "main")]
1076
        branch: String,
1077
        /// Rebuild only the last N commits (the others are followed, not checked)
1078
        #[arg(long, value_name = "N")]
1079
        last: Option<usize>,
1080
        /// Stop after N differences (0: check every commit whatever it finds)
1081
        #[arg(long, value_name = "N", default_value_t = 50)]
1082
        max_differences: usize,
1083
    },
1084
    /// Import a Git branch into a new Oxygen repository at DEST
1085
    Import {
1086
        /// Git repository to read
1087
        git_dir: PathBuf,
1088
        /// Directory for the new Oxygen repository
1089
        dest: PathBuf,
1090
        /// Branch to import
1091
        #[arg(long, default_value = "main")]
1092
        branch: String,
1093
        /// Author your own commits (Git author email = your identity's) with your key; sets git.claim
1094
        #[arg(long)]
1095
        claim: bool,
1096
    },
1097
}
1098
1099
#[derive(Subcommand)]
1100
enum PolicyCmd {
1101
    /// Create the initial policy with your identity as the only root
1102
    Init,
1103
    /// Show the current policy
1104
    Show {
1105
        /// Machine-readable output: one JSON document on stdout
1106
        #[arg(long)]
1107
        json: bool,
1108
    },
1109
    /// Allow an identity (from `oxy identity export`) to update bookmarks
1110
    Grant {
1111
        /// The identity to grant, exported with `oxy identity export`
1112
        identity_file: PathBuf,
1113
        /// Reference pattern the grant applies to (default: every bookmark)
1114
        #[arg(long)]
1115
        pattern: Option<String>,
1116
        /// Where to write the proposal when more root signatures are needed
1117
        #[arg(long)]
1118
        out: Option<PathBuf>,
1119
    },
1120
    /// Allow holders of an issuer's certificates for SUBJECT to sign (keyless)
1121
    GrantSubject {
1122
        /// Who: `repo:OWNER/NAME:bookmark:main`, `agent:NAME@ACCOUNT`; `*` matches any run of characters
1123
        subject: String,
1124
        /// The issuer's identity file, e.g. a hub's /.well-known/oxyhub-key
1125
        #[arg(long)]
1126
        issuer: PathBuf,
1127
        /// What its keys may sign: changes, refs, seal
1128
        #[arg(long, default_value = "changes,refs")]
1129
        scope: String,
1130
        /// Reference pattern the grant applies to (default: every bookmark)
1131
        #[arg(long)]
1132
        pattern: Option<String>,
1133
        /// Where to write the proposal when more root signatures are needed
1134
        #[arg(long)]
1135
        out: Option<PathBuf>,
1136
    },
1137
    /// Revoke a key (KeyId prefix of an identity in the policy)
1138
    Revoke {
1139
        /// KeyId prefix of the identity
1140
        key: String,
1141
        /// Where to write the proposal when more root signatures are needed
1142
        #[arg(long)]
1143
        out: Option<PathBuf>,
1144
    },
1145
    /// Manage root keys and the signature threshold for policy updates
1146
    Root {
1147
        #[command(subcommand)]
1148
        cmd: RootCmd,
1149
    },
1150
    /// Add your root signature to a proposal file; applies it once the threshold is met
1151
    Sign {
1152
        /// The proposal file to sign
1153
        proposal: PathBuf,
1154
        /// Where to write the proposal if it still needs signatures (default: in place)
1155
        #[arg(long)]
1156
        out: Option<PathBuf>,
1157
    },
1158
}
1159
1160
#[derive(Subcommand)]
1161
enum RootCmd {
1162
    /// Make an exported identity a root key
1163
    Add {
1164
        /// The identity to make a root, exported with `oxy identity export`
1165
        identity_file: PathBuf,
1166
        /// Where to write the proposal when more root signatures are needed
1167
        #[arg(long)]
1168
        out: Option<PathBuf>,
1169
    },
1170
    /// Remove a root key by KeyId prefix
1171
    Remove {
1172
        /// KeyId prefix of the root key
1173
        key: String,
1174
        /// Where to write the proposal when more root signatures are needed
1175
        #[arg(long)]
1176
        out: Option<PathBuf>,
1177
    },
1178
    /// Require this many root signatures on policy updates
1179
    Threshold {
1180
        /// Number of root signatures
1181
        n: u32,
1182
        /// Where to write the proposal when more root signatures are needed
1183
        #[arg(long)]
1184
        out: Option<PathBuf>,
1185
    },
1186
}
1187
1188
/// Open the repository containing the current directory.
1189122×
fn open() -> Result<Repo> {
1190122×
    let repo = Repo::open(&std::env::current_dir()?).context("opening repository")?;
1191122×
    match AT_OP.get().and_then(|o| o.as_deref()) {
11920×
        Some(op) => Ok(repo.at_op(op)?),
1193122×
        None => Ok(repo),
1194
    }
1195122×
}
1196
1197
/// `oxy man`: every page into `dir`, or the top-level page on stdout.
11982×
fn man(dir: Option<PathBuf>) -> Result<i32> {
1199
    use clap::CommandFactory;
12002×
    let cmd = Cli::command();
12012×
    match dir {
12021×
        Some(dir) => {
12031×
            std::fs::create_dir_all(&dir)?;
12041×
            clap_mangen::generate_to(cmd, &dir)?;
12051×
            let pages = std::fs::read_dir(&dir)?
1206127×
                .filter(|e| {
1207127×
                    e.as_ref()
1208127×
                        .is_ok_and(|e| e.path().extension().is_some_and(|x| x == "1"))
1209127×
                })
12101×
                .count();
12111×
            println!(
1212
                "{}",
12131×
                ui::done(format!("Wrote {pages} man pages to {}", dir.display()))
1214
            );
1215
        }
12161×
        None => clap_mangen::Man::new(cmd).render(&mut std::io::stdout())?,
1217
    }
12182×
    Ok(0)
12192×
}
1220
1221
/// Parse arguments and run; returns the process exit code.
1222152×
pub fn run() -> Result<i32> {
1223
    // The cloud stores (s3://, gs://, az://) for remotes kept on them.
1224152×
    oxy_strata::register();
1225152×
    let cli = Cli::parse();
1226152×
    ui::init(cli.plain);
1227152×
    AT_OP.set(cli.at_op.clone()).ok();
12280×
    match cli.cmd {
12294×
        Cmd::Completions { shell } => {
1230
            use clap::CommandFactory;
12314×
            clap_complete::generate(shell, &mut Cli::command(), "oxy", &mut std::io::stdout());
12324×
            Ok(0)
1233
        }
12342×
        Cmd::Man { dir } => man(dir),
123514×
        Cmd::Init { path, bare, store } => workspace::init(path, bare, store.as_deref()),
12368×
        Cmd::Status { json } => workspace::status(json),
1237
        Cmd::Prompt {
12380×
            format,
12390×
            glyphs,
12400×
            color,
12410×
        } => workspace::prompt(&format, glyphs, color.as_deref()),
1242
        Cmd::Commit {
124326×
            message,
124426×
            file,
124526×
            depends_on,
124626×
            paths,
124726×
            interactive,
124826×
            hunks,
1249
        } => {
125026×
            let message = match (message, file) {
125125×
                (Some(m), _) => m,
12521×
                (None, Some(f)) if f.as_os_str() == "-" => {
12530×
                    let mut s = String::new();
12540×
                    std::io::Read::read_to_string(&mut std::io::stdin(), &mut s)?;
12550×
                    s
1256
                }
12571×
                (None, Some(f)) => std::fs::read_to_string(&f).map_err(|e| {
12580×
                    anyhow::anyhow!("reading the message from {}: {e}", f.display())
12590×
                })?,
12600×
                (None, None) => anyhow::bail!("a commit message is required (-m or -F)"),
1261
            };
126226×
            workspace::commit(&message, &depends_on, &paths, interactive, &hunks)
1263
        }
12642×
        Cmd::Cat { path, change } => workspace::cat(&path, change.as_deref()),
12651×
        Cmd::Root { json } => workspace::root(json),
12661×
        Cmd::Version { json } => workspace::version(json),
12672×
        Cmd::Discard { paths, hunks } => workspace::discard(&paths, &hunks),
12682×
        Cmd::Hunks { json } => workspace::hunks(json),
12690×
        Cmd::Squash { change, into } => workspace::squash(&change, &into),
1270
        Cmd::Rebase {
12710×
            change,
12720×
            onto,
12730×
            into_working_copy,
12740×
        } => workspace::rebase(&change, &onto, into_working_copy),
12750×
        Cmd::Blame { path, json } => workspace::blame(&path, json),
12761×
        Cmd::Bisect { cmd } => match cmd {
12770×
            BisectCmd::Start => workspace::bisect_start(),
12780×
            BisectCmd::Good { changes } => workspace::bisect_mark(Some(true), &changes),
12790×
            BisectCmd::Bad { changes } => workspace::bisect_mark(Some(false), &changes),
12800×
            BisectCmd::Skip => workspace::bisect_mark(None, &[]),
12810×
            BisectCmd::Run { command } => workspace::bisect_run(&command),
12821×
            BisectCmd::Status { json } => workspace::bisect_status(json),
12830×
            BisectCmd::Reset => workspace::bisect_reset(),
1284
        },
1285
        Cmd::Log {
12868×
            revset,
12878×
            limit,
12888×
            verbose,
12898×
            path,
12908×
            lines,
12918×
            json,
12928×
        } => workspace::log(
12938×
            revset.as_deref(),
12948×
            limit,
12958×
            verbose,
12968×
            path.as_deref(),
12978×
            lines.as_deref(),
12988×
            json,
1299
        ),
13001×
        Cmd::Diff { change, json } => workspace::diff(change.as_deref(), json),
1301
        Cmd::Describe {
13024×
            message,
13034×
            change,
13044×
            json,
13054×
        } => match message {
13060×
            Some(m) => workspace::describe(&m, change.as_deref()),
13074×
            None if change.is_some() => {
13080×
                anyhow::bail!(
1309
                    "naming works on the working copy; to change a head's message pass -m"
1310
                )
1311
            }
13124×
            None => workspace::describe_name(json),
1313
        },
1314
        Cmd::Amend {
13150×
            message,
13160×
            into,
13170×
            paths,
13180×
        } => workspace::amend(message.as_deref(), into.as_deref(), &paths),
13190×
        Cmd::Split { change, paths } => workspace::split(&change, &paths),
1320
        Cmd::Abandon {
13210×
            change,
13220×
            revset,
13230×
            yes,
13240×
        } => workspace::abandon(change.as_deref(), revset.as_deref(), yes),
1325
        Cmd::Show {
13263×
            change,
13273×
            revset,
13283×
            stat,
13293×
            json,
13303×
        } => workspace::show(change.as_deref(), revset.as_deref(), stat, json),
1331
        Cmd::Checkout {
13320×
            changes,
13330×
            discard,
13340×
            carry,
13350×
        } => workspace::checkout(&changes, discard, carry),
13361×
        Cmd::Resolve { paths, json } => workspace::resolve(&paths, json),
13370×
        Cmd::Undo => workspace::undo(),
1338
        Cmd::Gc {
13392×
            now,
13402×
            expire_snapshots,
13412×
            remote,
13422×
        } => match remote {
13432×
            Some(name) => workspace::gc_remote(&name, now),
13440×
            None => workspace::gc(now, expire_snapshots),
1345
        },
13460×
        Cmd::Fsck { json } => workspace::fsck(json),
13470×
        Cmd::Doctor { offline, json } => workspace::doctor(offline, json),
13480×
        Cmd::Checkpoint => workspace::checkpoint(),
13491×
        Cmd::Op { cmd } => match cmd {
13501×
            OpCmd::Log { limit, json } => workspace::op_log(limit, json),
13510×
            OpCmd::Restore { op, discard } => workspace::op_restore(&op, discard),
13520×
            OpCmd::Revert { op } => workspace::op_revert(&op),
1353
        },
1354
        Cmd::Clone {
13555×
            url,
13565×
            dest,
13575×
            max_blob,
13585×
            sparse,
13595×
            depth,
13605×
            recursive,
13615×
        } => sync::clone(&url, dest, max_blob.as_deref(), &sparse, depth, recursive),
13620×
        Cmd::Deepen { depth, remote } => sync::deepen(&remote, depth),
13630×
        Cmd::Sparse { paths } => workspace::sparse(&paths),
13640×
        Cmd::Lock { path } => workspace::lock(&path),
13650×
        Cmd::Unlock { path } => workspace::unlock(&path),
13661×
        Cmd::Workspace { cmd } => match cmd {
13670×
            WorkspaceCmd::Add { path, changes } => workspace::workspace_add(&path, &changes),
13681×
            WorkspaceCmd::List { json } => workspace::workspace_list(json),
13690×
            WorkspaceCmd::Forget { workspace } => workspace::workspace_forget(&workspace),
1370
        },
137117×
        Cmd::Bookmark { cmd } => match cmd {
1372
            BookmarkCmd::Create {
13736×
                name,
13746×
                changes,
13756×
                upto,
13766×
                only,
13776×
            } => workspace::bookmark_create(&name, &changes, upto, only),
1378
            BookmarkCmd::Set {
13793×
                name,
13803×
                changes,
13813×
                upto,
13823×
                only,
13833×
            } => workspace::bookmark_set(&name, &changes, upto, only),
13840×
            BookmarkCmd::Delete { name } => workspace::bookmark_delete(&name),
13855×
            BookmarkCmd::List { all, verbose, json } => {
13865×
                workspace::bookmark_list(all, verbose, json)
1387
            }
13880×
            BookmarkCmd::Show { name, json } => workspace::bookmark_show(name.as_deref(), json),
1389
            BookmarkCmd::Switch {
13903×
                name,
13913×
                discard,
13923×
                carry,
13933×
            } => workspace::bookmark_switch(&name, discard, carry),
1394
        },
13950×
        Cmd::Merge { bookmark } => workspace::merge(&bookmark),
13960×
        Cmd::Auth { cmd } => match cmd {
1397
            AuthCmd::Login {
13980×
                hub,
13990×
                with_token,
14000×
                ca,
14010×
            } => auth::login(hub.as_deref(), with_token, ca),
14020×
            AuthCmd::Status => auth::status(),
14030×
            AuthCmd::Logout { hub } => auth::logout(hub.as_deref()),
14040×
            AuthCmd::Grant { hub } => auth::grant(hub.as_deref()),
1405
        },
14061×
        Cmd::Submodule { cmd } => match cmd {
1407
            SubmoduleCmd::Add {
14080×
                url,
14090×
                path,
14100×
                bookmark,
14110×
            } => sync::submodule_add(&url, &path, bookmark.as_deref()),
14120×
            SubmoduleCmd::Update { init, paths } => sync::submodule_update(init, &paths),
14131×
            SubmoduleCmd::Status { json } => sync::submodule_status(json),
14140×
            SubmoduleCmd::Remove { path } => sync::submodule_remove(&path),
1415
        },
1416
        Cmd::Witness {
1417
            cmd:
1418
                WitnessCmd::Serve {
14190×
                    name,
14200×
                    logs,
14210×
                    state,
14220×
                    bind,
14230×
                    tls_cert,
14240×
                    tls_key,
1425
                },
14260×
        } => tlog::witness_serve(&name, &logs, state, &bind, tls_cert.zip(tls_key)),
14270×
        Cmd::Tlog { cmd } => match cmd {
1428
            TlogCmd::Verify {
14290×
                hub,
14300×
                key,
14310×
                all,
14320×
                json,
14330×
            } => tlog::verify(hub.as_deref(), key.as_deref(), all, json),
1434
        },
143510×
        Cmd::Receipt { cmd } => match cmd {
14362×
            ReceiptCmd::List { rev, json } => receipt::list(rev.as_deref(), json),
1437
            ReceiptCmd::Show {
14381×
                receipt: r,
14391×
                rev,
14401×
                json,
14411×
            } => receipt::show(&r, rev.as_deref(), json),
1442
            ReceiptCmd::Export {
14433×
                receipt: r,
14443×
                file,
14453×
                rev,
14463×
                format,
14473×
            } => receipt::export(&r, &file, rev.as_deref(), &format),
14482×
            ReceiptCmd::Verify { file, json } => receipt::verify(&file, json),
14492×
            ReceiptCmd::Import { file } => receipt::import(&file),
1450
        },
14513×
        Cmd::Tag { cmd } => match cmd {
1452
            TagCmd::Create {
14532×
                name,
14542×
                changes,
14552×
                message,
14562×
            } => workspace::tag_create(&name, &changes, &message),
14570×
            TagCmd::Delete { name, reason } => workspace::tag_delete(&name, &reason),
14581×
            TagCmd::List { json } => workspace::tag_list(json),
1459
        },
146010×
        Cmd::Remote { cmd } => match cmd {
1461
            RemoteCmd::Add {
14624×
                name,
14634×
                url,
14644×
                profile,
14654×
                region,
14664×
                endpoint,
14674×
                credentials,
14684×
            } => sync::remote_add(
14694×
                &name,
14704×
                &url,
14714×
                &[
14724×
                    ("profile", profile),
14734×
                    ("region", region),
14744×
                    ("endpoint", endpoint),
14754×
                    ("credentials", credentials),
14764×
                ],
1477
            ),
14783×
            RemoteCmd::Check { name } => sync::remote_check(&name),
14791×
            RemoteCmd::Remove { name } => sync::remote_remove(&name),
14802×
            RemoteCmd::List { json } => sync::remote_list(json),
1481
        },
14821×
        Cmd::Fetch { remote, json } => sync::fetch(remote.as_deref(), json),
14834×
        Cmd::Pull { remote, json } => sync::pull(remote.as_deref(), json),
1484
        Cmd::Push {
14857×
            remote,
14867×
            force,
14877×
            bookmark,
14887×
            delete,
14897×
            json,
14907×
        } => match delete {
14910×
            Some(name) => sync::push_delete(remote.as_deref(), &name, json),
14927×
            None => sync::push(remote.as_deref(), force, bookmark.as_deref(), json),
1493
        },
1494
        Cmd::Serve {
14950×
            root,
14960×
            bind,
14970×
            tokens,
14980×
            tls_cert,
14990×
            tls_key,
15000×
        } => sync::serve(root, &bind, tokens, tls_cert.zip(tls_key)),
15013×
        Cmd::Identity { cmd } => match cmd {
1502
            IdentityCmd::Create {
15032×
                name,
15042×
                email,
15052×
                local,
15062×
                expires,
15072×
            } => identity::create(name, email, local, expires),
15080×
            IdentityCmd::Show => identity::show(),
15091×
            IdentityCmd::Export { path, pem } => identity::export(path, pem),
15100×
            IdentityCmd::SignChallenge { challenge, json } => {
15110×
                identity::sign_challenge(&challenge, json)
1512
            }
15130×
            IdentityCmd::Rotate => identity::rotate(),
15140×
            IdentityCmd::Renew { expires } => identity::renew(expires),
15150×
            IdentityCmd::Revoke { key, reason } => identity::revoke(key.as_deref(), &reason),
15160×
            IdentityCmd::Delegate { cmd } => match cmd {
1517
                DelegateCmd::Add {
15180×
                    identity_file,
15190×
                    scope,
15200×
                    expires,
15210×
                } => identity::delegate_add(&identity_file, &scope, expires.as_deref()),
15220×
                DelegateCmd::Remove { key } => identity::delegate_remove(&key),
15230×
                DelegateCmd::List => identity::delegate_list(),
1524
            },
1525
        },
1526
        Cmd::Git {
15270×
            cmd: GitCmd::Export { git_dir, branch },
15280×
        } => sync::git_export(&git_dir, branch.as_deref()),
1529
        Cmd::Git {
15300×
            cmd: GitCmd::Fetch { url, branch, claim },
15310×
        } => sync::git_fetch(&url, &branch, claim),
1532
        Cmd::Git {
15330×
            cmd: GitCmd::Push { url, branch },
15340×
        } => sync::git_push(&url, &branch),
1535
        Cmd::Git {
1536
            cmd: GitCmd::Recover,
15370×
        } => sync::git_recover(),
1538
        Cmd::Git {
1539
            cmd:
1540
                GitCmd::Import {
15410×
                    git_dir,
15420×
                    dest,
15430×
                    branch,
15440×
                    claim,
1545
                },
15460×
        } => sync::git_import(&git_dir, &dest, &branch, claim),
1547
        Cmd::Git {
1548
            cmd:
1549
                GitCmd::Verify {
15500×
                    git_dir,
15510×
                    branch,
15520×
                    last,
15530×
                    max_differences,
1554
                },
15550×
        } => sync::git_verify(&git_dir, &branch, last, max_differences),
15565×
        Cmd::Policy { cmd } => match cmd {
15571×
            PolicyCmd::Init => identity::policy_init(),
15583×
            PolicyCmd::Show { json } => identity::policy_show(json),
1559
            PolicyCmd::Grant {
15600×
                identity_file,
15610×
                pattern,
15620×
                out,
15630×
            } => identity::policy_grant(&identity_file, pattern.as_deref(), out),
1564
            PolicyCmd::GrantSubject {
15651×
                subject,
15661×
                issuer,
15671×
                scope,
15681×
                pattern,
15691×
                out,
15701×
            } => identity::policy_grant_subject(&subject, &issuer, &scope, pattern.as_deref(), out),
15710×
            PolicyCmd::Revoke { key, out } => identity::policy_revoke(&key, out),
15720×
            PolicyCmd::Root { cmd } => match cmd {
15730×
                RootCmd::Add { identity_file, out } => {
15740×
                    identity::policy_root_add(&identity_file, out)
1575
                }
15760×
                RootCmd::Remove { key, out } => identity::policy_root_remove(&key, out),
15770×
                RootCmd::Threshold { n, out } => identity::policy_threshold(n, out),
1578
            },
15790×
            PolicyCmd::Sign { proposal, out } => identity::policy_sign(&proposal, out),
1580
        },
1581
        Cmd::Seal {
15820×
            flow: Some(url),
15830×
            job: Some(job),
15840×
            reject,
15850×
            json,
1586
            ..
15870×
        } => approve::seal(&url, &job, reject, json),
1588
        Cmd::Seal {
15890×
            changes,
15900×
            proposal: Some(url),
15910×
            json,
1592
            ..
15930×
        } if changes.is_empty() => proposal::seal(&url, json),
15940×
        Cmd::Seal { changes, json, .. } => identity::seal(&changes, json),
15950×
        Cmd::Proposal { cmd } => match cmd {
15960×
            ProposalCmd::Show { url, json } => proposal::show(&url, json),
15970×
            ProposalCmd::Land { url, force } => proposal::land(&url, force),
1598
        },
1599
        Cmd::Verify {
16001×
            change,
16011×
            revset,
16021×
            json,
16031×
        } => identity::verify(change.as_deref(), revset.as_deref(), json),
1604
        Cmd::Config {
16051×
            key,
16061×
            value,
16071×
            user,
16081×
            unset,
16091×
        } => identity::config(&key, value.as_deref().unwrap_or(""), user, unset),
1610
    }
1611152×
}
1612
1613
#[cfg(test)]
1614
mod help_tests {
1615
    use super::Cli;
1616
    use clap::CommandFactory;
1617
1618
    /// Every command and every argument explains itself, so `--help`,
1619
    /// completions and the man pages are complete.
1620
    #[test]
16211×
    fn every_command_and_argument_has_help() {
1622127×
        fn walk(cmd: &clap::Command, path: &str, missing: &mut Vec<String>) {
1623127×
            let here = format!("{path} {}", cmd.get_name()).trim().to_string();
1624127×
            if cmd.get_about().is_none() && !path.is_empty() {
16250×
                missing.push(format!("{here} (command)"));
1626127×
            }
1627236×
            for a in cmd.get_arguments() {
1628236×
                let id = a.get_id().as_str();
1629236×
                if id == "help" || id == "version" || (a.is_global_set() && !path.is_empty()) {
16300×
                    continue;
1631236×
                }
1632236×
                if a.get_help().is_none() && a.get_long_help().is_none() {
16330×
                    missing.push(format!("{here} {id}"));
1634236×
                }
1635
            }
1636127×
            for sub in cmd.get_subcommands() {
1637126×
                walk(sub, &here, missing);
1638126×
            }
1639127×
        }
16401×
        let mut missing = Vec::new();
16411×
        walk(&Cli::command(), "", &mut missing);
16421×
        assert!(
16431×
            missing.is_empty(),
1644
            "{} without help:\n{}",
16450×
            missing.len(),
16460×
            missing.join("\n")
1647
        );
16481×
    }
1649
}