OXYGENHUB

Coverage / src/cli/mod.rs 58.1%

208 of 358 lines run, 9 of 18 functions · run #338 on proposal/125 · 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
        /// Machine-readable output: one JSON document on stdout
282
        #[arg(long)]
283
        json: bool,
284
    },
285
    /// Move the working copy to the state formed by CHANGE... (default: the bookmark heads)
286
    Checkout {
287
        /// Changes whose state to check out (default: the bookmark heads)
288
        changes: Vec<String>,
289
        /// Throw away uncommitted working-copy changes
290
        #[arg(long)]
291
        discard: bool,
292
        /// Take uncommitted changes along; refused when the target has
293
        /// other versions of the files they touch
294
        #[arg(long, conflicts_with = "discard")]
295
        carry: bool,
296
    },
297
    /// Report which conflicts of the working copy's base are resolved by the current files
298
    Resolve {
299
        /// Machine-readable output: one JSON document on stdout
300
        #[arg(long)]
301
        json: bool,
302
    },
303
    /// Undo the last operation
304
    Undo,
305
    /// Write a checkpoint of the current bookmark's state now
306
    Checkpoint,
307
    /// Print a shell completion script: `oxy completions bash > ~/.local/share/bash-completion/completions/oxy`
308
    Completions {
309
        /// bash, zsh, fish, elvish or powershell
310
        shell: clap_complete::Shell,
311
    },
312
    /// Write man pages (oxy.1 and one per command) into DIR, or print oxy.1
313
    Man {
314
        /// Directory to write every page into, e.g. ~/.local/share/man/man1
315
        #[arg(long)]
316
        dir: Option<PathBuf>,
317
    },
318
    /// Check the identity, configuration and remotes, and say what to do about any problem
319
    Doctor {
320
        /// Do not contact the remotes
321
        #[arg(long)]
322
        offline: bool,
323
        /// Machine-readable output: one JSON document on stdout
324
        #[arg(long)]
325
        json: bool,
326
    },
327
    /// Check the repository's integrity: objects, operation log, references, signatures, checkpoints
328
    Fsck {
329
        /// Machine-readable output: one JSON document on stdout
330
        #[arg(long)]
331
        json: bool,
332
    },
333
    /// Prune unreachable objects older than the grace period and repack everything into one pack
334
    Gc {
335
        /// Ignore the grace period (core.gc-grace) and prune immediately
336
        #[arg(long)]
337
        now: bool,
338
        /// Keep no past working-copy snapshots, only each workspace's current one, so files only they held go (core.snapshot-retention, default 7 days)
339
        #[arg(long)]
340
        expire_snapshots: bool,
341
        /// 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)
342
        #[arg(long, value_name = "NAME")]
343
        remote: Option<String>,
344
    },
345
    /// List operations
346
    #[command(name = "op")]
347
    Op {
348
        #[command(subcommand)]
349
        cmd: OpCmd,
350
    },
351
    /// Take the advisory local lock on a lockable file, making it writable
352
    Lock {
353
        /// The lockable file
354
        path: String,
355
    },
356
    /// Release the local lock and make the file read-only again
357
    Unlock {
358
        /// The locked file
359
        path: String,
360
    },
361
    /// Workspaces: extra checkout directories sharing this repository
362
    Workspace {
363
        #[command(subcommand)]
364
        cmd: WorkspaceCmd,
365
    },
366
    /// Bookmarks: named states; each workspace works on one
367
    Bookmark {
368
        #[command(subcommand)]
369
        cmd: BookmarkCmd,
370
    },
371
    /// Union another bookmark's heads into the current one (no merge change):
372
    /// a bookmark here, or a remote's (`origin/develop`) as last fetched
373
    Merge {
374
        /// The bookmark whose heads to add
375
        bookmark: String,
376
    },
377
    /// Sign in to a hub once, for every repository on it
378
    Auth {
379
        #[command(subcommand)]
380
        cmd: AuthCmd,
381
    },
382
    /// Subrepositories: nested repositories pinned to a state
383
    Submodule {
384
        #[command(subcommand)]
385
        cmd: SubmoduleCmd,
386
    },
387
    /// Witness hubs' transparency logs: cosign each checkpoint that extends
388
    /// the last one cosigned (spec §14.8)
389
    Witness {
390
        #[command(subcommand)]
391
        cmd: WitnessCmd,
392
    },
393
    /// Hubs' transparency logs: check that a hub shows everyone the same
394
    /// history (spec §14.8)
395
    Tlog {
396
        #[command(subcommand)]
397
        cmd: TlogCmd,
398
    },
399
    /// Execution receipts: signed records of what a runner ran on a state
400
    Receipt {
401
        #[command(subcommand)]
402
        cmd: ReceiptCmd,
403
    },
404
    /// Tags: immutable named states
405
    Tag {
406
        #[command(subcommand)]
407
        cmd: TagCmd,
408
    },
409
    /// Manage remotes
410
    Remote {
411
        #[command(subcommand)]
412
        cmd: RemoteCmd,
413
    },
414
    /// Fetch every bookmark of a remote into its tracking references
415
    Fetch {
416
        /// Remote name (default: origin)
417
        remote: Option<String>,
418
        /// Machine-readable output: one JSON document on stdout
419
        #[arg(long)]
420
        json: bool,
421
    },
422
    /// Fetch, then union the remote bookmark into the local one (no merge change)
423
    Pull {
424
        /// Remote name (default: origin)
425
        remote: Option<String>,
426
        /// Machine-readable output: one JSON document on stdout
427
        #[arg(long)]
428
        json: bool,
429
    },
430
    /// Push the current bookmark to a remote
431
    Push {
432
        /// Remote name (default: origin)
433
        remote: Option<String>,
434
        /// Allow dropping heads the remote has
435
        #[arg(long)]
436
        force: bool,
437
        /// Push this bookmark instead of the workspace's current one
438
        #[arg(short = 'b', long)]
439
        bookmark: Option<String>,
440
        /// Delete this bookmark on the remote (never its default bookmark);
441
        /// the local bookmark is kept
442
        #[arg(long, value_name = "NAME", conflicts_with_all = ["bookmark", "force"])]
443
        delete: Option<String>,
444
        /// Machine-readable output: one JSON document on stdout
445
        #[arg(long)]
446
        json: bool,
447
    },
448
    /// Serve repositories under ROOT over HTTPS (with --tls-cert/--tls-key) or plain HTTP
449
    Serve {
450
        /// Directory with one repository per subdirectory
451
        #[arg(long, default_value = ".")]
452
        root: PathBuf,
453
        /// Address and port to listen on
454
        #[arg(long, default_value = "127.0.0.1:8890")]
455
        bind: String,
456
        /// Bearer token allowed to push (repeatable); none means open
457
        #[arg(long = "token")]
458
        tokens: Vec<String>,
459
        /// PEM certificate chain; enables HTTPS together with --tls-key
460
        #[arg(long, requires = "tls_key")]
461
        tls_cert: Option<PathBuf>,
462
        /// PEM private key
463
        #[arg(long, requires = "tls_cert")]
464
        tls_key: Option<PathBuf>,
465
    },
466
    /// Manage the signing identity
467
    Identity {
468
        #[command(subcommand)]
469
        cmd: IdentityCmd,
470
    },
471
    /// Seal changes with your key: named ones, or every change on the current bookmark you can authenticate but have not
472
    Seal {
473
        /// Changes to seal (default: every change on the bookmark you can authenticate and have not sealed)
474
        changes: Vec<String>,
475
        /// Seal every change of a hub proposal and push the seal (your approval)
476
        #[arg(long, conflicts_with = "changes")]
477
        proposal: Option<String>,
478
        /// Approve a job of a hub run that waits for a sealed approval: `--flow https://hub/OWNER/NAME/flow/N --job apply`
479
        #[arg(long, conflicts_with_all = ["changes", "proposal"], requires = "job")]
480
        flow: Option<String>,
481
        /// The job to approve, with --flow
482
        #[arg(long, requires = "flow")]
483
        job: Option<String>,
484
        /// Reject the job instead of approving it, with --flow
485
        #[arg(long, requires = "flow")]
486
        reject: bool,
487
        /// Machine-readable output: one JSON document on stdout
488
        #[arg(long)]
489
        json: bool,
490
    },
491
    /// Hub proposals: show one, or land it from this client
492
    Proposal {
493
        #[command(subcommand)]
494
        cmd: ProposalCmd,
495
    },
496
    /// Verify the signatures on a change (default: every change in the log)
497
    Verify {
498
        /// The change to verify (default: every change in the log)
499
        change: Option<String>,
500
        /// Verify every change a revset selects: `release..main & unsigned()`
501
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
502
        revset: Option<String>,
503
        /// Machine-readable output: one JSON document on stdout
504
        #[arg(long)]
505
        json: bool,
506
    },
507
    /// Git interoperability
508
    Git {
509
        #[command(subcommand)]
510
        cmd: GitCmd,
511
    },
512
    /// Manage the trust policy (who may update which bookmarks)
513
    Policy {
514
        #[command(subcommand)]
515
        cmd: PolicyCmd,
516
    },
517
    /// 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)
518
    Config {
519
        /// The key, such as author.name or remote.origin.token
520
        key: String,
521
        /// The value to set (none with --unset); `-` reads it from standard input, out of the shell's history
522
        #[arg(required_unless_present = "unset")]
523
        value: Option<String>,
524
        /// Write to the user file (~/.config/oxy/config.toml) instead of this repository
525
        #[arg(long)]
526
        user: bool,
527
        /// Remove the key from this repository's file (or the user file with --user)
528
        #[arg(long)]
529
        unset: bool,
530
    },
531
}
532
533
#[derive(Subcommand)]
534
enum OpCmd {
535
    /// List operations, newest first, with what each changed
536
    Log {
537
        /// Show only the latest N (snapshots folded together count as one)
538
        #[arg(short = 'n', long)]
539
        limit: Option<usize>,
540
        /// Machine-readable output: one JSON document on stdout
541
        #[arg(long)]
542
        json: bool,
543
    },
544
    /// Go back to the bookmarks and working copy as they were after OP (recorded as a new operation, so it can be undone)
545
    Restore {
546
        /// The operation: an ID prefix from oxy op log, @ or @-
547
        op: String,
548
        /// Throw away uncommitted working-copy changes
549
        #[arg(long)]
550
        discard: bool,
551
    },
552
    /// Undo OP alone, keeping every operation after it: the bookmarks it moved go back
553
    Revert {
554
        /// The operation: an ID prefix from oxy op log
555
        op: String,
556
    },
557
}
558
559
#[derive(Subcommand)]
560
enum WorkspaceCmd {
561
    /// Create a workspace at PATH checked out on CHANGE... (default: the bookmark heads)
562
    Add {
563
        /// Directory for the new workspace (must be empty or absent)
564
        path: PathBuf,
565
        /// Changes whose state to check out there
566
        changes: Vec<String>,
567
    },
568
    /// List workspaces and their working-copy changes
569
    List {
570
        /// Machine-readable output: one JSON document on stdout
571
        #[arg(long)]
572
        json: bool,
573
    },
574
    /// Stop tracking a workspace (by id prefix or path); its files stay
575
    Forget {
576
        /// Workspace id prefix or path
577
        workspace: String,
578
    },
579
}
580
581
#[derive(Subcommand)]
582
enum BisectCmd {
583
    /// Begin; remembers where the working copy was
584
    Start,
585
    /// Mark CHANGE... (or the state under test) as good
586
    Good {
587
        /// Changes known to be good (default: the state under test)
588
        changes: Vec<String>,
589
    },
590
    /// Mark CHANGE... (or the state under test) as bad
591
    Bad {
592
        /// Changes known to be bad (default: the state under test)
593
        changes: Vec<String>,
594
    },
595
    /// The state under test cannot be tested; try another
596
    Skip,
597
    /// Run a command for each step: exit 0 good, 125 skip, else bad
598
    Run {
599
        /// Command and arguments to run at each step
600
        #[arg(required = true, trailing_var_arg = true)]
601
        command: Vec<String>,
602
    },
603
    /// Where the search stands
604
    Status {
605
        /// Machine-readable output: one JSON document on stdout
606
        #[arg(long)]
607
        json: bool,
608
    },
609
    /// Restore the working copy and forget the search
610
    Reset,
611
}
612
613
#[derive(Subcommand)]
614
enum BookmarkCmd {
615
    /// Create a bookmark at CHANGE... (default: the working copy's base)
616
    Create {
617
        /// Name of the new bookmark
618
        name: String,
619
        /// Its heads (default: the working copy's base). A state is its
620
        /// heads and what they depend on: a change alone may leave out
621
        /// earlier changes of the current state, which is refused unless
622
        /// --upto or --only says which is meant
623
        changes: Vec<String>,
624
        /// Everything of the current state up to CHANGE..., as a Git
625
        /// branch at a commit would hold
626
        #[arg(long, conflicts_with = "only")]
627
        upto: bool,
628
        /// Just CHANGE... and what they depend on. Other changes to the
629
        /// same files are left out, so a file can come out partly edited;
630
        /// to add one change to a bookmark's work, give the bookmark's
631
        /// heads with it instead: `bookmark set NAME <its heads> CHANGE`
632
        #[arg(long)]
633
        only: bool,
634
    },
635
    /// Point an existing bookmark at CHANGE...
636
    Set {
637
        /// The bookmark to move
638
        name: String,
639
        /// Its new heads. A change alone may leave out changes the
640
        /// bookmark now holds that were recorded before it, which is
641
        /// refused unless --upto or --only says which is meant
642
        changes: Vec<String>,
643
        /// Everything the bookmark holds up to CHANGE..., as a Git branch
644
        /// moved to a commit would hold
645
        #[arg(long, conflicts_with = "only")]
646
        upto: bool,
647
        /// Just CHANGE... and what they depend on. Other changes to the
648
        /// same files are left out, so a file can come out partly edited;
649
        /// to add one change to a bookmark's work, give the bookmark's
650
        /// heads with it instead: `bookmark set NAME <its heads> CHANGE`
651
        #[arg(long)]
652
        only: bool,
653
    },
654
    /// Remove a bookmark; its changes stay
655
    Delete {
656
        /// The bookmark to remove
657
        name: String,
658
    },
659
    /// List bookmarks with their heads and difference from origin
660
    List {
661
        /// Also list remotes' bookmarks that have no local bookmark
662
        #[arg(long, short)]
663
        all: bool,
664
        /// Each head of every bookmark, as `bookmark show` prints them
665
        #[arg(long, short)]
666
        verbose: bool,
667
        /// Machine-readable output: one JSON document on stdout
668
        #[arg(long)]
669
        json: bool,
670
    },
671
    /// A bookmark's heads: each change nothing else on it depends on,
672
    /// newest first. A bookmark name is also a revset for its heads
673
    /// (`oxy log -r NAME`, or `bookmark(NAME)` to mean only the bookmark)
674
    Show {
675
        /// The bookmark, or REMOTE/NAME (default: the current one)
676
        name: Option<String>,
677
        /// Machine-readable output: one JSON document on stdout
678
        #[arg(long)]
679
        json: bool,
680
    },
681
    /// Make NAME this workspace's bookmark and check it out. Uncommitted work stops it; --carry takes the work along, --discard drops it
682
    Switch {
683
        /// The bookmark to work on; one only a remote has (NAME or REMOTE/NAME) is created from it
684
        name: String,
685
        /// Throw away uncommitted working-copy changes
686
        #[arg(long)]
687
        discard: bool,
688
        /// Take uncommitted changes along; refused when NAME has other
689
        /// versions of the files they touch
690
        #[arg(long, conflicts_with = "discard")]
691
        carry: bool,
692
    },
693
}
694
695
#[derive(Subcommand)]
696
enum WitnessCmd {
697
    /// Serve a witness (C2SP tlog-witness: POST /add-checkpoint), signing
698
    /// with this oxy home's key (author.key)
699
    Serve {
700
        /// The witness's name in cosignatures: a host name
701
        #[arg(long)]
702
        name: String,
703
        /// A log to witness, as ORIGIN=FILE: its origin (HOST/log) and its
704
        /// key's identity file (a hub's /.well-known/oxyhub-key); repeatable
705
        #[arg(long = "log", required = true)]
706
        logs: Vec<String>,
707
        /// Where to keep what it cosigned
708
        #[arg(long, default_value = "witness-state")]
709
        state: PathBuf,
710
        /// Address and port to listen on
711
        #[arg(long, default_value = "127.0.0.1:8891")]
712
        bind: String,
713
        /// PEM certificate chain; enables HTTPS together with --tls-key
714
        #[arg(long, requires = "tls_key")]
715
        tls_cert: Option<PathBuf>,
716
        /// PEM private key for --tls-cert
717
        #[arg(long, requires = "tls_cert")]
718
        tls_key: Option<PathBuf>,
719
    },
720
}
721
722
#[derive(Subcommand)]
723
enum TlogCmd {
724
    /// Check a hub's whole log: its checkpoint against the log key and the
725
    /// last checkpoint seen, and every entry against the root it signed;
726
    /// then list this repository's entries (or a key's, or all)
727
    Verify {
728
        /// The hub, as https://oxygenhub.io (default: this checkout's remote)
729
        hub: Option<String>,
730
        /// List the entries a key signed (a KeyId) instead
731
        #[arg(long, conflicts_with = "all")]
732
        key: Option<String>,
733
        /// List every entry
734
        #[arg(long)]
735
        all: bool,
736
        /// Machine-readable output
737
        #[arg(long)]
738
        json: bool,
739
    },
740
}
741
742
#[derive(Subcommand)]
743
enum AuthCmd {
744
    /// Sign in to HUB in the browser (device sign-in) and keep the token for
745
    /// every repository there
746
    Login {
747
        /// The hub, as https://oxygenhub.io or oxygenhub.io (default: this checkout's origin)
748
        hub: Option<String>,
749
        /// Read a token from standard input instead (for CI and scripts)
750
        #[arg(long)]
751
        with_token: bool,
752
        /// PEM file of extra roots to trust (a hub with a self-signed certificate)
753
        #[arg(long)]
754
        ca: Option<PathBuf>,
755
    },
756
    /// List the hubs you are signed in to, checking each token with its hub
757
    Status,
758
    /// Forget HUB's token and revoke it on the hub
759
    Logout {
760
        /// The hub (default: this checkout's origin, or the only one)
761
        hub: Option<String>,
762
    },
763
    /// Keep an agent grant token (from `oh agent grant`) for keyless
764
    /// signing: with `author.signer = keyless`, commits and pushes are
765
    /// signed by fresh keys the hub certifies, in the grantor's name
766
    /// (the token is read from standard input, so it stays out of the
767
    /// shell's history)
768
    Grant {
769
        /// The hub (default: this checkout's origin)
770
        hub: Option<String>,
771
    },
772
}
773
774
#[derive(Subcommand)]
775
enum SubmoduleCmd {
776
    /// Clone URL (Oxygen or Git) into PATH and register it in .oxymodules
777
    Add {
778
        /// URL or path of the Oxygen or Git repository
779
        url: String,
780
        /// Where to put it, relative to the repository root
781
        path: String,
782
        /// Bookmark (Oxygen) or branch (Git) to check out and track
783
        #[arg(long)]
784
        bookmark: Option<String>,
785
    },
786
    /// Bring nested repositories to their pins
787
    Update {
788
        /// Clone nested repositories that are absent
789
        #[arg(long)]
790
        init: bool,
791
        /// Subrepos to update (default: all)
792
        paths: Vec<String>,
793
    },
794
    /// List subrepos with their pins and on-disk state
795
    Status {
796
        /// Machine-readable output: one JSON document on stdout
797
        #[arg(long)]
798
        json: bool,
799
    },
800
    /// Unregister PATH; the directory stays, the node goes with the next commit
801
    Remove {
802
        /// The subrepo to unregister
803
        path: String,
804
    },
805
}
806
807
#[derive(Subcommand)]
808
enum ReceiptCmd {
809
    /// The receipts kept for a state (default: the bookmark heads)
810
    List {
811
        /// Change, bookmark or tag whose state to look at
812
        rev: Option<String>,
813
        /// Machine-readable output: one JSON document on stdout
814
        #[arg(long)]
815
        json: bool,
816
    },
817
    /// One receipt in full, and whether its signature verifies
818
    Show {
819
        /// The receipt (a prefix of its hash, as `list` shows it)
820
        receipt: String,
821
        /// Change, bookmark or tag whose state holds it
822
        #[arg(long)]
823
        rev: Option<String>,
824
        /// Machine-readable output: one JSON document on stdout
825
        #[arg(long)]
826
        json: bool,
827
    },
828
    /// Write a signed receipt to FILE
829
    Export {
830
        /// The receipt (a prefix of its hash, as `list` shows it)
831
        receipt: String,
832
        /// Where to write it
833
        file: String,
834
        /// Change, bookmark or tag whose state holds it
835
        #[arg(long)]
836
        rev: Option<String>,
837
        /// `oxygen`: the runner's signed receipt, as `verify` and `import`
838
        /// read it. `slsa`: SLSA provenance in a DSSE envelope, signed with
839
        /// your key, for in-toto and cosign (`oxy identity export --pem`
840
        /// gives the key they check it with)
841
        #[arg(long, default_value = "oxygen", value_parser = ["oxygen", "slsa"])]
842
        format: String,
843
    },
844
    /// Check a signed receipt in FILE without keeping it
845
    Verify {
846
        /// A signed receipt, as a runner or `export` writes it
847
        file: String,
848
        /// Machine-readable output: one JSON document on stdout
849
        #[arg(long)]
850
        json: bool,
851
    },
852
    /// Verify a signed receipt in FILE and keep it with its state
853
    Import {
854
        /// A signed receipt, as a runner or `export` writes it
855
        file: String,
856
    },
857
}
858
859
#[derive(Subcommand)]
860
enum TagCmd {
861
    /// Tag the state of CHANGE... (default: the bookmark heads)
862
    Create {
863
        /// Name of the tag; tags never move
864
        name: String,
865
        /// Changes whose state to tag (default: the bookmark heads)
866
        changes: Vec<String>,
867
        /// A message recorded with the tag
868
        #[arg(short, long, default_value = "")]
869
        message: String,
870
    },
871
    /// List tags and the states they name
872
    List {
873
        /// Machine-readable output: one JSON document on stdout
874
        #[arg(long)]
875
        json: bool,
876
    },
877
}
878
879
#[derive(Subcommand)]
880
enum RemoteCmd {
881
    /// Add a remote
882
    Add {
883
        /// Name to refer to the remote by, such as origin
884
        name: String,
885
        /// 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
886
        url: String,
887
        /// For an s3:// store: the AWS profile to use (default: AWS_PROFILE, else "default")
888
        #[arg(long)]
889
        profile: Option<String>,
890
        /// For an s3:// store: its region (default: the environment, the profile, else asked of S3)
891
        #[arg(long)]
892
        region: Option<String>,
893
        /// For an s3://, gs:// or az:// store: another endpoint, such as an S3-compatible service
894
        #[arg(long)]
895
        endpoint: Option<String>,
896
        /// For a gs:// store: a service account key file, or application default credentials
897
        #[arg(long)]
898
        credentials: Option<String>,
899
    },
900
    /// Check a remote: that it is reachable with the credentials in hand, what it holds, and (for a store) that it behaves
901
    Check {
902
        /// The remote to check
903
        name: String,
904
    },
905
    /// Remove a remote
906
    Remove {
907
        /// The remote to remove
908
        name: String,
909
    },
910
    /// List remotes and their URLs
911
    List {
912
        /// Machine-readable output: one JSON document on stdout
913
        #[arg(long)]
914
        json: bool,
915
    },
916
}
917
918
#[derive(Subcommand)]
919
enum ProposalCmd {
920
    /// Show a proposal by its hub URL
921
    Show {
922
        /// The proposal's URL on the hub
923
        url: String,
924
        /// Machine-readable output: one JSON document on stdout
925
        #[arg(long)]
926
        json: bool,
927
    },
928
    /// Fetch the proposal's changes, set the target bookmark to the projected state, and push with your key
929
    Land {
930
        /// The proposal's URL on the hub
931
        url: String,
932
        /// Land even when the hub reports blockers
933
        #[arg(long)]
934
        force: bool,
935
    },
936
}
937
938
#[derive(Subcommand)]
939
enum IdentityCmd {
940
    /// Generate a composite Ed25519 + ML-DSA-65 key pair and make it your author identity
941
    Create {
942
        /// Your name (default: author.name)
943
        #[arg(long)]
944
        name: Option<String>,
945
        /// Your email (default: author.email)
946
        #[arg(long)]
947
        email: Option<String>,
948
        /// Record the author in this repository only, not in the user config
949
        #[arg(long)]
950
        local: bool,
951
        /// Expire the identity this many days from now
952
        #[arg(long)]
953
        expires: Option<u64>,
954
    },
955
    /// Show the configured identity
956
    Show,
957
    /// Write your identity object to a file, to hand to a policy holder
958
    Export {
959
        /// File to write (default: <key>.identity, or <key>.pem with --pem, in the current directory)
960
        path: Option<PathBuf>,
961
        /// Write the Ed25519 public key as PEM instead, as cosign's --key and
962
        /// other DSSE verifiers take it
963
        #[arg(long)]
964
        pem: bool,
965
    },
966
    /// Sign a host's challenge (hex, at least 16 bytes) to prove you hold your key; prints the signature as hex
967
    SignChallenge {
968
        /// The host's challenge, as hex
969
        challenge: String,
970
        /// Machine-readable output: one JSON document on stdout
971
        #[arg(long)]
972
        json: bool,
973
    },
974
    /// Move to a fresh key pair; the policy follows if it names your key
975
    Rotate,
976
    /// Re-issue your identity with a new expiry (in days from now; 0 = never)
977
    Renew {
978
        /// Days from now until it expires; 0 for never
979
        #[arg(long)]
980
        expires: u64,
981
    },
982
    /// Revoke a key: yours by default, or any key if you hold a policy root
983
    Revoke {
984
        /// KeyId prefix (default: your own key)
985
        key: Option<String>,
986
        /// Why, recorded in the revocation
987
        #[arg(long, default_value = "")]
988
        reason: String,
989
    },
990
    /// Keys allowed to sign or seal on your behalf
991
    Delegate {
992
        #[command(subcommand)]
993
        cmd: DelegateCmd,
994
    },
995
}
996
997
#[derive(Subcommand)]
998
enum DelegateCmd {
999
    /// Add a delegate from an exported identity file
1000
    Add {
1001
        /// The delegates' exported identity files: one rotation for all of them
1002
        #[arg(required = true)]
1003
        identity_file: Vec<PathBuf>,
1004
        /// What it may do for you: changes, refs, seal (comma-separated) or all.
1005
        /// An agent gets `changes`; a host that lands for you needs `changes,refs`
1006
        #[arg(long, default_value = "changes")]
1007
        scope: String,
1008
        /// How long for: 30m, 8h, 7d, or a number of days (default: until removed)
1009
        #[arg(long)]
1010
        expires: Option<String>,
1011
    },
1012
    /// Remove a delegate by KeyId prefix
1013
    Remove {
1014
        /// KeyId prefix of the delegate
1015
        key: String,
1016
    },
1017
    /// List delegates
1018
    List,
1019
}
1020
1021
#[derive(Subcommand)]
1022
enum GitCmd {
1023
    /// Export the current bookmark to a Git repository (created bare if absent)
1024
    Export {
1025
        /// Git repository to write to (created bare if absent)
1026
        git_dir: PathBuf,
1027
        /// Git branch to write (default: the bookmark name)
1028
        #[arg(long)]
1029
        branch: Option<String>,
1030
    },
1031
    /// Fetch a branch from a Git remote (path or URL) into the current bookmark
1032
    Fetch {
1033
        /// Git remote: a path or URL
1034
        url: String,
1035
        /// Branch to fetch
1036
        #[arg(long, default_value = "main")]
1037
        branch: String,
1038
        /// Author your own commits (Git author email = your identity's) with your key; sets git.claim
1039
        #[arg(long)]
1040
        claim: bool,
1041
    },
1042
    /// Push the current bookmark to a branch of a Git remote (fetch first)
1043
    Push {
1044
        /// Git remote: a path or URL
1045
        url: String,
1046
        /// Branch to push to
1047
        #[arg(long, default_value = "main")]
1048
        branch: String,
1049
    },
1050
    /// 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
1051
    Recover,
1052
    /// Check this repository's import of a Git branch: every commit's tree must be reproduced exactly
1053
    Verify {
1054
        /// The Git repository the import came from
1055
        git_dir: PathBuf,
1056
        /// Branch that was imported
1057
        #[arg(long, default_value = "main")]
1058
        branch: String,
1059
        /// Rebuild only the last N commits (the others are followed, not checked)
1060
        #[arg(long, value_name = "N")]
1061
        last: Option<usize>,
1062
        /// Stop after N differences (0: check every commit whatever it finds)
1063
        #[arg(long, value_name = "N", default_value_t = 50)]
1064
        max_differences: usize,
1065
    },
1066
    /// Import a Git branch into a new Oxygen repository at DEST
1067
    Import {
1068
        /// Git repository to read
1069
        git_dir: PathBuf,
1070
        /// Directory for the new Oxygen repository
1071
        dest: PathBuf,
1072
        /// Branch to import
1073
        #[arg(long, default_value = "main")]
1074
        branch: String,
1075
        /// Author your own commits (Git author email = your identity's) with your key; sets git.claim
1076
        #[arg(long)]
1077
        claim: bool,
1078
    },
1079
}
1080
1081
#[derive(Subcommand)]
1082
enum PolicyCmd {
1083
    /// Create the initial policy with your identity as the only root
1084
    Init,
1085
    /// Show the current policy
1086
    Show {
1087
        /// Machine-readable output: one JSON document on stdout
1088
        #[arg(long)]
1089
        json: bool,
1090
    },
1091
    /// Allow an identity (from `oxy identity export`) to update bookmarks
1092
    Grant {
1093
        /// The identity to grant, exported with `oxy identity export`
1094
        identity_file: PathBuf,
1095
        /// Reference pattern the grant applies to (default: every bookmark)
1096
        #[arg(long)]
1097
        pattern: Option<String>,
1098
        /// Where to write the proposal when more root signatures are needed
1099
        #[arg(long)]
1100
        out: Option<PathBuf>,
1101
    },
1102
    /// Allow holders of an issuer's certificates for SUBJECT to sign (keyless)
1103
    GrantSubject {
1104
        /// Who: `repo:OWNER/NAME:bookmark:main`, `agent:NAME@ACCOUNT`; `*` matches any run of characters
1105
        subject: String,
1106
        /// The issuer's identity file, e.g. a hub's /.well-known/oxyhub-key
1107
        #[arg(long)]
1108
        issuer: PathBuf,
1109
        /// What its keys may sign: changes, refs, seal
1110
        #[arg(long, default_value = "changes,refs")]
1111
        scope: String,
1112
        /// Reference pattern the grant applies to (default: every bookmark)
1113
        #[arg(long)]
1114
        pattern: Option<String>,
1115
        /// Where to write the proposal when more root signatures are needed
1116
        #[arg(long)]
1117
        out: Option<PathBuf>,
1118
    },
1119
    /// Revoke a key (KeyId prefix of an identity in the policy)
1120
    Revoke {
1121
        /// KeyId prefix of the identity
1122
        key: String,
1123
        /// Where to write the proposal when more root signatures are needed
1124
        #[arg(long)]
1125
        out: Option<PathBuf>,
1126
    },
1127
    /// Manage root keys and the signature threshold for policy updates
1128
    Root {
1129
        #[command(subcommand)]
1130
        cmd: RootCmd,
1131
    },
1132
    /// Add your root signature to a proposal file; applies it once the threshold is met
1133
    Sign {
1134
        /// The proposal file to sign
1135
        proposal: PathBuf,
1136
        /// Where to write the proposal if it still needs signatures (default: in place)
1137
        #[arg(long)]
1138
        out: Option<PathBuf>,
1139
    },
1140
}
1141
1142
#[derive(Subcommand)]
1143
enum RootCmd {
1144
    /// Make an exported identity a root key
1145
    Add {
1146
        /// The identity to make a root, exported with `oxy identity export`
1147
        identity_file: PathBuf,
1148
        /// Where to write the proposal when more root signatures are needed
1149
        #[arg(long)]
1150
        out: Option<PathBuf>,
1151
    },
1152
    /// Remove a root key by KeyId prefix
1153
    Remove {
1154
        /// KeyId prefix of the root key
1155
        key: String,
1156
        /// Where to write the proposal when more root signatures are needed
1157
        #[arg(long)]
1158
        out: Option<PathBuf>,
1159
    },
1160
    /// Require this many root signatures on policy updates
1161
    Threshold {
1162
        /// Number of root signatures
1163
        n: u32,
1164
        /// Where to write the proposal when more root signatures are needed
1165
        #[arg(long)]
1166
        out: Option<PathBuf>,
1167
    },
1168
}
1169
1170
/// Open the repository containing the current directory.
1171121×
fn open() -> Result<Repo> {
1172121×
    let repo = Repo::open(&std::env::current_dir()?).context("opening repository")?;
1173121×
    match AT_OP.get().and_then(|o| o.as_deref()) {
11740×
        Some(op) => Ok(repo.at_op(op)?),
1175121×
        None => Ok(repo),
1176
    }
1177121×
}
1178
1179
/// `oxy man`: every page into `dir`, or the top-level page on stdout.
11802×
fn man(dir: Option<PathBuf>) -> Result<i32> {
1181
    use clap::CommandFactory;
11822×
    let cmd = Cli::command();
11832×
    match dir {
11841×
        Some(dir) => {
11851×
            std::fs::create_dir_all(&dir)?;
11861×
            clap_mangen::generate_to(cmd, &dir)?;
11871×
            let pages = std::fs::read_dir(&dir)?
1188126×
                .filter(|e| {
1189126×
                    e.as_ref()
1190126×
                        .is_ok_and(|e| e.path().extension().is_some_and(|x| x == "1"))
1191126×
                })
11921×
                .count();
11931×
            println!(
1194
                "{}",
11951×
                ui::done(format!("Wrote {pages} man pages to {}", dir.display()))
1196
            );
1197
        }
11981×
        None => clap_mangen::Man::new(cmd).render(&mut std::io::stdout())?,
1199
    }
12002×
    Ok(0)
12012×
}
1202
1203
/// Parse arguments and run; returns the process exit code.
1204151×
pub fn run() -> Result<i32> {
1205
    // The cloud stores (s3://, gs://, az://) for remotes kept on them.
1206151×
    oxy_strata::register();
1207151×
    let cli = Cli::parse();
1208151×
    ui::init(cli.plain);
1209151×
    AT_OP.set(cli.at_op.clone()).ok();
12100×
    match cli.cmd {
12114×
        Cmd::Completions { shell } => {
1212
            use clap::CommandFactory;
12134×
            clap_complete::generate(shell, &mut Cli::command(), "oxy", &mut std::io::stdout());
12144×
            Ok(0)
1215
        }
12162×
        Cmd::Man { dir } => man(dir),
121714×
        Cmd::Init { path, bare, store } => workspace::init(path, bare, store.as_deref()),
12188×
        Cmd::Status { json } => workspace::status(json),
1219
        Cmd::Prompt {
12200×
            format,
12210×
            glyphs,
12220×
            color,
12230×
        } => workspace::prompt(&format, glyphs, color.as_deref()),
1224
        Cmd::Commit {
122526×
            message,
122626×
            file,
122726×
            depends_on,
122826×
            paths,
122926×
            interactive,
123026×
            hunks,
1231
        } => {
123226×
            let message = match (message, file) {
123325×
                (Some(m), _) => m,
12341×
                (None, Some(f)) if f.as_os_str() == "-" => {
12350×
                    let mut s = String::new();
12360×
                    std::io::Read::read_to_string(&mut std::io::stdin(), &mut s)?;
12370×
                    s
1238
                }
12391×
                (None, Some(f)) => std::fs::read_to_string(&f).map_err(|e| {
12400×
                    anyhow::anyhow!("reading the message from {}: {e}", f.display())
12410×
                })?,
12420×
                (None, None) => anyhow::bail!("a commit message is required (-m or -F)"),
1243
            };
124426×
            workspace::commit(&message, &depends_on, &paths, interactive, &hunks)
1245
        }
12462×
        Cmd::Cat { path, change } => workspace::cat(&path, change.as_deref()),
12471×
        Cmd::Root { json } => workspace::root(json),
12481×
        Cmd::Version { json } => workspace::version(json),
12492×
        Cmd::Discard { paths, hunks } => workspace::discard(&paths, &hunks),
12502×
        Cmd::Hunks { json } => workspace::hunks(json),
12510×
        Cmd::Squash { change, into } => workspace::squash(&change, &into),
1252
        Cmd::Rebase {
12530×
            change,
12540×
            onto,
12550×
            into_working_copy,
12560×
        } => workspace::rebase(&change, &onto, into_working_copy),
12570×
        Cmd::Blame { path, json } => workspace::blame(&path, json),
12581×
        Cmd::Bisect { cmd } => match cmd {
12590×
            BisectCmd::Start => workspace::bisect_start(),
12600×
            BisectCmd::Good { changes } => workspace::bisect_mark(Some(true), &changes),
12610×
            BisectCmd::Bad { changes } => workspace::bisect_mark(Some(false), &changes),
12620×
            BisectCmd::Skip => workspace::bisect_mark(None, &[]),
12630×
            BisectCmd::Run { command } => workspace::bisect_run(&command),
12641×
            BisectCmd::Status { json } => workspace::bisect_status(json),
12650×
            BisectCmd::Reset => workspace::bisect_reset(),
1266
        },
1267
        Cmd::Log {
12688×
            revset,
12698×
            limit,
12708×
            verbose,
12718×
            path,
12728×
            lines,
12738×
            json,
12748×
        } => workspace::log(
12758×
            revset.as_deref(),
12768×
            limit,
12778×
            verbose,
12788×
            path.as_deref(),
12798×
            lines.as_deref(),
12808×
            json,
1281
        ),
12821×
        Cmd::Diff { change, json } => workspace::diff(change.as_deref(), json),
1283
        Cmd::Describe {
12844×
            message,
12854×
            change,
12864×
            json,
12874×
        } => match message {
12880×
            Some(m) => workspace::describe(&m, change.as_deref()),
12894×
            None if change.is_some() => {
12900×
                anyhow::bail!(
1291
                    "naming works on the working copy; to change a head's message pass -m"
1292
                )
1293
            }
12944×
            None => workspace::describe_name(json),
1295
        },
1296
        Cmd::Amend {
12970×
            message,
12980×
            into,
12990×
            paths,
13000×
        } => workspace::amend(message.as_deref(), into.as_deref(), &paths),
13010×
        Cmd::Split { change, paths } => workspace::split(&change, &paths),
1302
        Cmd::Abandon {
13030×
            change,
13040×
            revset,
13050×
            yes,
13060×
        } => workspace::abandon(change.as_deref(), revset.as_deref(), yes),
1307
        Cmd::Show {
13082×
            change,
13092×
            revset,
13102×
            json,
13112×
        } => workspace::show(change.as_deref(), revset.as_deref(), json),
1312
        Cmd::Checkout {
13130×
            changes,
13140×
            discard,
13150×
            carry,
13160×
        } => workspace::checkout(&changes, discard, carry),
13171×
        Cmd::Resolve { json } => workspace::resolve(json),
13180×
        Cmd::Undo => workspace::undo(),
1319
        Cmd::Gc {
13202×
            now,
13212×
            expire_snapshots,
13222×
            remote,
13232×
        } => match remote {
13242×
            Some(name) => workspace::gc_remote(&name, now),
13250×
            None => workspace::gc(now, expire_snapshots),
1326
        },
13270×
        Cmd::Fsck { json } => workspace::fsck(json),
13280×
        Cmd::Doctor { offline, json } => workspace::doctor(offline, json),
13290×
        Cmd::Checkpoint => workspace::checkpoint(),
13301×
        Cmd::Op { cmd } => match cmd {
13311×
            OpCmd::Log { limit, json } => workspace::op_log(limit, json),
13320×
            OpCmd::Restore { op, discard } => workspace::op_restore(&op, discard),
13330×
            OpCmd::Revert { op } => workspace::op_revert(&op),
1334
        },
1335
        Cmd::Clone {
13365×
            url,
13375×
            dest,
13385×
            max_blob,
13395×
            sparse,
13405×
            depth,
13415×
            recursive,
13425×
        } => sync::clone(&url, dest, max_blob.as_deref(), &sparse, depth, recursive),
13430×
        Cmd::Deepen { depth, remote } => sync::deepen(&remote, depth),
13440×
        Cmd::Sparse { paths } => workspace::sparse(&paths),
13450×
        Cmd::Lock { path } => workspace::lock(&path),
13460×
        Cmd::Unlock { path } => workspace::unlock(&path),
13471×
        Cmd::Workspace { cmd } => match cmd {
13480×
            WorkspaceCmd::Add { path, changes } => workspace::workspace_add(&path, &changes),
13491×
            WorkspaceCmd::List { json } => workspace::workspace_list(json),
13500×
            WorkspaceCmd::Forget { workspace } => workspace::workspace_forget(&workspace),
1351
        },
135217×
        Cmd::Bookmark { cmd } => match cmd {
1353
            BookmarkCmd::Create {
13546×
                name,
13556×
                changes,
13566×
                upto,
13576×
                only,
13586×
            } => workspace::bookmark_create(&name, &changes, upto, only),
1359
            BookmarkCmd::Set {
13603×
                name,
13613×
                changes,
13623×
                upto,
13633×
                only,
13643×
            } => workspace::bookmark_set(&name, &changes, upto, only),
13650×
            BookmarkCmd::Delete { name } => workspace::bookmark_delete(&name),
13665×
            BookmarkCmd::List { all, verbose, json } => {
13675×
                workspace::bookmark_list(all, verbose, json)
1368
            }
13690×
            BookmarkCmd::Show { name, json } => workspace::bookmark_show(name.as_deref(), json),
1370
            BookmarkCmd::Switch {
13713×
                name,
13723×
                discard,
13733×
                carry,
13743×
            } => workspace::bookmark_switch(&name, discard, carry),
1375
        },
13760×
        Cmd::Merge { bookmark } => workspace::merge(&bookmark),
13770×
        Cmd::Auth { cmd } => match cmd {
1378
            AuthCmd::Login {
13790×
                hub,
13800×
                with_token,
13810×
                ca,
13820×
            } => auth::login(hub.as_deref(), with_token, ca),
13830×
            AuthCmd::Status => auth::status(),
13840×
            AuthCmd::Logout { hub } => auth::logout(hub.as_deref()),
13850×
            AuthCmd::Grant { hub } => auth::grant(hub.as_deref()),
1386
        },
13871×
        Cmd::Submodule { cmd } => match cmd {
1388
            SubmoduleCmd::Add {
13890×
                url,
13900×
                path,
13910×
                bookmark,
13920×
            } => sync::submodule_add(&url, &path, bookmark.as_deref()),
13930×
            SubmoduleCmd::Update { init, paths } => sync::submodule_update(init, &paths),
13941×
            SubmoduleCmd::Status { json } => sync::submodule_status(json),
13950×
            SubmoduleCmd::Remove { path } => sync::submodule_remove(&path),
1396
        },
1397
        Cmd::Witness {
1398
            cmd:
1399
                WitnessCmd::Serve {
14000×
                    name,
14010×
                    logs,
14020×
                    state,
14030×
                    bind,
14040×
                    tls_cert,
14050×
                    tls_key,
1406
                },
14070×
        } => tlog::witness_serve(&name, &logs, state, &bind, tls_cert.zip(tls_key)),
14080×
        Cmd::Tlog { cmd } => match cmd {
1409
            TlogCmd::Verify {
14100×
                hub,
14110×
                key,
14120×
                all,
14130×
                json,
14140×
            } => tlog::verify(hub.as_deref(), key.as_deref(), all, json),
1415
        },
141610×
        Cmd::Receipt { cmd } => match cmd {
14172×
            ReceiptCmd::List { rev, json } => receipt::list(rev.as_deref(), json),
1418
            ReceiptCmd::Show {
14191×
                receipt: r,
14201×
                rev,
14211×
                json,
14221×
            } => receipt::show(&r, rev.as_deref(), json),
1423
            ReceiptCmd::Export {
14243×
                receipt: r,
14253×
                file,
14263×
                rev,
14273×
                format,
14283×
            } => receipt::export(&r, &file, rev.as_deref(), &format),
14292×
            ReceiptCmd::Verify { file, json } => receipt::verify(&file, json),
14302×
            ReceiptCmd::Import { file } => receipt::import(&file),
1431
        },
14323×
        Cmd::Tag { cmd } => match cmd {
1433
            TagCmd::Create {
14342×
                name,
14352×
                changes,
14362×
                message,
14372×
            } => workspace::tag_create(&name, &changes, &message),
14381×
            TagCmd::List { json } => workspace::tag_list(json),
1439
        },
144010×
        Cmd::Remote { cmd } => match cmd {
1441
            RemoteCmd::Add {
14424×
                name,
14434×
                url,
14444×
                profile,
14454×
                region,
14464×
                endpoint,
14474×
                credentials,
14484×
            } => sync::remote_add(
14494×
                &name,
14504×
                &url,
14514×
                &[
14524×
                    ("profile", profile),
14534×
                    ("region", region),
14544×
                    ("endpoint", endpoint),
14554×
                    ("credentials", credentials),
14564×
                ],
1457
            ),
14583×
            RemoteCmd::Check { name } => sync::remote_check(&name),
14591×
            RemoteCmd::Remove { name } => sync::remote_remove(&name),
14602×
            RemoteCmd::List { json } => sync::remote_list(json),
1461
        },
14621×
        Cmd::Fetch { remote, json } => sync::fetch(remote.as_deref(), json),
14634×
        Cmd::Pull { remote, json } => sync::pull(remote.as_deref(), json),
1464
        Cmd::Push {
14657×
            remote,
14667×
            force,
14677×
            bookmark,
14687×
            delete,
14697×
            json,
14707×
        } => match delete {
14710×
            Some(name) => sync::push_delete(remote.as_deref(), &name, json),
14727×
            None => sync::push(remote.as_deref(), force, bookmark.as_deref(), json),
1473
        },
1474
        Cmd::Serve {
14750×
            root,
14760×
            bind,
14770×
            tokens,
14780×
            tls_cert,
14790×
            tls_key,
14800×
        } => sync::serve(root, &bind, tokens, tls_cert.zip(tls_key)),
14813×
        Cmd::Identity { cmd } => match cmd {
1482
            IdentityCmd::Create {
14832×
                name,
14842×
                email,
14852×
                local,
14862×
                expires,
14872×
            } => identity::create(name, email, local, expires),
14880×
            IdentityCmd::Show => identity::show(),
14891×
            IdentityCmd::Export { path, pem } => identity::export(path, pem),
14900×
            IdentityCmd::SignChallenge { challenge, json } => {
14910×
                identity::sign_challenge(&challenge, json)
1492
            }
14930×
            IdentityCmd::Rotate => identity::rotate(),
14940×
            IdentityCmd::Renew { expires } => identity::renew(expires),
14950×
            IdentityCmd::Revoke { key, reason } => identity::revoke(key.as_deref(), &reason),
14960×
            IdentityCmd::Delegate { cmd } => match cmd {
1497
                DelegateCmd::Add {
14980×
                    identity_file,
14990×
                    scope,
15000×
                    expires,
15010×
                } => identity::delegate_add(&identity_file, &scope, expires.as_deref()),
15020×
                DelegateCmd::Remove { key } => identity::delegate_remove(&key),
15030×
                DelegateCmd::List => identity::delegate_list(),
1504
            },
1505
        },
1506
        Cmd::Git {
15070×
            cmd: GitCmd::Export { git_dir, branch },
15080×
        } => sync::git_export(&git_dir, branch.as_deref()),
1509
        Cmd::Git {
15100×
            cmd: GitCmd::Fetch { url, branch, claim },
15110×
        } => sync::git_fetch(&url, &branch, claim),
1512
        Cmd::Git {
15130×
            cmd: GitCmd::Push { url, branch },
15140×
        } => sync::git_push(&url, &branch),
1515
        Cmd::Git {
1516
            cmd: GitCmd::Recover,
15170×
        } => sync::git_recover(),
1518
        Cmd::Git {
1519
            cmd:
1520
                GitCmd::Import {
15210×
                    git_dir,
15220×
                    dest,
15230×
                    branch,
15240×
                    claim,
1525
                },
15260×
        } => sync::git_import(&git_dir, &dest, &branch, claim),
1527
        Cmd::Git {
1528
            cmd:
1529
                GitCmd::Verify {
15300×
                    git_dir,
15310×
                    branch,
15320×
                    last,
15330×
                    max_differences,
1534
                },
15350×
        } => sync::git_verify(&git_dir, &branch, last, max_differences),
15365×
        Cmd::Policy { cmd } => match cmd {
15371×
            PolicyCmd::Init => identity::policy_init(),
15383×
            PolicyCmd::Show { json } => identity::policy_show(json),
1539
            PolicyCmd::Grant {
15400×
                identity_file,
15410×
                pattern,
15420×
                out,
15430×
            } => identity::policy_grant(&identity_file, pattern.as_deref(), out),
1544
            PolicyCmd::GrantSubject {
15451×
                subject,
15461×
                issuer,
15471×
                scope,
15481×
                pattern,
15491×
                out,
15501×
            } => identity::policy_grant_subject(&subject, &issuer, &scope, pattern.as_deref(), out),
15510×
            PolicyCmd::Revoke { key, out } => identity::policy_revoke(&key, out),
15520×
            PolicyCmd::Root { cmd } => match cmd {
15530×
                RootCmd::Add { identity_file, out } => {
15540×
                    identity::policy_root_add(&identity_file, out)
1555
                }
15560×
                RootCmd::Remove { key, out } => identity::policy_root_remove(&key, out),
15570×
                RootCmd::Threshold { n, out } => identity::policy_threshold(n, out),
1558
            },
15590×
            PolicyCmd::Sign { proposal, out } => identity::policy_sign(&proposal, out),
1560
        },
1561
        Cmd::Seal {
15620×
            flow: Some(url),
15630×
            job: Some(job),
15640×
            reject,
15650×
            json,
1566
            ..
15670×
        } => approve::seal(&url, &job, reject, json),
1568
        Cmd::Seal {
15690×
            changes,
15700×
            proposal: Some(url),
15710×
            json,
1572
            ..
15730×
        } if changes.is_empty() => proposal::seal(&url, json),
15740×
        Cmd::Seal { changes, json, .. } => identity::seal(&changes, json),
15750×
        Cmd::Proposal { cmd } => match cmd {
15760×
            ProposalCmd::Show { url, json } => proposal::show(&url, json),
15770×
            ProposalCmd::Land { url, force } => proposal::land(&url, force),
1578
        },
1579
        Cmd::Verify {
15801×
            change,
15811×
            revset,
15821×
            json,
15831×
        } => identity::verify(change.as_deref(), revset.as_deref(), json),
1584
        Cmd::Config {
15851×
            key,
15861×
            value,
15871×
            user,
15881×
            unset,
15891×
        } => identity::config(&key, value.as_deref().unwrap_or(""), user, unset),
1590
    }
1591151×
}
1592
1593
#[cfg(test)]
1594
mod help_tests {
1595
    use super::Cli;
1596
    use clap::CommandFactory;
1597
1598
    /// Every command and every argument explains itself, so `--help`,
1599
    /// completions and the man pages are complete.
1600
    #[test]
16011×
    fn every_command_and_argument_has_help() {
1602126×
        fn walk(cmd: &clap::Command, path: &str, missing: &mut Vec<String>) {
1603126×
            let here = format!("{path} {}", cmd.get_name()).trim().to_string();
1604126×
            if cmd.get_about().is_none() && !path.is_empty() {
16050×
                missing.push(format!("{here} (command)"));
1606126×
            }
1607232×
            for a in cmd.get_arguments() {
1608232×
                let id = a.get_id().as_str();
1609232×
                if id == "help" || id == "version" || (a.is_global_set() && !path.is_empty()) {
16100×
                    continue;
1611232×
                }
1612232×
                if a.get_help().is_none() && a.get_long_help().is_none() {
16130×
                    missing.push(format!("{here} {id}"));
1614232×
                }
1615
            }
1616126×
            for sub in cmd.get_subcommands() {
1617125×
                walk(sub, &here, missing);
1618125×
            }
1619126×
        }
16201×
        let mut missing = Vec::new();
16211×
        walk(&Cli::command(), "", &mut missing);
16221×
        assert!(
16231×
            missing.is_empty(),
1624
            "{} without help:\n{}",
16250×
            missing.len(),
16260×
            missing.join("\n")
1627
        );
16281×
    }
1629
}