OXYGENHUB

Coverage / src/cli/mod.rs 58.7%

209 of 356 lines run, 9 of 18 functions · run #343 on proposal/124 · run missed

1
//! Command-line definitions and dispatch.
2
3
mod approve;
4
mod auth;
5
mod format;
6
mod identity;
7
mod json;
8
mod proposal;
9
mod receipt;
10
mod sync;
11
mod tlog;
12
pub mod ui;
13
mod workspace;
14
15
use anyhow::{Context, Result};
16
use clap::{Parser, Subcommand};
17
use oxy_core::repo::Repo;
18
use std::path::PathBuf;
19
20
#[derive(Parser)]
21
#[command(
22
    name = "oxy",
23
    version = env!("OXY_VERSION_LONG"),
24
    about = "Oxygen: breathing fresh air into version control"
25
)]
26
struct Cli {
27
    /// Plain output: no colour, no spinner (also implied by NO_COLOR or a non-terminal)
28
    #[arg(long, global = true)]
29
    plain: bool,
30
    /// Read the repository as it was after operation OP (an ID from oxy op log, @ or @-); commands that would change it are refused
31
    #[arg(long, global = true, value_name = "OP")]
32
    at_op: Option<String>,
33
    #[command(subcommand)]
34
    cmd: Cmd,
35
}
36
37
/// `--at-op`, for `open` to apply.
38
static AT_OP: std::sync::OnceLock<Option<String>> = std::sync::OnceLock::new();
39
40
#[derive(Subcommand)]
41
enum Cmd {
42
    /// Create a repository in PATH (default: current directory)
43
    Init {
44
        /// Directory to create the repository in (default: the current directory)
45
        path: Option<PathBuf>,
46
        /// No working copy: an object store and references only, for hosting
47
        #[arg(long)]
48
        bare: bool,
49
        /// Keep the objects and the operation log on this store
50
        /// (dir://PATH, s3://BUCKET/PREFIX, gs://…, az://…) instead of
51
        /// in .oxy, with a local cache in front (storage.cache, 2 GiB)
52
        #[arg(long, value_name = "URL")]
53
        store: Option<String>,
54
    },
55
    /// Clone a repository from a local path or an http(s) URL
56
    Clone {
57
        /// Local path or http(s) URL of the repository
58
        url: String,
59
        /// Directory to clone into (default: the last part of the URL)
60
        dest: Option<PathBuf>,
61
        /// Leave blobs larger than this (e.g. 1M) to be fetched on first read
62
        #[arg(long)]
63
        max_blob: Option<String>,
64
        /// Materialize only these paths (repeatable); implies lazy blobs
65
        #[arg(long = "sparse")]
66
        sparse: Vec<String>,
67
        /// Shallow clone: fetch only this many levels of history below the heads
68
        #[arg(long)]
69
        depth: Option<u32>,
70
        /// Clone the subrepos too (as oxy submodule update --init)
71
        #[arg(long)]
72
        recursive: bool,
73
    },
74
    /// Fetch more history below a shallow clone's boundary
75
    Deepen {
76
        /// Levels of history to add below the boundary
77
        #[arg(default_value_t = 10)]
78
        depth: u32,
79
        /// Remote to fetch the history from
80
        #[arg(long, default_value = "origin")]
81
        remote: String,
82
    },
83
    /// Show or set the sparse filter (paths to materialize); re-checks out the bookmark
84
    Sparse {
85
        /// Paths to materialize; none prints the current filter
86
        paths: Vec<String>,
87
    },
88
    /// Show the working copy: changed paths and conflicts
89
    Status {
90
        /// Machine-readable output: paths, and every conflict with its kind and contributing changes
91
        #[arg(long)]
92
        json: bool,
93
    },
94
    /// One-line summary for shell prompts; fast and records nothing
95
    Prompt {
96
        /// Placeholders: %b bookmark, %c change id, %h heads, %d dirty (*), %x conflict (!), %A/%D ahead/behind (+n/-n), %a/%B raw counts, %s state glyph, %U/%O ahead/behind arrows, %i icon
97
        #[arg(long, default_value = oxy_core::repo::DEFAULT_PROMPT_FORMAT)]
98
        format: String,
99
        /// Glyph format (%i %b %c %s%U%O) instead of the plain default
100
        #[arg(long)]
101
        glyphs: bool,
102
        /// Colour by state (cyan clean, yellow dirty, red conflicted): raw escapes, or guarded for a bash or zsh PS1
103
        #[arg(long, value_parser = ["raw", "bash", "zsh"])]
104
        color: Option<String>,
105
    },
106
    /// Record the working copy as a change on the current bookmark
107
    Commit {
108
        /// The change's message: a subject line, then optionally a blank line and a body
109
        #[arg(short, long, required_unless_present = "file", conflicts_with = "file")]
110
        message: Option<String>,
111
        /// Read the message from FILE (`-` for standard input)
112
        #[arg(short = 'F', long, value_name = "FILE")]
113
        file: Option<PathBuf>,
114
        /// Extra explicit dependencies (ChangeId prefix, #hash prefix)
115
        #[arg(long = "depends-on")]
116
        depends_on: Vec<String>,
117
        /// Commit only these paths; the rest stays as uncommitted work
118
        paths: Vec<String>,
119
        /// Choose hunks one by one
120
        #[arg(short, long)]
121
        interactive: bool,
122
        /// Commit these hunks (as `oxy hunks` numbers them), comma separated
123
        #[arg(long, value_delimiter = ',')]
124
        hunks: Vec<usize>,
125
    },
126
    /// Fold CHANGE into one of its dependencies (keeps that change's id)
127
    Squash {
128
        /// The change to fold (ChangeId prefix, #hash prefix)
129
        change: String,
130
        /// The dependency that absorbs it
131
        #[arg(long)]
132
        into: String,
133
    },
134
    /// Re-express CHANGE against another base state
135
    Rebase {
136
        /// The change to re-express (ChangeId prefix, #hash prefix)
137
        change: String,
138
        /// The changes, bookmark or tag whose state becomes the new base
139
        #[arg(long, required = true, num_args = 1..)]
140
        onto: Vec<String>,
141
        /// Where the rebase would be conflicted, merge the target into the
142
        /// current bookmark instead, leaving the conflict in the working
143
        /// copy to fix and commit
144
        #[arg(long)]
145
        into_working_copy: bool,
146
    },
147
    /// Show which change introduced each line of a file
148
    Blame {
149
        /// File to annotate, relative to the repository root
150
        path: String,
151
        /// Machine-readable output: one JSON document on stdout
152
        #[arg(long)]
153
        json: bool,
154
    },
155
    /// Find the change that introduced a regression
156
    Bisect {
157
        #[command(subcommand)]
158
        cmd: BisectCmd,
159
    },
160
    /// List changes reachable from the bookmark and the working copy
161
    Log {
162
        /// Show the changes a revset selects: `main` (a bookmark name means its
163
        /// heads; `bookmark(main)` only ever the bookmark), `main..feature &
164
        /// author(andy)`, `touches("src/**") & date(-7d..)` (see
165
        /// docs/revset_query_language.md)
166
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with_all = ["path", "lines"])]
167
        revset: Option<String>,
168
        /// Show at most this many changes
169
        #[arg(short = 'n', long)]
170
        limit: Option<usize>,
171
        /// Show full messages, dependencies, and signatures
172
        #[arg(short, long)]
173
        verbose: bool,
174
        /// Only changes touching this path (renames followed)
175
        #[arg(long)]
176
        path: Option<String>,
177
        /// Only changes that wrote or deleted lines START to END of PATH
178
        /// (numbered as in the working copy's base), or deleted lines from
179
        /// between them: the history of a function
180
        #[arg(short = 'L', value_name = "START,END:PATH", conflicts_with = "path")]
181
        lines: Option<String>,
182
        /// Machine-readable output: one JSON document on stdout
183
        #[arg(long)]
184
        json: bool,
185
    },
186
    /// Show what the working copy changes against its base
187
    Diff {
188
        /// A change instead of the working copy
189
        change: Option<String>,
190
        /// Machine-readable output: one JSON document on stdout
191
        #[arg(long)]
192
        json: bool,
193
    },
194
    /// Print a file as it is in a state (default: the working copy's base)
195
    Cat {
196
        /// File to print, relative to the repository root
197
        path: String,
198
        /// A bookmark or tag (its state), or a change: a change means its
199
        /// dependency closure, the change and what it depends on, so files
200
        /// only later changes touched are absent or at older versions
201
        #[arg(short = 'r', long)]
202
        change: Option<String>,
203
    },
204
    /// Print the repository root, workspace, and bookmark
205
    Root {
206
        /// Machine-readable output: one JSON document on stdout
207
        #[arg(long)]
208
        json: bool,
209
    },
210
    /// Print the version of oxy, its repository format, and protocol
211
    Version {
212
        /// Machine-readable output: one JSON document on stdout
213
        #[arg(long)]
214
        json: bool,
215
    },
216
    /// Restore paths to the working copy's base, or undo chosen hunks
217
    Discard {
218
        /// Paths to restore; none with --hunks, or everything with neither
219
        paths: Vec<String>,
220
        /// Hunk indices as `oxy hunks` numbers them, comma separated
221
        #[arg(long, value_delimiter = ',')]
222
        hunks: Vec<usize>,
223
    },
224
    /// List the working copy's hunks, numbered as commit --hunks expects
225
    Hunks {
226
        /// Machine-readable output: one JSON document on stdout
227
        #[arg(long)]
228
        json: bool,
229
    },
230
    /// With -m, change the message of a head; without, name the working
231
    /// copy for a build: its tag, or the nearest tag plus distance and
232
    /// change, or the bookmark and change, and -dirty
233
    Describe {
234
        /// The new message
235
        #[arg(short, long)]
236
        message: Option<String>,
237
        /// The head to describe (default: the one the working copy sits on)
238
        change: Option<String>,
239
        /// Machine-readable output (naming only)
240
        #[arg(long, conflicts_with = "message")]
241
        json: bool,
242
    },
243
    /// Fold the working copy into the head it sits on, or into CHANGE with --into
244
    Amend {
245
        /// Replace the message too
246
        #[arg(short, long)]
247
        message: Option<String>,
248
        /// Amend an older change; the edits must touch only lines it already knows
249
        #[arg(long)]
250
        into: Option<String>,
251
    },
252
    /// Split a head: the named paths become a separate first change
253
    Split {
254
        /// The head to split
255
        change: String,
256
        /// Paths whose edits become the first change
257
        paths: Vec<String>,
258
    },
259
    /// Drop a change from the bookmark; its content stays on disk as uncommitted work
260
    Abandon {
261
        /// The change to drop (ChangeId prefix, #hash prefix)
262
        #[arg(required_unless_present = "revset")]
263
        change: Option<String>,
264
        /// Drop every change a revset selects, newest first
265
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
266
        revset: Option<String>,
267
        /// Drop more than five changes without asking
268
        #[arg(long, short = 'y')]
269
        yes: bool,
270
    },
271
    /// Show one change (ChangeId prefix, #hash prefix, or @), or those a revset selects
272
    Show {
273
        /// ChangeId prefix, #hash prefix, or @ for the working copy
274
        #[arg(required_unless_present = "revset")]
275
        change: Option<String>,
276
        /// Show every change a revset selects
277
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
278
        revset: Option<String>,
279
        /// The files it touched with lines added and removed, instead of the diff
280
        #[arg(long)]
281
        stat: bool,
282
        /// Machine-readable output: one JSON document on stdout
283
        #[arg(long)]
284
        json: bool,
285
    },
286
    /// Move the working copy to the state formed by CHANGE... (default: the bookmark heads)
287
    Checkout {
288
        /// Changes whose state to check out (default: the bookmark heads)
289
        changes: Vec<String>,
290
        /// Throw away uncommitted working-copy changes
291
        #[arg(long)]
292
        discard: bool,
293
        /// Take uncommitted changes along; refused when the target has
294
        /// other versions of the files they touch
295
        #[arg(long, conflicts_with = "discard")]
296
        carry: bool,
297
    },
298
    /// Report which conflicts of the working copy's base are resolved by the current files
299
    Resolve {
300
        /// Machine-readable output: one JSON document on stdout
301
        #[arg(long)]
302
        json: bool,
303
    },
304
    /// Undo the last operation
305
    Undo,
306
    /// Write a checkpoint of the current bookmark's state now
307
    Checkpoint,
308
    /// Print a shell completion script: `oxy completions bash > ~/.local/share/bash-completion/completions/oxy`
309
    Completions {
310
        /// bash, zsh, fish, elvish or powershell
311
        shell: clap_complete::Shell,
312
    },
313
    /// Write man pages (oxy.1 and one per command) into DIR, or print oxy.1
314
    Man {
315
        /// Directory to write every page into, e.g. ~/.local/share/man/man1
316
        #[arg(long)]
317
        dir: Option<PathBuf>,
318
    },
319
    /// Check the identity, configuration and remotes, and say what to do about any problem
320
    Doctor {
321
        /// Do not contact the remotes
322
        #[arg(long)]
323
        offline: bool,
324
        /// Machine-readable output: one JSON document on stdout
325
        #[arg(long)]
326
        json: bool,
327
    },
328
    /// Check the repository's integrity: objects, operation log, references, signatures, checkpoints
329
    Fsck {
330
        /// Machine-readable output: one JSON document on stdout
331
        #[arg(long)]
332
        json: bool,
333
    },
334
    /// Prune unreachable objects older than the grace period and repack everything into one pack
335
    Gc {
336
        /// Ignore the grace period (core.gc-grace) and prune immediately
337
        #[arg(long)]
338
        now: bool,
339
        /// Keep no past working-copy snapshots, only each workspace's current one, so files only they held go (core.snapshot-retention, default 7 days)
340
        #[arg(long)]
341
        expire_snapshots: bool,
342
        /// 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)
343
        #[arg(long, value_name = "NAME")]
344
        remote: Option<String>,
345
    },
346
    /// List operations
347
    #[command(name = "op")]
348
    Op {
349
        #[command(subcommand)]
350
        cmd: OpCmd,
351
    },
352
    /// Take the advisory local lock on a lockable file, making it writable
353
    Lock {
354
        /// The lockable file
355
        path: String,
356
    },
357
    /// Release the local lock and make the file read-only again
358
    Unlock {
359
        /// The locked file
360
        path: String,
361
    },
362
    /// Workspaces: extra checkout directories sharing this repository
363
    Workspace {
364
        #[command(subcommand)]
365
        cmd: WorkspaceCmd,
366
    },
367
    /// Bookmarks: named states; each workspace works on one
368
    Bookmark {
369
        #[command(subcommand)]
370
        cmd: BookmarkCmd,
371
    },
372
    /// Union another bookmark's heads into the current one (no merge change):
373
    /// a bookmark here, or a remote's (`origin/develop`) as last fetched
374
    Merge {
375
        /// The bookmark whose heads to add
376
        bookmark: String,
377
    },
378
    /// Sign in to a hub once, for every repository on it
379
    Auth {
380
        #[command(subcommand)]
381
        cmd: AuthCmd,
382
    },
383
    /// Subrepositories: nested repositories pinned to a state
384
    Submodule {
385
        #[command(subcommand)]
386
        cmd: SubmoduleCmd,
387
    },
388
    /// Witness hubs' transparency logs: cosign each checkpoint that extends
389
    /// the last one cosigned (spec §14.8)
390
    Witness {
391
        #[command(subcommand)]
392
        cmd: WitnessCmd,
393
    },
394
    /// Hubs' transparency logs: check that a hub shows everyone the same
395
    /// history (spec §14.8)
396
    Tlog {
397
        #[command(subcommand)]
398
        cmd: TlogCmd,
399
    },
400
    /// Execution receipts: signed records of what a runner ran on a state
401
    Receipt {
402
        #[command(subcommand)]
403
        cmd: ReceiptCmd,
404
    },
405
    /// Tags: immutable named states
406
    Tag {
407
        #[command(subcommand)]
408
        cmd: TagCmd,
409
    },
410
    /// Manage remotes
411
    Remote {
412
        #[command(subcommand)]
413
        cmd: RemoteCmd,
414
    },
415
    /// Fetch every bookmark of a remote into its tracking references
416
    Fetch {
417
        /// Remote name (default: origin)
418
        remote: Option<String>,
419
        /// Machine-readable output: one JSON document on stdout
420
        #[arg(long)]
421
        json: bool,
422
    },
423
    /// Fetch, then union the remote bookmark into the local one (no merge change)
424
    Pull {
425
        /// Remote name (default: origin)
426
        remote: Option<String>,
427
        /// Machine-readable output: one JSON document on stdout
428
        #[arg(long)]
429
        json: bool,
430
    },
431
    /// Push the current bookmark to a remote
432
    Push {
433
        /// Remote name (default: origin)
434
        remote: Option<String>,
435
        /// Allow dropping heads the remote has
436
        #[arg(long)]
437
        force: bool,
438
        /// Push this bookmark instead of the workspace's current one
439
        #[arg(short = 'b', long)]
440
        bookmark: Option<String>,
441
        /// Delete this bookmark on the remote (never its default bookmark);
442
        /// the local bookmark is kept
443
        #[arg(long, value_name = "NAME", conflicts_with_all = ["bookmark", "force"])]
444
        delete: Option<String>,
445
        /// Machine-readable output: one JSON document on stdout
446
        #[arg(long)]
447
        json: bool,
448
    },
449
    /// Serve repositories under ROOT over HTTPS (with --tls-cert/--tls-key) or plain HTTP
450
    Serve {
451
        /// Directory with one repository per subdirectory
452
        #[arg(long, default_value = ".")]
453
        root: PathBuf,
454
        /// Address and port to listen on
455
        #[arg(long, default_value = "127.0.0.1:8890")]
456
        bind: String,
457
        /// Bearer token allowed to push (repeatable); none means open
458
        #[arg(long = "token")]
459
        tokens: Vec<String>,
460
        /// PEM certificate chain; enables HTTPS together with --tls-key
461
        #[arg(long, requires = "tls_key")]
462
        tls_cert: Option<PathBuf>,
463
        /// PEM private key
464
        #[arg(long, requires = "tls_cert")]
465
        tls_key: Option<PathBuf>,
466
    },
467
    /// Manage the signing identity
468
    Identity {
469
        #[command(subcommand)]
470
        cmd: IdentityCmd,
471
    },
472
    /// Seal changes with your key: named ones, or every change on the current bookmark you can authenticate but have not
473
    Seal {
474
        /// Changes to seal (default: every change on the bookmark you can authenticate and have not sealed)
475
        changes: Vec<String>,
476
        /// Seal every change of a hub proposal and push the seal (your approval)
477
        #[arg(long, conflicts_with = "changes")]
478
        proposal: Option<String>,
479
        /// Approve a job of a hub run that waits for a sealed approval: `--flow https://hub/OWNER/NAME/flow/N --job apply`
480
        #[arg(long, conflicts_with_all = ["changes", "proposal"], requires = "job")]
481
        flow: Option<String>,
482
        /// The job to approve, with --flow
483
        #[arg(long, requires = "flow")]
484
        job: Option<String>,
485
        /// Reject the job instead of approving it, with --flow
486
        #[arg(long, requires = "flow")]
487
        reject: bool,
488
        /// Machine-readable output: one JSON document on stdout
489
        #[arg(long)]
490
        json: bool,
491
    },
492
    /// Hub proposals: show one, or land it from this client
493
    Proposal {
494
        #[command(subcommand)]
495
        cmd: ProposalCmd,
496
    },
497
    /// Verify the signatures on a change (default: every change in the log)
498
    Verify {
499
        /// The change to verify (default: every change in the log)
500
        change: Option<String>,
501
        /// Verify every change a revset selects: `release..main & unsigned()`
502
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
503
        revset: Option<String>,
504
        /// Machine-readable output: one JSON document on stdout
505
        #[arg(long)]
506
        json: bool,
507
    },
508
    /// Git interoperability
509
    Git {
510
        #[command(subcommand)]
511
        cmd: GitCmd,
512
    },
513
    /// Manage the trust policy (who may update which bookmarks)
514
    Policy {
515
        #[command(subcommand)]
516
        cmd: PolicyCmd,
517
    },
518
    /// 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)
519
    Config {
520
        /// The key, such as author.name or remote.origin.token
521
        key: String,
522
        /// The value to set (none with --unset); `-` reads it from standard input, out of the shell's history
523
        #[arg(required_unless_present = "unset")]
524
        value: Option<String>,
525
        /// Write to the user file (~/.config/oxy/config.toml) instead of this repository
526
        #[arg(long)]
527
        user: bool,
528
        /// Remove the key from this repository's file (or the user file with --user)
529
        #[arg(long)]
530
        unset: bool,
531
    },
532
}
533
534
#[derive(Subcommand)]
535
enum OpCmd {
536
    /// List operations, newest first, with what each changed
537
    Log {
538
        /// Show only the latest N (snapshots folded together count as one)
539
        #[arg(short = 'n', long)]
540
        limit: Option<usize>,
541
        /// Machine-readable output: one JSON document on stdout
542
        #[arg(long)]
543
        json: bool,
544
    },
545
    /// Go back to the bookmarks and working copy as they were after OP (recorded as a new operation, so it can be undone)
546
    Restore {
547
        /// The operation: an ID prefix from oxy op log, @ or @-
548
        op: String,
549
        /// Throw away uncommitted working-copy changes
550
        #[arg(long)]
551
        discard: bool,
552
    },
553
    /// Undo OP alone, keeping every operation after it: the bookmarks it moved go back
554
    Revert {
555
        /// The operation: an ID prefix from oxy op log
556
        op: String,
557
    },
558
}
559
560
#[derive(Subcommand)]
561
enum WorkspaceCmd {
562
    /// Create a workspace at PATH checked out on CHANGE... (default: the bookmark heads)
563
    Add {
564
        /// Directory for the new workspace (must be empty or absent)
565
        path: PathBuf,
566
        /// Changes whose state to check out there
567
        changes: Vec<String>,
568
    },
569
    /// List workspaces and their working-copy changes
570
    List {
571
        /// Machine-readable output: one JSON document on stdout
572
        #[arg(long)]
573
        json: bool,
574
    },
575
    /// Stop tracking a workspace (by id prefix or path); its files stay
576
    Forget {
577
        /// Workspace id prefix or path
578
        workspace: String,
579
    },
580
}
581
582
#[derive(Subcommand)]
583
enum BisectCmd {
584
    /// Begin; remembers where the working copy was
585
    Start,
586
    /// Mark CHANGE... (or the state under test) as good
587
    Good {
588
        /// Changes known to be good (default: the state under test)
589
        changes: Vec<String>,
590
    },
591
    /// Mark CHANGE... (or the state under test) as bad
592
    Bad {
593
        /// Changes known to be bad (default: the state under test)
594
        changes: Vec<String>,
595
    },
596
    /// The state under test cannot be tested; try another
597
    Skip,
598
    /// Run a command for each step: exit 0 good, 125 skip, else bad
599
    Run {
600
        /// Command and arguments to run at each step
601
        #[arg(required = true, trailing_var_arg = true)]
602
        command: Vec<String>,
603
    },
604
    /// Where the search stands
605
    Status {
606
        /// Machine-readable output: one JSON document on stdout
607
        #[arg(long)]
608
        json: bool,
609
    },
610
    /// Restore the working copy and forget the search
611
    Reset,
612
}
613
614
#[derive(Subcommand)]
615
enum BookmarkCmd {
616
    /// Create a bookmark at CHANGE... (default: the working copy's base)
617
    Create {
618
        /// Name of the new bookmark
619
        name: String,
620
        /// Its heads (default: the working copy's base). A state is its
621
        /// heads and what they depend on: a change alone may leave out
622
        /// earlier changes of the current state, which is refused unless
623
        /// --upto or --only says which is meant
624
        changes: Vec<String>,
625
        /// Everything of the current state up to CHANGE..., as a Git
626
        /// branch at a commit would hold
627
        #[arg(long, conflicts_with = "only")]
628
        upto: bool,
629
        /// Just CHANGE... and what they depend on. Other changes to the
630
        /// same files are left out, so a file can come out partly edited;
631
        /// to add one change to a bookmark's work, give the bookmark's
632
        /// heads with it instead: `bookmark set NAME <its heads> CHANGE`
633
        #[arg(long)]
634
        only: bool,
635
    },
636
    /// Point an existing bookmark at CHANGE...
637
    Set {
638
        /// The bookmark to move
639
        name: String,
640
        /// Its new heads. A change alone may leave out changes the
641
        /// bookmark now holds that were recorded before it, which is
642
        /// refused unless --upto or --only says which is meant
643
        changes: Vec<String>,
644
        /// Everything the bookmark holds up to CHANGE..., as a Git branch
645
        /// moved to a commit would hold
646
        #[arg(long, conflicts_with = "only")]
647
        upto: bool,
648
        /// Just CHANGE... and what they depend on. Other changes to the
649
        /// same files are left out, so a file can come out partly edited;
650
        /// to add one change to a bookmark's work, give the bookmark's
651
        /// heads with it instead: `bookmark set NAME <its heads> CHANGE`
652
        #[arg(long)]
653
        only: bool,
654
    },
655
    /// Remove a bookmark; its changes stay
656
    Delete {
657
        /// The bookmark to remove
658
        name: String,
659
    },
660
    /// List bookmarks with their heads and difference from origin
661
    List {
662
        /// Also list remotes' bookmarks that have no local bookmark
663
        #[arg(long, short)]
664
        all: bool,
665
        /// Each head of every bookmark, as `bookmark show` prints them
666
        #[arg(long, short)]
667
        verbose: bool,
668
        /// Machine-readable output: one JSON document on stdout
669
        #[arg(long)]
670
        json: bool,
671
    },
672
    /// A bookmark's heads: each change nothing else on it depends on,
673
    /// newest first. A bookmark name is also a revset for its heads
674
    /// (`oxy log -r NAME`, or `bookmark(NAME)` to mean only the bookmark)
675
    Show {
676
        /// The bookmark, or REMOTE/NAME (default: the current one)
677
        name: Option<String>,
678
        /// Machine-readable output: one JSON document on stdout
679
        #[arg(long)]
680
        json: bool,
681
    },
682
    /// Make NAME this workspace's bookmark and check it out. Uncommitted work stops it; --carry takes the work along, --discard drops it
683
    Switch {
684
        /// The bookmark to work on; one only a remote has (NAME or REMOTE/NAME) is created from it
685
        name: String,
686
        /// Throw away uncommitted working-copy changes
687
        #[arg(long)]
688
        discard: bool,
689
        /// Take uncommitted changes along; refused when NAME has other
690
        /// versions of the files they touch
691
        #[arg(long, conflicts_with = "discard")]
692
        carry: bool,
693
    },
694
}
695
696
#[derive(Subcommand)]
697
enum WitnessCmd {
698
    /// Serve a witness (C2SP tlog-witness: POST /add-checkpoint), signing
699
    /// with this oxy home's key (author.key)
700
    Serve {
701
        /// The witness's name in cosignatures: a host name
702
        #[arg(long)]
703
        name: String,
704
        /// A log to witness, as ORIGIN=FILE: its origin (HOST/log) and its
705
        /// key's identity file (a hub's /.well-known/oxyhub-key); repeatable
706
        #[arg(long = "log", required = true)]
707
        logs: Vec<String>,
708
        /// Where to keep what it cosigned
709
        #[arg(long, default_value = "witness-state")]
710
        state: PathBuf,
711
        /// Address and port to listen on
712
        #[arg(long, default_value = "127.0.0.1:8891")]
713
        bind: String,
714
        /// PEM certificate chain; enables HTTPS together with --tls-key
715
        #[arg(long, requires = "tls_key")]
716
        tls_cert: Option<PathBuf>,
717
        /// PEM private key for --tls-cert
718
        #[arg(long, requires = "tls_cert")]
719
        tls_key: Option<PathBuf>,
720
    },
721
}
722
723
#[derive(Subcommand)]
724
enum TlogCmd {
725
    /// Check a hub's whole log: its checkpoint against the log key and the
726
    /// last checkpoint seen, and every entry against the root it signed;
727
    /// then list this repository's entries (or a key's, or all)
728
    Verify {
729
        /// The hub, as https://oxygenhub.io (default: this checkout's remote)
730
        hub: Option<String>,
731
        /// List the entries a key signed (a KeyId) instead
732
        #[arg(long, conflicts_with = "all")]
733
        key: Option<String>,
734
        /// List every entry
735
        #[arg(long)]
736
        all: bool,
737
        /// Machine-readable output
738
        #[arg(long)]
739
        json: bool,
740
    },
741
}
742
743
#[derive(Subcommand)]
744
enum AuthCmd {
745
    /// Sign in to HUB in the browser (device sign-in) and keep the token for
746
    /// every repository there
747
    Login {
748
        /// The hub, as https://oxygenhub.io or oxygenhub.io (default: this checkout's origin)
749
        hub: Option<String>,
750
        /// Read a token from standard input instead (for CI and scripts)
751
        #[arg(long)]
752
        with_token: bool,
753
        /// PEM file of extra roots to trust (a hub with a self-signed certificate)
754
        #[arg(long)]
755
        ca: Option<PathBuf>,
756
    },
757
    /// List the hubs you are signed in to, checking each token with its hub
758
    Status,
759
    /// Forget HUB's token and revoke it on the hub
760
    Logout {
761
        /// The hub (default: this checkout's origin, or the only one)
762
        hub: Option<String>,
763
    },
764
    /// Keep an agent grant token (from `oh agent grant`) for keyless
765
    /// signing: with `author.signer = keyless`, commits and pushes are
766
    /// signed by fresh keys the hub certifies, in the grantor's name
767
    /// (the token is read from standard input, so it stays out of the
768
    /// shell's history)
769
    Grant {
770
        /// The hub (default: this checkout's origin)
771
        hub: Option<String>,
772
    },
773
}
774
775
#[derive(Subcommand)]
776
enum SubmoduleCmd {
777
    /// Clone URL (Oxygen or Git) into PATH and register it in .oxymodules
778
    Add {
779
        /// URL or path of the Oxygen or Git repository
780
        url: String,
781
        /// Where to put it, relative to the repository root
782
        path: String,
783
        /// Bookmark (Oxygen) or branch (Git) to check out and track
784
        #[arg(long)]
785
        bookmark: Option<String>,
786
    },
787
    /// Bring nested repositories to their pins
788
    Update {
789
        /// Clone nested repositories that are absent
790
        #[arg(long)]
791
        init: bool,
792
        /// Subrepos to update (default: all)
793
        paths: Vec<String>,
794
    },
795
    /// List subrepos with their pins and on-disk state
796
    Status {
797
        /// Machine-readable output: one JSON document on stdout
798
        #[arg(long)]
799
        json: bool,
800
    },
801
    /// Unregister PATH; the directory stays, the node goes with the next commit
802
    Remove {
803
        /// The subrepo to unregister
804
        path: String,
805
    },
806
}
807
808
#[derive(Subcommand)]
809
enum ReceiptCmd {
810
    /// The receipts kept for a state (default: the bookmark heads)
811
    List {
812
        /// Change, bookmark or tag whose state to look at
813
        rev: Option<String>,
814
        /// Machine-readable output: one JSON document on stdout
815
        #[arg(long)]
816
        json: bool,
817
    },
818
    /// One receipt in full, and whether its signature verifies
819
    Show {
820
        /// The receipt (a prefix of its hash, as `list` shows it)
821
        receipt: String,
822
        /// Change, bookmark or tag whose state holds it
823
        #[arg(long)]
824
        rev: Option<String>,
825
        /// Machine-readable output: one JSON document on stdout
826
        #[arg(long)]
827
        json: bool,
828
    },
829
    /// Write a signed receipt to FILE
830
    Export {
831
        /// The receipt (a prefix of its hash, as `list` shows it)
832
        receipt: String,
833
        /// Where to write it
834
        file: String,
835
        /// Change, bookmark or tag whose state holds it
836
        #[arg(long)]
837
        rev: Option<String>,
838
        /// `oxygen`: the runner's signed receipt, as `verify` and `import`
839
        /// read it. `slsa`: SLSA provenance in a DSSE envelope, signed with
840
        /// your key, for in-toto and cosign (`oxy identity export --pem`
841
        /// gives the key they check it with)
842
        #[arg(long, default_value = "oxygen", value_parser = ["oxygen", "slsa"])]
843
        format: String,
844
    },
845
    /// Check a signed receipt in FILE without keeping it
846
    Verify {
847
        /// A signed receipt, as a runner or `export` writes it
848
        file: String,
849
        /// Machine-readable output: one JSON document on stdout
850
        #[arg(long)]
851
        json: bool,
852
    },
853
    /// Verify a signed receipt in FILE and keep it with its state
854
    Import {
855
        /// A signed receipt, as a runner or `export` writes it
856
        file: String,
857
    },
858
}
859
860
#[derive(Subcommand)]
861
enum TagCmd {
862
    /// Tag the state of CHANGE... (default: the bookmark heads)
863
    Create {
864
        /// Name of the tag; tags never move
865
        name: String,
866
        /// Changes whose state to tag (default: the bookmark heads)
867
        changes: Vec<String>,
868
        /// A message recorded with the tag
869
        #[arg(short, long, default_value = "")]
870
        message: String,
871
    },
872
    /// List tags and the states they name
873
    List {
874
        /// Machine-readable output: one JSON document on stdout
875
        #[arg(long)]
876
        json: bool,
877
    },
878
}
879
880
#[derive(Subcommand)]
881
enum RemoteCmd {
882
    /// Add a remote
883
    Add {
884
        /// Name to refer to the remote by, such as origin
885
        name: String,
886
        /// 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
887
        url: String,
888
        /// For an s3:// store: the AWS profile to use (default: AWS_PROFILE, else "default")
889
        #[arg(long)]
890
        profile: Option<String>,
891
        /// For an s3:// store: its region (default: the environment, the profile, else asked of S3)
892
        #[arg(long)]
893
        region: Option<String>,
894
        /// For an s3://, gs:// or az:// store: another endpoint, such as an S3-compatible service
895
        #[arg(long)]
896
        endpoint: Option<String>,
897
        /// For a gs:// store: a service account key file, or application default credentials
898
        #[arg(long)]
899
        credentials: Option<String>,
900
    },
901
    /// Check a remote: that it is reachable with the credentials in hand, what it holds, and (for a store) that it behaves
902
    Check {
903
        /// The remote to check
904
        name: String,
905
    },
906
    /// Remove a remote
907
    Remove {
908
        /// The remote to remove
909
        name: String,
910
    },
911
    /// List remotes and their URLs
912
    List {
913
        /// Machine-readable output: one JSON document on stdout
914
        #[arg(long)]
915
        json: bool,
916
    },
917
}
918
919
#[derive(Subcommand)]
920
enum ProposalCmd {
921
    /// Show a proposal by its hub URL
922
    Show {
923
        /// The proposal's URL on the hub
924
        url: String,
925
        /// Machine-readable output: one JSON document on stdout
926
        #[arg(long)]
927
        json: bool,
928
    },
929
    /// Fetch the proposal's changes, set the target bookmark to the projected state, and push with your key
930
    Land {
931
        /// The proposal's URL on the hub
932
        url: String,
933
        /// Land even when the hub reports blockers
934
        #[arg(long)]
935
        force: bool,
936
    },
937
}
938
939
#[derive(Subcommand)]
940
enum IdentityCmd {
941
    /// Generate a composite Ed25519 + ML-DSA-65 key pair and make it your author identity
942
    Create {
943
        /// Your name (default: author.name)
944
        #[arg(long)]
945
        name: Option<String>,
946
        /// Your email (default: author.email)
947
        #[arg(long)]
948
        email: Option<String>,
949
        /// Record the author in this repository only, not in the user config
950
        #[arg(long)]
951
        local: bool,
952
        /// Expire the identity this many days from now
953
        #[arg(long)]
954
        expires: Option<u64>,
955
    },
956
    /// Show the configured identity
957
    Show,
958
    /// Write your identity object to a file, to hand to a policy holder
959
    Export {
960
        /// File to write (default: <key>.identity, or <key>.pem with --pem, in the current directory)
961
        path: Option<PathBuf>,
962
        /// Write the Ed25519 public key as PEM instead, as cosign's --key and
963
        /// other DSSE verifiers take it
964
        #[arg(long)]
965
        pem: bool,
966
    },
967
    /// Sign a host's challenge (hex, at least 16 bytes) to prove you hold your key; prints the signature as hex
968
    SignChallenge {
969
        /// The host's challenge, as hex
970
        challenge: String,
971
        /// Machine-readable output: one JSON document on stdout
972
        #[arg(long)]
973
        json: bool,
974
    },
975
    /// Move to a fresh key pair; the policy follows if it names your key
976
    Rotate,
977
    /// Re-issue your identity with a new expiry (in days from now; 0 = never)
978
    Renew {
979
        /// Days from now until it expires; 0 for never
980
        #[arg(long)]
981
        expires: u64,
982
    },
983
    /// Revoke a key: yours by default, or any key if you hold a policy root
984
    Revoke {
985
        /// KeyId prefix (default: your own key)
986
        key: Option<String>,
987
        /// Why, recorded in the revocation
988
        #[arg(long, default_value = "")]
989
        reason: String,
990
    },
991
    /// Keys allowed to sign or seal on your behalf
992
    Delegate {
993
        #[command(subcommand)]
994
        cmd: DelegateCmd,
995
    },
996
}
997
998
#[derive(Subcommand)]
999
enum DelegateCmd {
1000
    /// Add a delegate from an exported identity file
1001
    Add {
1002
        /// The delegates' exported identity files: one rotation for all of them
1003
        #[arg(required = true)]
1004
        identity_file: Vec<PathBuf>,
1005
        /// What it may do for you: changes, refs, seal (comma-separated) or all.
1006
        /// An agent gets `changes`; a host that lands for you needs `changes,refs`
1007
        #[arg(long, default_value = "changes")]
1008
        scope: String,
1009
        /// How long for: 30m, 8h, 7d, or a number of days (default: until removed)
1010
        #[arg(long)]
1011
        expires: Option<String>,
1012
    },
1013
    /// Remove a delegate by KeyId prefix
1014
    Remove {
1015
        /// KeyId prefix of the delegate
1016
        key: String,
1017
    },
1018
    /// List delegates
1019
    List,
1020
}
1021
1022
#[derive(Subcommand)]
1023
enum GitCmd {
1024
    /// Export the current bookmark to a Git repository (created bare if absent)
1025
    Export {
1026
        /// Git repository to write to (created bare if absent)
1027
        git_dir: PathBuf,
1028
        /// Git branch to write (default: the bookmark name)
1029
        #[arg(long)]
1030
        branch: Option<String>,
1031
    },
1032
    /// Fetch a branch from a Git remote (path or URL) into the current bookmark
1033
    Fetch {
1034
        /// Git remote: a path or URL
1035
        url: String,
1036
        /// Branch to fetch
1037
        #[arg(long, default_value = "main")]
1038
        branch: String,
1039
        /// Author your own commits (Git author email = your identity's) with your key; sets git.claim
1040
        #[arg(long)]
1041
        claim: bool,
1042
    },
1043
    /// Push the current bookmark to a branch of a Git remote (fetch first)
1044
    Push {
1045
        /// Git remote: a path or URL
1046
        url: String,
1047
        /// Branch to push to
1048
        #[arg(long, default_value = "main")]
1049
        branch: String,
1050
    },
1051
    /// 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
1052
    Recover,
1053
    /// Check this repository's import of a Git branch: every commit's tree must be reproduced exactly
1054
    Verify {
1055
        /// The Git repository the import came from
1056
        git_dir: PathBuf,
1057
        /// Branch that was imported
1058
        #[arg(long, default_value = "main")]
1059
        branch: String,
1060
        /// Rebuild only the last N commits (the others are followed, not checked)
1061
        #[arg(long, value_name = "N")]
1062
        last: Option<usize>,
1063
        /// Stop after N differences (0: check every commit whatever it finds)
1064
        #[arg(long, value_name = "N", default_value_t = 50)]
1065
        max_differences: usize,
1066
    },
1067
    /// Import a Git branch into a new Oxygen repository at DEST
1068
    Import {
1069
        /// Git repository to read
1070
        git_dir: PathBuf,
1071
        /// Directory for the new Oxygen repository
1072
        dest: PathBuf,
1073
        /// Branch to import
1074
        #[arg(long, default_value = "main")]
1075
        branch: String,
1076
        /// Author your own commits (Git author email = your identity's) with your key; sets git.claim
1077
        #[arg(long)]
1078
        claim: bool,
1079
    },
1080
}
1081
1082
#[derive(Subcommand)]
1083
enum PolicyCmd {
1084
    /// Create the initial policy with your identity as the only root
1085
    Init,
1086
    /// Show the current policy
1087
    Show {
1088
        /// Machine-readable output: one JSON document on stdout
1089
        #[arg(long)]
1090
        json: bool,
1091
    },
1092
    /// Allow an identity (from `oxy identity export`) to update bookmarks
1093
    Grant {
1094
        /// The identity to grant, exported with `oxy identity export`
1095
        identity_file: PathBuf,
1096
        /// Reference pattern the grant applies to (default: every bookmark)
1097
        #[arg(long)]
1098
        pattern: Option<String>,
1099
        /// Where to write the proposal when more root signatures are needed
1100
        #[arg(long)]
1101
        out: Option<PathBuf>,
1102
    },
1103
    /// Allow holders of an issuer's certificates for SUBJECT to sign (keyless)
1104
    GrantSubject {
1105
        /// Who: `repo:OWNER/NAME:bookmark:main`, `agent:NAME@ACCOUNT`; `*` matches any run of characters
1106
        subject: String,
1107
        /// The issuer's identity file, e.g. a hub's /.well-known/oxyhub-key
1108
        #[arg(long)]
1109
        issuer: PathBuf,
1110
        /// What its keys may sign: changes, refs, seal
1111
        #[arg(long, default_value = "changes,refs")]
1112
        scope: String,
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
    /// Revoke a key (KeyId prefix of an identity in the policy)
1121
    Revoke {
1122
        /// KeyId prefix of the identity
1123
        key: String,
1124
        /// Where to write the proposal when more root signatures are needed
1125
        #[arg(long)]
1126
        out: Option<PathBuf>,
1127
    },
1128
    /// Manage root keys and the signature threshold for policy updates
1129
    Root {
1130
        #[command(subcommand)]
1131
        cmd: RootCmd,
1132
    },
1133
    /// Add your root signature to a proposal file; applies it once the threshold is met
1134
    Sign {
1135
        /// The proposal file to sign
1136
        proposal: PathBuf,
1137
        /// Where to write the proposal if it still needs signatures (default: in place)
1138
        #[arg(long)]
1139
        out: Option<PathBuf>,
1140
    },
1141
}
1142
1143
#[derive(Subcommand)]
1144
enum RootCmd {
1145
    /// Make an exported identity a root key
1146
    Add {
1147
        /// The identity to make a root, exported with `oxy identity export`
1148
        identity_file: PathBuf,
1149
        /// Where to write the proposal when more root signatures are needed
1150
        #[arg(long)]
1151
        out: Option<PathBuf>,
1152
    },
1153
    /// Remove a root key by KeyId prefix
1154
    Remove {
1155
        /// KeyId prefix of the root key
1156
        key: String,
1157
        /// Where to write the proposal when more root signatures are needed
1158
        #[arg(long)]
1159
        out: Option<PathBuf>,
1160
    },
1161
    /// Require this many root signatures on policy updates
1162
    Threshold {
1163
        /// Number of root signatures
1164
        n: u32,
1165
        /// Where to write the proposal when more root signatures are needed
1166
        #[arg(long)]
1167
        out: Option<PathBuf>,
1168
    },
1169
}
1170
1171
/// Open the repository containing the current directory.
1172122×
fn open() -> Result<Repo> {
1173122×
    let repo = Repo::open(&std::env::current_dir()?).context("opening repository")?;
1174122×
    match AT_OP.get().and_then(|o| o.as_deref()) {
11750×
        Some(op) => Ok(repo.at_op(op)?),
1176122×
        None => Ok(repo),
1177
    }
1178122×
}
1179
1180
/// `oxy man`: every page into `dir`, or the top-level page on stdout.
11812×
fn man(dir: Option<PathBuf>) -> Result<i32> {
1182
    use clap::CommandFactory;
11832×
    let cmd = Cli::command();
11842×
    match dir {
11851×
        Some(dir) => {
11861×
            std::fs::create_dir_all(&dir)?;
11871×
            clap_mangen::generate_to(cmd, &dir)?;
11881×
            let pages = std::fs::read_dir(&dir)?
1189126×
                .filter(|e| {
1190126×
                    e.as_ref()
1191126×
                        .is_ok_and(|e| e.path().extension().is_some_and(|x| x == "1"))
1192126×
                })
11931×
                .count();
11941×
            println!(
1195
                "{}",
11961×
                ui::done(format!("Wrote {pages} man pages to {}", dir.display()))
1197
            );
1198
        }
11991×
        None => clap_mangen::Man::new(cmd).render(&mut std::io::stdout())?,
1200
    }
12012×
    Ok(0)
12022×
}
1203
1204
/// Parse arguments and run; returns the process exit code.
1205152×
pub fn run() -> Result<i32> {
1206
    // The cloud stores (s3://, gs://, az://) for remotes kept on them.
1207152×
    oxy_strata::register();
1208152×
    let cli = Cli::parse();
1209152×
    ui::init(cli.plain);
1210152×
    AT_OP.set(cli.at_op.clone()).ok();
12110×
    match cli.cmd {
12124×
        Cmd::Completions { shell } => {
1213
            use clap::CommandFactory;
12144×
            clap_complete::generate(shell, &mut Cli::command(), "oxy", &mut std::io::stdout());
12154×
            Ok(0)
1216
        }
12172×
        Cmd::Man { dir } => man(dir),
121814×
        Cmd::Init { path, bare, store } => workspace::init(path, bare, store.as_deref()),
12198×
        Cmd::Status { json } => workspace::status(json),
1220
        Cmd::Prompt {
12210×
            format,
12220×
            glyphs,
12230×
            color,
12240×
        } => workspace::prompt(&format, glyphs, color.as_deref()),
1225
        Cmd::Commit {
122626×
            message,
122726×
            file,
122826×
            depends_on,
122926×
            paths,
123026×
            interactive,
123126×
            hunks,
1232
        } => {
123326×
            let message = match (message, file) {
123425×
                (Some(m), _) => m,
12351×
                (None, Some(f)) if f.as_os_str() == "-" => {
12360×
                    let mut s = String::new();
12370×
                    std::io::Read::read_to_string(&mut std::io::stdin(), &mut s)?;
12380×
                    s
1239
                }
12401×
                (None, Some(f)) => std::fs::read_to_string(&f).map_err(|e| {
12410×
                    anyhow::anyhow!("reading the message from {}: {e}", f.display())
12420×
                })?,
12430×
                (None, None) => anyhow::bail!("a commit message is required (-m or -F)"),
1244
            };
124526×
            workspace::commit(&message, &depends_on, &paths, interactive, &hunks)
1246
        }
12472×
        Cmd::Cat { path, change } => workspace::cat(&path, change.as_deref()),
12481×
        Cmd::Root { json } => workspace::root(json),
12491×
        Cmd::Version { json } => workspace::version(json),
12502×
        Cmd::Discard { paths, hunks } => workspace::discard(&paths, &hunks),
12512×
        Cmd::Hunks { json } => workspace::hunks(json),
12520×
        Cmd::Squash { change, into } => workspace::squash(&change, &into),
1253
        Cmd::Rebase {
12540×
            change,
12550×
            onto,
12560×
            into_working_copy,
12570×
        } => workspace::rebase(&change, &onto, into_working_copy),
12580×
        Cmd::Blame { path, json } => workspace::blame(&path, json),
12591×
        Cmd::Bisect { cmd } => match cmd {
12600×
            BisectCmd::Start => workspace::bisect_start(),
12610×
            BisectCmd::Good { changes } => workspace::bisect_mark(Some(true), &changes),
12620×
            BisectCmd::Bad { changes } => workspace::bisect_mark(Some(false), &changes),
12630×
            BisectCmd::Skip => workspace::bisect_mark(None, &[]),
12640×
            BisectCmd::Run { command } => workspace::bisect_run(&command),
12651×
            BisectCmd::Status { json } => workspace::bisect_status(json),
12660×
            BisectCmd::Reset => workspace::bisect_reset(),
1267
        },
1268
        Cmd::Log {
12698×
            revset,
12708×
            limit,
12718×
            verbose,
12728×
            path,
12738×
            lines,
12748×
            json,
12758×
        } => workspace::log(
12768×
            revset.as_deref(),
12778×
            limit,
12788×
            verbose,
12798×
            path.as_deref(),
12808×
            lines.as_deref(),
12818×
            json,
1282
        ),
12831×
        Cmd::Diff { change, json } => workspace::diff(change.as_deref(), json),
1284
        Cmd::Describe {
12854×
            message,
12864×
            change,
12874×
            json,
12884×
        } => match message {
12890×
            Some(m) => workspace::describe(&m, change.as_deref()),
12904×
            None if change.is_some() => {
12910×
                anyhow::bail!(
1292
                    "naming works on the working copy; to change a head's message pass -m"
1293
                )
1294
            }
12954×
            None => workspace::describe_name(json),
1296
        },
12970×
        Cmd::Amend { message, into } => workspace::amend(message.as_deref(), into.as_deref()),
12980×
        Cmd::Split { change, paths } => workspace::split(&change, &paths),
1299
        Cmd::Abandon {
13000×
            change,
13010×
            revset,
13020×
            yes,
13030×
        } => workspace::abandon(change.as_deref(), revset.as_deref(), yes),
1304
        Cmd::Show {
13053×
            change,
13063×
            revset,
13073×
            stat,
13083×
            json,
13093×
        } => workspace::show(change.as_deref(), revset.as_deref(), stat, json),
1310
        Cmd::Checkout {
13110×
            changes,
13120×
            discard,
13130×
            carry,
13140×
        } => workspace::checkout(&changes, discard, carry),
13151×
        Cmd::Resolve { json } => workspace::resolve(json),
13160×
        Cmd::Undo => workspace::undo(),
1317
        Cmd::Gc {
13182×
            now,
13192×
            expire_snapshots,
13202×
            remote,
13212×
        } => match remote {
13222×
            Some(name) => workspace::gc_remote(&name, now),
13230×
            None => workspace::gc(now, expire_snapshots),
1324
        },
13250×
        Cmd::Fsck { json } => workspace::fsck(json),
13260×
        Cmd::Doctor { offline, json } => workspace::doctor(offline, json),
13270×
        Cmd::Checkpoint => workspace::checkpoint(),
13281×
        Cmd::Op { cmd } => match cmd {
13291×
            OpCmd::Log { limit, json } => workspace::op_log(limit, json),
13300×
            OpCmd::Restore { op, discard } => workspace::op_restore(&op, discard),
13310×
            OpCmd::Revert { op } => workspace::op_revert(&op),
1332
        },
1333
        Cmd::Clone {
13345×
            url,
13355×
            dest,
13365×
            max_blob,
13375×
            sparse,
13385×
            depth,
13395×
            recursive,
13405×
        } => sync::clone(&url, dest, max_blob.as_deref(), &sparse, depth, recursive),
13410×
        Cmd::Deepen { depth, remote } => sync::deepen(&remote, depth),
13420×
        Cmd::Sparse { paths } => workspace::sparse(&paths),
13430×
        Cmd::Lock { path } => workspace::lock(&path),
13440×
        Cmd::Unlock { path } => workspace::unlock(&path),
13451×
        Cmd::Workspace { cmd } => match cmd {
13460×
            WorkspaceCmd::Add { path, changes } => workspace::workspace_add(&path, &changes),
13471×
            WorkspaceCmd::List { json } => workspace::workspace_list(json),
13480×
            WorkspaceCmd::Forget { workspace } => workspace::workspace_forget(&workspace),
1349
        },
135017×
        Cmd::Bookmark { cmd } => match cmd {
1351
            BookmarkCmd::Create {
13526×
                name,
13536×
                changes,
13546×
                upto,
13556×
                only,
13566×
            } => workspace::bookmark_create(&name, &changes, upto, only),
1357
            BookmarkCmd::Set {
13583×
                name,
13593×
                changes,
13603×
                upto,
13613×
                only,
13623×
            } => workspace::bookmark_set(&name, &changes, upto, only),
13630×
            BookmarkCmd::Delete { name } => workspace::bookmark_delete(&name),
13645×
            BookmarkCmd::List { all, verbose, json } => {
13655×
                workspace::bookmark_list(all, verbose, json)
1366
            }
13670×
            BookmarkCmd::Show { name, json } => workspace::bookmark_show(name.as_deref(), json),
1368
            BookmarkCmd::Switch {
13693×
                name,
13703×
                discard,
13713×
                carry,
13723×
            } => workspace::bookmark_switch(&name, discard, carry),
1373
        },
13740×
        Cmd::Merge { bookmark } => workspace::merge(&bookmark),
13750×
        Cmd::Auth { cmd } => match cmd {
1376
            AuthCmd::Login {
13770×
                hub,
13780×
                with_token,
13790×
                ca,
13800×
            } => auth::login(hub.as_deref(), with_token, ca),
13810×
            AuthCmd::Status => auth::status(),
13820×
            AuthCmd::Logout { hub } => auth::logout(hub.as_deref()),
13830×
            AuthCmd::Grant { hub } => auth::grant(hub.as_deref()),
1384
        },
13851×
        Cmd::Submodule { cmd } => match cmd {
1386
            SubmoduleCmd::Add {
13870×
                url,
13880×
                path,
13890×
                bookmark,
13900×
            } => sync::submodule_add(&url, &path, bookmark.as_deref()),
13910×
            SubmoduleCmd::Update { init, paths } => sync::submodule_update(init, &paths),
13921×
            SubmoduleCmd::Status { json } => sync::submodule_status(json),
13930×
            SubmoduleCmd::Remove { path } => sync::submodule_remove(&path),
1394
        },
1395
        Cmd::Witness {
1396
            cmd:
1397
                WitnessCmd::Serve {
13980×
                    name,
13990×
                    logs,
14000×
                    state,
14010×
                    bind,
14020×
                    tls_cert,
14030×
                    tls_key,
1404
                },
14050×
        } => tlog::witness_serve(&name, &logs, state, &bind, tls_cert.zip(tls_key)),
14060×
        Cmd::Tlog { cmd } => match cmd {
1407
            TlogCmd::Verify {
14080×
                hub,
14090×
                key,
14100×
                all,
14110×
                json,
14120×
            } => tlog::verify(hub.as_deref(), key.as_deref(), all, json),
1413
        },
141410×
        Cmd::Receipt { cmd } => match cmd {
14152×
            ReceiptCmd::List { rev, json } => receipt::list(rev.as_deref(), json),
1416
            ReceiptCmd::Show {
14171×
                receipt: r,
14181×
                rev,
14191×
                json,
14201×
            } => receipt::show(&r, rev.as_deref(), json),
1421
            ReceiptCmd::Export {
14223×
                receipt: r,
14233×
                file,
14243×
                rev,
14253×
                format,
14263×
            } => receipt::export(&r, &file, rev.as_deref(), &format),
14272×
            ReceiptCmd::Verify { file, json } => receipt::verify(&file, json),
14282×
            ReceiptCmd::Import { file } => receipt::import(&file),
1429
        },
14303×
        Cmd::Tag { cmd } => match cmd {
1431
            TagCmd::Create {
14322×
                name,
14332×
                changes,
14342×
                message,
14352×
            } => workspace::tag_create(&name, &changes, &message),
14361×
            TagCmd::List { json } => workspace::tag_list(json),
1437
        },
143810×
        Cmd::Remote { cmd } => match cmd {
1439
            RemoteCmd::Add {
14404×
                name,
14414×
                url,
14424×
                profile,
14434×
                region,
14444×
                endpoint,
14454×
                credentials,
14464×
            } => sync::remote_add(
14474×
                &name,
14484×
                &url,
14494×
                &[
14504×
                    ("profile", profile),
14514×
                    ("region", region),
14524×
                    ("endpoint", endpoint),
14534×
                    ("credentials", credentials),
14544×
                ],
1455
            ),
14563×
            RemoteCmd::Check { name } => sync::remote_check(&name),
14571×
            RemoteCmd::Remove { name } => sync::remote_remove(&name),
14582×
            RemoteCmd::List { json } => sync::remote_list(json),
1459
        },
14601×
        Cmd::Fetch { remote, json } => sync::fetch(remote.as_deref(), json),
14614×
        Cmd::Pull { remote, json } => sync::pull(remote.as_deref(), json),
1462
        Cmd::Push {
14637×
            remote,
14647×
            force,
14657×
            bookmark,
14667×
            delete,
14677×
            json,
14687×
        } => match delete {
14690×
            Some(name) => sync::push_delete(remote.as_deref(), &name, json),
14707×
            None => sync::push(remote.as_deref(), force, bookmark.as_deref(), json),
1471
        },
1472
        Cmd::Serve {
14730×
            root,
14740×
            bind,
14750×
            tokens,
14760×
            tls_cert,
14770×
            tls_key,
14780×
        } => sync::serve(root, &bind, tokens, tls_cert.zip(tls_key)),
14793×
        Cmd::Identity { cmd } => match cmd {
1480
            IdentityCmd::Create {
14812×
                name,
14822×
                email,
14832×
                local,
14842×
                expires,
14852×
            } => identity::create(name, email, local, expires),
14860×
            IdentityCmd::Show => identity::show(),
14871×
            IdentityCmd::Export { path, pem } => identity::export(path, pem),
14880×
            IdentityCmd::SignChallenge { challenge, json } => {
14890×
                identity::sign_challenge(&challenge, json)
1490
            }
14910×
            IdentityCmd::Rotate => identity::rotate(),
14920×
            IdentityCmd::Renew { expires } => identity::renew(expires),
14930×
            IdentityCmd::Revoke { key, reason } => identity::revoke(key.as_deref(), &reason),
14940×
            IdentityCmd::Delegate { cmd } => match cmd {
1495
                DelegateCmd::Add {
14960×
                    identity_file,
14970×
                    scope,
14980×
                    expires,
14990×
                } => identity::delegate_add(&identity_file, &scope, expires.as_deref()),
15000×
                DelegateCmd::Remove { key } => identity::delegate_remove(&key),
15010×
                DelegateCmd::List => identity::delegate_list(),
1502
            },
1503
        },
1504
        Cmd::Git {
15050×
            cmd: GitCmd::Export { git_dir, branch },
15060×
        } => sync::git_export(&git_dir, branch.as_deref()),
1507
        Cmd::Git {
15080×
            cmd: GitCmd::Fetch { url, branch, claim },
15090×
        } => sync::git_fetch(&url, &branch, claim),
1510
        Cmd::Git {
15110×
            cmd: GitCmd::Push { url, branch },
15120×
        } => sync::git_push(&url, &branch),
1513
        Cmd::Git {
1514
            cmd: GitCmd::Recover,
15150×
        } => sync::git_recover(),
1516
        Cmd::Git {
1517
            cmd:
1518
                GitCmd::Import {
15190×
                    git_dir,
15200×
                    dest,
15210×
                    branch,
15220×
                    claim,
1523
                },
15240×
        } => sync::git_import(&git_dir, &dest, &branch, claim),
1525
        Cmd::Git {
1526
            cmd:
1527
                GitCmd::Verify {
15280×
                    git_dir,
15290×
                    branch,
15300×
                    last,
15310×
                    max_differences,
1532
                },
15330×
        } => sync::git_verify(&git_dir, &branch, last, max_differences),
15345×
        Cmd::Policy { cmd } => match cmd {
15351×
            PolicyCmd::Init => identity::policy_init(),
15363×
            PolicyCmd::Show { json } => identity::policy_show(json),
1537
            PolicyCmd::Grant {
15380×
                identity_file,
15390×
                pattern,
15400×
                out,
15410×
            } => identity::policy_grant(&identity_file, pattern.as_deref(), out),
1542
            PolicyCmd::GrantSubject {
15431×
                subject,
15441×
                issuer,
15451×
                scope,
15461×
                pattern,
15471×
                out,
15481×
            } => identity::policy_grant_subject(&subject, &issuer, &scope, pattern.as_deref(), out),
15490×
            PolicyCmd::Revoke { key, out } => identity::policy_revoke(&key, out),
15500×
            PolicyCmd::Root { cmd } => match cmd {
15510×
                RootCmd::Add { identity_file, out } => {
15520×
                    identity::policy_root_add(&identity_file, out)
1553
                }
15540×
                RootCmd::Remove { key, out } => identity::policy_root_remove(&key, out),
15550×
                RootCmd::Threshold { n, out } => identity::policy_threshold(n, out),
1556
            },
15570×
            PolicyCmd::Sign { proposal, out } => identity::policy_sign(&proposal, out),
1558
        },
1559
        Cmd::Seal {
15600×
            flow: Some(url),
15610×
            job: Some(job),
15620×
            reject,
15630×
            json,
1564
            ..
15650×
        } => approve::seal(&url, &job, reject, json),
1566
        Cmd::Seal {
15670×
            changes,
15680×
            proposal: Some(url),
15690×
            json,
1570
            ..
15710×
        } if changes.is_empty() => proposal::seal(&url, json),
15720×
        Cmd::Seal { changes, json, .. } => identity::seal(&changes, json),
15730×
        Cmd::Proposal { cmd } => match cmd {
15740×
            ProposalCmd::Show { url, json } => proposal::show(&url, json),
15750×
            ProposalCmd::Land { url, force } => proposal::land(&url, force),
1576
        },
1577
        Cmd::Verify {
15781×
            change,
15791×
            revset,
15801×
            json,
15811×
        } => identity::verify(change.as_deref(), revset.as_deref(), json),
1582
        Cmd::Config {
15831×
            key,
15841×
            value,
15851×
            user,
15861×
            unset,
15871×
        } => identity::config(&key, value.as_deref().unwrap_or(""), user, unset),
1588
    }
1589152×
}
1590
1591
#[cfg(test)]
1592
mod help_tests {
1593
    use super::Cli;
1594
    use clap::CommandFactory;
1595
1596
    /// Every command and every argument explains itself, so `--help`,
1597
    /// completions and the man pages are complete.
1598
    #[test]
15991×
    fn every_command_and_argument_has_help() {
1600126×
        fn walk(cmd: &clap::Command, path: &str, missing: &mut Vec<String>) {
1601126×
            let here = format!("{path} {}", cmd.get_name()).trim().to_string();
1602126×
            if cmd.get_about().is_none() && !path.is_empty() {
16030×
                missing.push(format!("{here} (command)"));
1604126×
            }
1605232×
            for a in cmd.get_arguments() {
1606232×
                let id = a.get_id().as_str();
1607232×
                if id == "help" || id == "version" || (a.is_global_set() && !path.is_empty()) {
16080×
                    continue;
1609232×
                }
1610232×
                if a.get_help().is_none() && a.get_long_help().is_none() {
16110×
                    missing.push(format!("{here} {id}"));
1612232×
                }
1613
            }
1614126×
            for sub in cmd.get_subcommands() {
1615125×
                walk(sub, &here, missing);
1616125×
            }
1617126×
        }
16181×
        let mut missing = Vec::new();
16191×
        walk(&Cli::command(), "", &mut missing);
16201×
        assert!(
16211×
            missing.is_empty(),
1622
            "{} without help:\n{}",
16230×
            missing.len(),
16240×
            missing.join("\n")
1625
        );
16261×
    }
1627
}