OXYGENHUB

Coverage / src/cli/mod.rs 58.2%

209 of 359 lines run, 9 of 18 functions · run #363 on main · run missed

1
//! Command-line definitions and dispatch.
2
3
mod approve;
4
mod auth;
5
mod format;
6
mod identity;
7
mod json;
8
mod proposal;
9
mod receipt;
10
mod sync;
11
mod tlog;
12
pub mod ui;
13
mod workspace;
14
15
use anyhow::{Context, Result};
16
use clap::{Parser, Subcommand};
17
use oxy_core::repo::Repo;
18
use std::path::PathBuf;
19
20
#[derive(Parser)]
21
#[command(
22
    name = "oxy",
23
    version = env!("OXY_VERSION_LONG"),
24
    about = "Oxygen: breathing fresh air into version control"
25
)]
26
struct Cli {
27
    /// Plain output: no colour, no spinner (also implied by NO_COLOR or a non-terminal)
28
    #[arg(long, global = true)]
29
    plain: bool,
30
    /// Read the repository as it was after operation OP (an ID from oxy op log, @ or @-); commands that would change it are refused
31
    #[arg(long, global = true, value_name = "OP")]
32
    at_op: Option<String>,
33
    #[command(subcommand)]
34
    cmd: Cmd,
35
}
36
37
/// `--at-op`, for `open` to apply.
38
static AT_OP: std::sync::OnceLock<Option<String>> = std::sync::OnceLock::new();
39
40
#[derive(Subcommand)]
41
enum Cmd {
42
    /// Create a repository in PATH (default: current directory)
43
    Init {
44
        /// Directory to create the repository in (default: the current directory)
45
        path: Option<PathBuf>,
46
        /// No working copy: an object store and references only, for hosting
47
        #[arg(long)]
48
        bare: bool,
49
        /// Keep the objects and the operation log on this store
50
        /// (dir://PATH, s3://BUCKET/PREFIX, gs://…, az://…) instead of
51
        /// in .oxy, with a local cache in front (storage.cache, 2 GiB)
52
        #[arg(long, value_name = "URL")]
53
        store: Option<String>,
54
    },
55
    /// Clone a repository from a local path or an http(s) URL
56
    Clone {
57
        /// Local path or http(s) URL of the repository
58
        url: String,
59
        /// Directory to clone into (default: the last part of the URL)
60
        dest: Option<PathBuf>,
61
        /// Leave blobs larger than this (e.g. 1M) to be fetched on first read
62
        #[arg(long)]
63
        max_blob: Option<String>,
64
        /// Materialize only these paths (repeatable); implies lazy blobs
65
        #[arg(long = "sparse")]
66
        sparse: Vec<String>,
67
        /// Shallow clone: fetch only this many levels of history below the heads
68
        #[arg(long)]
69
        depth: Option<u32>,
70
        /// Clone the subrepos too (as oxy submodule update --init)
71
        #[arg(long)]
72
        recursive: bool,
73
    },
74
    /// Fetch more history below a shallow clone's boundary
75
    Deepen {
76
        /// Levels of history to add below the boundary
77
        #[arg(default_value_t = 10)]
78
        depth: u32,
79
        /// Remote to fetch the history from
80
        #[arg(long, default_value = "origin")]
81
        remote: String,
82
    },
83
    /// Show or set the sparse filter (paths to materialize); re-checks out the bookmark
84
    Sparse {
85
        /// Paths to materialize; none prints the current filter
86
        paths: Vec<String>,
87
    },
88
    /// Show the working copy: changed paths and conflicts
89
    Status {
90
        /// Machine-readable output: paths, and every conflict with its kind and contributing changes
91
        #[arg(long)]
92
        json: bool,
93
    },
94
    /// One-line summary for shell prompts; fast and records nothing
95
    Prompt {
96
        /// Placeholders: %b bookmark, %c change id, %h heads, %d dirty (*), %x conflict (!), %A/%D ahead/behind (+n/-n), %a/%B raw counts, %s state glyph, %U/%O ahead/behind arrows, %i icon
97
        #[arg(long, default_value = oxy_core::repo::DEFAULT_PROMPT_FORMAT)]
98
        format: String,
99
        /// Glyph format (%i %b %c %s%U%O) instead of the plain default
100
        #[arg(long)]
101
        glyphs: bool,
102
        /// Colour by state (cyan clean, yellow dirty, red conflicted): raw escapes, or guarded for a bash or zsh PS1
103
        #[arg(long, value_parser = ["raw", "bash", "zsh"])]
104
        color: Option<String>,
105
    },
106
    /// Record the working copy as a change on the current bookmark
107
    Commit {
108
        /// The change's message: a subject line, then optionally a blank line and a body
109
        #[arg(short, long, required_unless_present = "file", conflicts_with = "file")]
110
        message: Option<String>,
111
        /// Read the message from FILE (`-` for standard input)
112
        #[arg(short = 'F', long, value_name = "FILE")]
113
        file: Option<PathBuf>,
114
        /// Extra explicit dependencies (ChangeId prefix, #hash prefix)
115
        #[arg(long = "depends-on")]
116
        depends_on: Vec<String>,
117
        /// Commit only these paths; the rest stays as uncommitted work
118
        paths: Vec<String>,
119
        /// Choose hunks one by one
120
        #[arg(short, long)]
121
        interactive: bool,
122
        /// Commit these hunks (as `oxy hunks` numbers them), comma separated
123
        #[arg(long, value_delimiter = ',')]
124
        hunks: Vec<usize>,
125
    },
126
    /// Fold CHANGE into one of its dependencies (keeps that change's id)
127
    Squash {
128
        /// The change to fold (ChangeId prefix, #hash prefix)
129
        change: String,
130
        /// The dependency that absorbs it
131
        #[arg(long)]
132
        into: String,
133
    },
134
    /// Re-express CHANGE against another base state
135
    Rebase {
136
        /// The change to re-express (ChangeId prefix, #hash prefix)
137
        change: String,
138
        /// The changes, bookmark or tag whose state becomes the new base
139
        #[arg(long, required = true, num_args = 1..)]
140
        onto: Vec<String>,
141
        /// Where the rebase would be conflicted, merge the target into the
142
        /// current bookmark instead, leaving the conflict in the working
143
        /// copy to fix and commit
144
        #[arg(long)]
145
        into_working_copy: bool,
146
    },
147
    /// Show which change introduced each line of a file
148
    Blame {
149
        /// File to annotate, relative to the repository root
150
        path: String,
151
        /// Machine-readable output: one JSON document on stdout
152
        #[arg(long)]
153
        json: bool,
154
    },
155
    /// Find the change that introduced a regression
156
    Bisect {
157
        #[command(subcommand)]
158
        cmd: BisectCmd,
159
    },
160
    /// List changes reachable from the bookmark and the working copy
161
    Log {
162
        /// Show the changes a revset selects: `main` (a bookmark name means its
163
        /// heads; `bookmark(main)` only ever the bookmark), `main..feature &
164
        /// author(andy)`, `touches("src/**") & date(-7d..)` (see
165
        /// docs/revset_query_language.md)
166
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with_all = ["path", "lines"])]
167
        revset: Option<String>,
168
        /// Show at most this many changes
169
        #[arg(short = 'n', long)]
170
        limit: Option<usize>,
171
        /// Show full messages, dependencies, and signatures
172
        #[arg(short, long)]
173
        verbose: bool,
174
        /// Only changes touching this path (renames followed)
175
        #[arg(long)]
176
        path: Option<String>,
177
        /// Only changes that wrote or deleted lines START to END of PATH
178
        /// (numbered as in the working copy's base), or deleted lines from
179
        /// between them: the history of a function
180
        #[arg(short = 'L', value_name = "START,END:PATH", conflicts_with = "path")]
181
        lines: Option<String>,
182
        /// Machine-readable output: one JSON document on stdout
183
        #[arg(long)]
184
        json: bool,
185
    },
186
    /// Show what the working copy changes against its base
187
    Diff {
188
        /// A change instead of the working copy
189
        change: Option<String>,
190
        /// Machine-readable output: one JSON document on stdout
191
        #[arg(long)]
192
        json: bool,
193
    },
194
    /// Print a file as it is in a state (default: the working copy's base)
195
    Cat {
196
        /// File to print, relative to the repository root
197
        path: String,
198
        /// A bookmark or tag (its state), or a change: a change means its
199
        /// dependency closure, the change and what it depends on, so files
200
        /// only later changes touched are absent or at older versions
201
        #[arg(short = 'r', long)]
202
        change: Option<String>,
203
    },
204
    /// Print the repository root, workspace, and bookmark
205
    Root {
206
        /// Machine-readable output: one JSON document on stdout
207
        #[arg(long)]
208
        json: bool,
209
    },
210
    /// Print the version of oxy, its repository format, and protocol
211
    Version {
212
        /// Machine-readable output: one JSON document on stdout
213
        #[arg(long)]
214
        json: bool,
215
    },
216
    /// Restore paths to the working copy's base, or undo chosen hunks
217
    Discard {
218
        /// Paths to restore; none with --hunks, or everything with neither
219
        paths: Vec<String>,
220
        /// Hunk indices as `oxy hunks` numbers them, comma separated
221
        #[arg(long, value_delimiter = ',')]
222
        hunks: Vec<usize>,
223
    },
224
    /// List the working copy's hunks, numbered as commit --hunks expects
225
    Hunks {
226
        /// Machine-readable output: one JSON document on stdout
227
        #[arg(long)]
228
        json: bool,
229
    },
230
    /// With -m, change the message of a head; without, name the working
231
    /// copy for a build: its tag, or the nearest tag plus distance and
232
    /// change, or the bookmark and change, and -dirty
233
    Describe {
234
        /// The new message
235
        #[arg(short, long)]
236
        message: Option<String>,
237
        /// The head to describe (default: the one the working copy sits on)
238
        change: Option<String>,
239
        /// Machine-readable output (naming only)
240
        #[arg(long, conflicts_with = "message")]
241
        json: bool,
242
    },
243
    /// Fold the working copy into the head it sits on, or into CHANGE with --into
244
    Amend {
245
        /// Replace the message too
246
        #[arg(short, long)]
247
        message: Option<String>,
248
        /// Amend an older change; the edits must touch only lines it already knows
249
        #[arg(long, conflicts_with = "paths")]
250
        into: Option<String>,
251
        /// Fold in only these paths; the rest stays as uncommitted work
252
        paths: Vec<String>,
253
    },
254
    /// Split a head: the named paths become a separate first change
255
    Split {
256
        /// The head to split
257
        change: String,
258
        /// Paths whose edits become the first change
259
        paths: Vec<String>,
260
    },
261
    /// Drop a change from the bookmark; its content stays on disk as uncommitted work
262
    Abandon {
263
        /// The change to drop (ChangeId prefix, #hash prefix)
264
        #[arg(required_unless_present = "revset")]
265
        change: Option<String>,
266
        /// Drop every change a revset selects, newest first
267
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
268
        revset: Option<String>,
269
        /// Drop more than five changes without asking
270
        #[arg(long, short = 'y')]
271
        yes: bool,
272
    },
273
    /// Show one change (ChangeId prefix, #hash prefix, or @), or those a revset selects
274
    Show {
275
        /// ChangeId prefix, #hash prefix, or @ for the working copy
276
        #[arg(required_unless_present = "revset")]
277
        change: Option<String>,
278
        /// Show every change a revset selects
279
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
280
        revset: Option<String>,
281
        /// The files it touched with lines added and removed, instead of the diff
282
        #[arg(long)]
283
        stat: bool,
284
        /// Machine-readable output: one JSON document on stdout
285
        #[arg(long)]
286
        json: bool,
287
    },
288
    /// Move the working copy to the state formed by CHANGE... (default: the bookmark heads)
289
    Checkout {
290
        /// Changes whose state to check out (default: the bookmark heads)
291
        changes: Vec<String>,
292
        /// Throw away uncommitted working-copy changes
293
        #[arg(long)]
294
        discard: bool,
295
        /// Take uncommitted changes along; refused when the target has
296
        /// other versions of the files they touch
297
        #[arg(long, conflicts_with = "discard")]
298
        carry: bool,
299
    },
300
    /// Report which conflicts of the working copy's base are resolved by the current files
301
    Resolve {
302
        /// Machine-readable output: one JSON document on stdout
303
        #[arg(long)]
304
        json: bool,
305
    },
306
    /// Undo the last operation
307
    Undo,
308
    /// Write a checkpoint of the current bookmark's state now
309
    Checkpoint,
310
    /// Print a shell completion script: `oxy completions bash > ~/.local/share/bash-completion/completions/oxy`
311
    Completions {
312
        /// bash, zsh, fish, elvish or powershell
313
        shell: clap_complete::Shell,
314
    },
315
    /// Write man pages (oxy.1 and one per command) into DIR, or print oxy.1
316
    Man {
317
        /// Directory to write every page into, e.g. ~/.local/share/man/man1
318
        #[arg(long)]
319
        dir: Option<PathBuf>,
320
    },
321
    /// Check the identity, configuration and remotes, and say what to do about any problem
322
    Doctor {
323
        /// Do not contact the remotes
324
        #[arg(long)]
325
        offline: bool,
326
        /// Machine-readable output: one JSON document on stdout
327
        #[arg(long)]
328
        json: bool,
329
    },
330
    /// Check the repository's integrity: objects, operation log, references, signatures, checkpoints
331
    Fsck {
332
        /// Machine-readable output: one JSON document on stdout
333
        #[arg(long)]
334
        json: bool,
335
    },
336
    /// Prune unreachable objects older than the grace period and repack everything into one pack
337
    Gc {
338
        /// Ignore the grace period (core.gc-grace) and prune immediately
339
        #[arg(long)]
340
        now: bool,
341
        /// Keep no past working-copy snapshots, only each workspace's current one, so files only they held go (core.snapshot-retention, default 7 days)
342
        #[arg(long)]
343
        expire_snapshots: bool,
344
        /// 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)
345
        #[arg(long, value_name = "NAME")]
346
        remote: Option<String>,
347
    },
348
    /// List operations
349
    #[command(name = "op")]
350
    Op {
351
        #[command(subcommand)]
352
        cmd: OpCmd,
353
    },
354
    /// Take the advisory local lock on a lockable file, making it writable
355
    Lock {
356
        /// The lockable file
357
        path: String,
358
    },
359
    /// Release the local lock and make the file read-only again
360
    Unlock {
361
        /// The locked file
362
        path: String,
363
    },
364
    /// Workspaces: extra checkout directories sharing this repository
365
    Workspace {
366
        #[command(subcommand)]
367
        cmd: WorkspaceCmd,
368
    },
369
    /// Bookmarks: named states; each workspace works on one
370
    Bookmark {
371
        #[command(subcommand)]
372
        cmd: BookmarkCmd,
373
    },
374
    /// Union another bookmark's heads into the current one (no merge change):
375
    /// a bookmark here, or a remote's (`origin/develop`) as last fetched
376
    Merge {
377
        /// The bookmark whose heads to add
378
        bookmark: String,
379
    },
380
    /// Sign in to a hub once, for every repository on it
381
    Auth {
382
        #[command(subcommand)]
383
        cmd: AuthCmd,
384
    },
385
    /// Subrepositories: nested repositories pinned to a state
386
    Submodule {
387
        #[command(subcommand)]
388
        cmd: SubmoduleCmd,
389
    },
390
    /// Witness hubs' transparency logs: cosign each checkpoint that extends
391
    /// the last one cosigned (spec §14.8)
392
    Witness {
393
        #[command(subcommand)]
394
        cmd: WitnessCmd,
395
    },
396
    /// Hubs' transparency logs: check that a hub shows everyone the same
397
    /// history (spec §14.8)
398
    Tlog {
399
        #[command(subcommand)]
400
        cmd: TlogCmd,
401
    },
402
    /// Execution receipts: signed records of what a runner ran on a state
403
    Receipt {
404
        #[command(subcommand)]
405
        cmd: ReceiptCmd,
406
    },
407
    /// Tags: immutable named states
408
    Tag {
409
        #[command(subcommand)]
410
        cmd: TagCmd,
411
    },
412
    /// Manage remotes
413
    Remote {
414
        #[command(subcommand)]
415
        cmd: RemoteCmd,
416
    },
417
    /// Fetch every bookmark of a remote into its tracking references
418
    Fetch {
419
        /// Remote name (default: origin)
420
        remote: Option<String>,
421
        /// Machine-readable output: one JSON document on stdout
422
        #[arg(long)]
423
        json: bool,
424
    },
425
    /// Fetch, then union the remote bookmark into the local one (no merge change)
426
    Pull {
427
        /// Remote name (default: origin)
428
        remote: Option<String>,
429
        /// Machine-readable output: one JSON document on stdout
430
        #[arg(long)]
431
        json: bool,
432
    },
433
    /// Push the current bookmark to a remote
434
    Push {
435
        /// Remote name (default: origin)
436
        remote: Option<String>,
437
        /// Allow dropping heads the remote has
438
        #[arg(long)]
439
        force: bool,
440
        /// Push this bookmark instead of the workspace's current one
441
        #[arg(short = 'b', long)]
442
        bookmark: Option<String>,
443
        /// Delete this bookmark on the remote (never its default bookmark);
444
        /// the local bookmark is kept
445
        #[arg(long, value_name = "NAME", conflicts_with_all = ["bookmark", "force"])]
446
        delete: Option<String>,
447
        /// Machine-readable output: one JSON document on stdout
448
        #[arg(long)]
449
        json: bool,
450
    },
451
    /// Serve repositories under ROOT over HTTPS (with --tls-cert/--tls-key) or plain HTTP
452
    Serve {
453
        /// Directory with one repository per subdirectory
454
        #[arg(long, default_value = ".")]
455
        root: PathBuf,
456
        /// Address and port to listen on
457
        #[arg(long, default_value = "127.0.0.1:8890")]
458
        bind: String,
459
        /// Bearer token allowed to push (repeatable); none means open
460
        #[arg(long = "token")]
461
        tokens: Vec<String>,
462
        /// PEM certificate chain; enables HTTPS together with --tls-key
463
        #[arg(long, requires = "tls_key")]
464
        tls_cert: Option<PathBuf>,
465
        /// PEM private key
466
        #[arg(long, requires = "tls_cert")]
467
        tls_key: Option<PathBuf>,
468
    },
469
    /// Manage the signing identity
470
    Identity {
471
        #[command(subcommand)]
472
        cmd: IdentityCmd,
473
    },
474
    /// Seal changes with your key: named ones, or every change on the current bookmark you can authenticate but have not
475
    Seal {
476
        /// Changes to seal (default: every change on the bookmark you can authenticate and have not sealed)
477
        changes: Vec<String>,
478
        /// Seal every change of a hub proposal and push the seal (your approval)
479
        #[arg(long, conflicts_with = "changes")]
480
        proposal: Option<String>,
481
        /// Approve a job of a hub run that waits for a sealed approval: `--flow https://hub/OWNER/NAME/flow/N --job apply`
482
        #[arg(long, conflicts_with_all = ["changes", "proposal"], requires = "job")]
483
        flow: Option<String>,
484
        /// The job to approve, with --flow
485
        #[arg(long, requires = "flow")]
486
        job: Option<String>,
487
        /// Reject the job instead of approving it, with --flow
488
        #[arg(long, requires = "flow")]
489
        reject: bool,
490
        /// Machine-readable output: one JSON document on stdout
491
        #[arg(long)]
492
        json: bool,
493
    },
494
    /// Hub proposals: show one, or land it from this client
495
    Proposal {
496
        #[command(subcommand)]
497
        cmd: ProposalCmd,
498
    },
499
    /// Verify the signatures on a change (default: every change in the log)
500
    Verify {
501
        /// The change to verify (default: every change in the log)
502
        change: Option<String>,
503
        /// Verify every change a revset selects: `release..main & unsigned()`
504
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
505
        revset: Option<String>,
506
        /// Machine-readable output: one JSON document on stdout
507
        #[arg(long)]
508
        json: bool,
509
    },
510
    /// Git interoperability
511
    Git {
512
        #[command(subcommand)]
513
        cmd: GitCmd,
514
    },
515
    /// Manage the trust policy (who may update which bookmarks)
516
    Policy {
517
        #[command(subcommand)]
518
        cmd: PolicyCmd,
519
    },
520
    /// 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)
521
    Config {
522
        /// The key, such as author.name or remote.origin.token
523
        key: String,
524
        /// The value to set (none with --unset); `-` reads it from standard input, out of the shell's history
525
        #[arg(required_unless_present = "unset")]
526
        value: Option<String>,
527
        /// Write to the user file (~/.config/oxy/config.toml) instead of this repository
528
        #[arg(long)]
529
        user: bool,
530
        /// Remove the key from this repository's file (or the user file with --user)
531
        #[arg(long)]
532
        unset: bool,
533
    },
534
}
535
536
#[derive(Subcommand)]
537
enum OpCmd {
538
    /// List operations, newest first, with what each changed
539
    Log {
540
        /// Show only the latest N (snapshots folded together count as one)
541
        #[arg(short = 'n', long)]
542
        limit: Option<usize>,
543
        /// Machine-readable output: one JSON document on stdout
544
        #[arg(long)]
545
        json: bool,
546
    },
547
    /// Go back to the bookmarks and working copy as they were after OP (recorded as a new operation, so it can be undone)
548
    Restore {
549
        /// The operation: an ID prefix from oxy op log, @ or @-
550
        op: String,
551
        /// Throw away uncommitted working-copy changes
552
        #[arg(long)]
553
        discard: bool,
554
    },
555
    /// Undo OP alone, keeping every operation after it: the bookmarks it moved go back
556
    Revert {
557
        /// The operation: an ID prefix from oxy op log
558
        op: String,
559
    },
560
}
561
562
#[derive(Subcommand)]
563
enum WorkspaceCmd {
564
    /// Create a workspace at PATH checked out on CHANGE... (default: the bookmark heads)
565
    Add {
566
        /// Directory for the new workspace (must be empty or absent)
567
        path: PathBuf,
568
        /// Changes whose state to check out there
569
        changes: Vec<String>,
570
    },
571
    /// List workspaces and their working-copy changes
572
    List {
573
        /// Machine-readable output: one JSON document on stdout
574
        #[arg(long)]
575
        json: bool,
576
    },
577
    /// Stop tracking a workspace (by id prefix or path); its files stay
578
    Forget {
579
        /// Workspace id prefix or path
580
        workspace: String,
581
    },
582
}
583
584
#[derive(Subcommand)]
585
enum BisectCmd {
586
    /// Begin; remembers where the working copy was
587
    Start,
588
    /// Mark CHANGE... (or the state under test) as good
589
    Good {
590
        /// Changes known to be good (default: the state under test)
591
        changes: Vec<String>,
592
    },
593
    /// Mark CHANGE... (or the state under test) as bad
594
    Bad {
595
        /// Changes known to be bad (default: the state under test)
596
        changes: Vec<String>,
597
    },
598
    /// The state under test cannot be tested; try another
599
    Skip,
600
    /// Run a command for each step: exit 0 good, 125 skip, else bad
601
    Run {
602
        /// Command and arguments to run at each step
603
        #[arg(required = true, trailing_var_arg = true)]
604
        command: Vec<String>,
605
    },
606
    /// Where the search stands
607
    Status {
608
        /// Machine-readable output: one JSON document on stdout
609
        #[arg(long)]
610
        json: bool,
611
    },
612
    /// Restore the working copy and forget the search
613
    Reset,
614
}
615
616
#[derive(Subcommand)]
617
enum BookmarkCmd {
618
    /// Create a bookmark at CHANGE... (default: the working copy's base)
619
    Create {
620
        /// Name of the new bookmark
621
        name: String,
622
        /// Its heads (default: the working copy's base). A state is its
623
        /// heads and what they depend on: a change alone may leave out
624
        /// earlier changes of the current state, which is refused unless
625
        /// --upto or --only says which is meant
626
        changes: Vec<String>,
627
        /// Everything of the current state up to CHANGE..., as a Git
628
        /// branch at a commit would hold
629
        #[arg(long, conflicts_with = "only")]
630
        upto: bool,
631
        /// Just CHANGE... and what they depend on. Other changes to the
632
        /// same files are left out, so a file can come out partly edited;
633
        /// to add one change to a bookmark's work, give the bookmark's
634
        /// heads with it instead: `bookmark set NAME <its heads> CHANGE`
635
        #[arg(long)]
636
        only: bool,
637
    },
638
    /// Point an existing bookmark at CHANGE...
639
    Set {
640
        /// The bookmark to move
641
        name: String,
642
        /// Its new heads. A change alone may leave out changes the
643
        /// bookmark now holds that were recorded before it, which is
644
        /// refused unless --upto or --only says which is meant
645
        changes: Vec<String>,
646
        /// Everything the bookmark holds up to CHANGE..., as a Git branch
647
        /// moved to a commit would hold
648
        #[arg(long, conflicts_with = "only")]
649
        upto: bool,
650
        /// Just CHANGE... and what they depend on. Other changes to the
651
        /// same files are left out, so a file can come out partly edited;
652
        /// to add one change to a bookmark's work, give the bookmark's
653
        /// heads with it instead: `bookmark set NAME <its heads> CHANGE`
654
        #[arg(long)]
655
        only: bool,
656
    },
657
    /// Remove a bookmark; its changes stay
658
    Delete {
659
        /// The bookmark to remove
660
        name: String,
661
    },
662
    /// List bookmarks with their heads and difference from origin
663
    List {
664
        /// Also list remotes' bookmarks that have no local bookmark
665
        #[arg(long, short)]
666
        all: bool,
667
        /// Each head of every bookmark, as `bookmark show` prints them
668
        #[arg(long, short)]
669
        verbose: bool,
670
        /// Machine-readable output: one JSON document on stdout
671
        #[arg(long)]
672
        json: bool,
673
    },
674
    /// A bookmark's heads: each change nothing else on it depends on,
675
    /// newest first. A bookmark name is also a revset for its heads
676
    /// (`oxy log -r NAME`, or `bookmark(NAME)` to mean only the bookmark)
677
    Show {
678
        /// The bookmark, or REMOTE/NAME (default: the current one)
679
        name: Option<String>,
680
        /// Machine-readable output: one JSON document on stdout
681
        #[arg(long)]
682
        json: bool,
683
    },
684
    /// Make NAME this workspace's bookmark and check it out. Uncommitted work stops it; --carry takes the work along, --discard drops it
685
    Switch {
686
        /// The bookmark to work on; one only a remote has (NAME or REMOTE/NAME) is created from it
687
        name: String,
688
        /// Throw away uncommitted working-copy changes
689
        #[arg(long)]
690
        discard: bool,
691
        /// Take uncommitted changes along; refused when NAME has other
692
        /// versions of the files they touch
693
        #[arg(long, conflicts_with = "discard")]
694
        carry: bool,
695
    },
696
}
697
698
#[derive(Subcommand)]
699
enum WitnessCmd {
700
    /// Serve a witness (C2SP tlog-witness: POST /add-checkpoint), signing
701
    /// with this oxy home's key (author.key)
702
    Serve {
703
        /// The witness's name in cosignatures: a host name
704
        #[arg(long)]
705
        name: String,
706
        /// A log to witness, as ORIGIN=FILE: its origin (HOST/log) and its
707
        /// key's identity file (a hub's /.well-known/oxyhub-key); repeatable
708
        #[arg(long = "log", required = true)]
709
        logs: Vec<String>,
710
        /// Where to keep what it cosigned
711
        #[arg(long, default_value = "witness-state")]
712
        state: PathBuf,
713
        /// Address and port to listen on
714
        #[arg(long, default_value = "127.0.0.1:8891")]
715
        bind: String,
716
        /// PEM certificate chain; enables HTTPS together with --tls-key
717
        #[arg(long, requires = "tls_key")]
718
        tls_cert: Option<PathBuf>,
719
        /// PEM private key for --tls-cert
720
        #[arg(long, requires = "tls_cert")]
721
        tls_key: Option<PathBuf>,
722
    },
723
}
724
725
#[derive(Subcommand)]
726
enum TlogCmd {
727
    /// Check a hub's whole log: its checkpoint against the log key and the
728
    /// last checkpoint seen, and every entry against the root it signed;
729
    /// then list this repository's entries (or a key's, or all)
730
    Verify {
731
        /// The hub, as https://oxygenhub.io (default: this checkout's remote)
732
        hub: Option<String>,
733
        /// List the entries a key signed (a KeyId) instead
734
        #[arg(long, conflicts_with = "all")]
735
        key: Option<String>,
736
        /// List every entry
737
        #[arg(long)]
738
        all: bool,
739
        /// Machine-readable output
740
        #[arg(long)]
741
        json: bool,
742
    },
743
}
744
745
#[derive(Subcommand)]
746
enum AuthCmd {
747
    /// Sign in to HUB in the browser (device sign-in) and keep the token for
748
    /// every repository there
749
    Login {
750
        /// The hub, as https://oxygenhub.io or oxygenhub.io (default: this checkout's origin)
751
        hub: Option<String>,
752
        /// Read a token from standard input instead (for CI and scripts)
753
        #[arg(long)]
754
        with_token: bool,
755
        /// PEM file of extra roots to trust (a hub with a self-signed certificate)
756
        #[arg(long)]
757
        ca: Option<PathBuf>,
758
    },
759
    /// List the hubs you are signed in to, checking each token with its hub
760
    Status,
761
    /// Forget HUB's token and revoke it on the hub
762
    Logout {
763
        /// The hub (default: this checkout's origin, or the only one)
764
        hub: Option<String>,
765
    },
766
    /// Keep an agent grant token (from `oh agent grant`) for keyless
767
    /// signing: with `author.signer = keyless`, commits and pushes are
768
    /// signed by fresh keys the hub certifies, in the grantor's name
769
    /// (the token is read from standard input, so it stays out of the
770
    /// shell's history)
771
    Grant {
772
        /// The hub (default: this checkout's origin)
773
        hub: Option<String>,
774
    },
775
}
776
777
#[derive(Subcommand)]
778
enum SubmoduleCmd {
779
    /// Clone URL (Oxygen or Git) into PATH and register it in .oxymodules
780
    Add {
781
        /// URL or path of the Oxygen or Git repository
782
        url: String,
783
        /// Where to put it, relative to the repository root
784
        path: String,
785
        /// Bookmark (Oxygen) or branch (Git) to check out and track
786
        #[arg(long)]
787
        bookmark: Option<String>,
788
    },
789
    /// Bring nested repositories to their pins
790
    Update {
791
        /// Clone nested repositories that are absent
792
        #[arg(long)]
793
        init: bool,
794
        /// Subrepos to update (default: all)
795
        paths: Vec<String>,
796
    },
797
    /// List subrepos with their pins and on-disk state
798
    Status {
799
        /// Machine-readable output: one JSON document on stdout
800
        #[arg(long)]
801
        json: bool,
802
    },
803
    /// Unregister PATH; the directory stays, the node goes with the next commit
804
    Remove {
805
        /// The subrepo to unregister
806
        path: String,
807
    },
808
}
809
810
#[derive(Subcommand)]
811
enum ReceiptCmd {
812
    /// The receipts kept for a state (default: the bookmark heads)
813
    List {
814
        /// Change, bookmark or tag whose state to look at
815
        rev: Option<String>,
816
        /// Machine-readable output: one JSON document on stdout
817
        #[arg(long)]
818
        json: bool,
819
    },
820
    /// One receipt in full, and whether its signature verifies
821
    Show {
822
        /// The receipt (a prefix of its hash, as `list` shows it)
823
        receipt: String,
824
        /// Change, bookmark or tag whose state holds it
825
        #[arg(long)]
826
        rev: Option<String>,
827
        /// Machine-readable output: one JSON document on stdout
828
        #[arg(long)]
829
        json: bool,
830
    },
831
    /// Write a signed receipt to FILE
832
    Export {
833
        /// The receipt (a prefix of its hash, as `list` shows it)
834
        receipt: String,
835
        /// Where to write it
836
        file: String,
837
        /// Change, bookmark or tag whose state holds it
838
        #[arg(long)]
839
        rev: Option<String>,
840
        /// `oxygen`: the runner's signed receipt, as `verify` and `import`
841
        /// read it. `slsa`: SLSA provenance in a DSSE envelope, signed with
842
        /// your key, for in-toto and cosign (`oxy identity export --pem`
843
        /// gives the key they check it with)
844
        #[arg(long, default_value = "oxygen", value_parser = ["oxygen", "slsa"])]
845
        format: String,
846
    },
847
    /// Check a signed receipt in FILE without keeping it
848
    Verify {
849
        /// A signed receipt, as a runner or `export` writes it
850
        file: String,
851
        /// Machine-readable output: one JSON document on stdout
852
        #[arg(long)]
853
        json: bool,
854
    },
855
    /// Verify a signed receipt in FILE and keep it with its state
856
    Import {
857
        /// A signed receipt, as a runner or `export` writes it
858
        file: String,
859
    },
860
}
861
862
#[derive(Subcommand)]
863
enum TagCmd {
864
    /// Tag the state of CHANGE... (default: the bookmark heads)
865
    Create {
866
        /// Name of the tag; tags never move
867
        name: String,
868
        /// Changes whose state to tag (default: the bookmark heads)
869
        changes: Vec<String>,
870
        /// A message recorded with the tag
871
        #[arg(short, long, default_value = "")]
872
        message: String,
873
    },
874
    /// List tags and the states they name
875
    List {
876
        /// Machine-readable output: one JSON document on stdout
877
        #[arg(long)]
878
        json: bool,
879
    },
880
}
881
882
#[derive(Subcommand)]
883
enum RemoteCmd {
884
    /// Add a remote
885
    Add {
886
        /// Name to refer to the remote by, such as origin
887
        name: String,
888
        /// 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
889
        url: String,
890
        /// For an s3:// store: the AWS profile to use (default: AWS_PROFILE, else "default")
891
        #[arg(long)]
892
        profile: Option<String>,
893
        /// For an s3:// store: its region (default: the environment, the profile, else asked of S3)
894
        #[arg(long)]
895
        region: Option<String>,
896
        /// For an s3://, gs:// or az:// store: another endpoint, such as an S3-compatible service
897
        #[arg(long)]
898
        endpoint: Option<String>,
899
        /// For a gs:// store: a service account key file, or application default credentials
900
        #[arg(long)]
901
        credentials: Option<String>,
902
    },
903
    /// Check a remote: that it is reachable with the credentials in hand, what it holds, and (for a store) that it behaves
904
    Check {
905
        /// The remote to check
906
        name: String,
907
    },
908
    /// Remove a remote
909
    Remove {
910
        /// The remote to remove
911
        name: String,
912
    },
913
    /// List remotes and their URLs
914
    List {
915
        /// Machine-readable output: one JSON document on stdout
916
        #[arg(long)]
917
        json: bool,
918
    },
919
}
920
921
#[derive(Subcommand)]
922
enum ProposalCmd {
923
    /// Show a proposal by its hub URL
924
    Show {
925
        /// The proposal's URL on the hub
926
        url: String,
927
        /// Machine-readable output: one JSON document on stdout
928
        #[arg(long)]
929
        json: bool,
930
    },
931
    /// Fetch the proposal's changes, set the target bookmark to the projected state, and push with your key
932
    Land {
933
        /// The proposal's URL on the hub
934
        url: String,
935
        /// Land even when the hub reports blockers
936
        #[arg(long)]
937
        force: bool,
938
    },
939
}
940
941
#[derive(Subcommand)]
942
enum IdentityCmd {
943
    /// Generate a composite Ed25519 + ML-DSA-65 key pair and make it your author identity
944
    Create {
945
        /// Your name (default: author.name)
946
        #[arg(long)]
947
        name: Option<String>,
948
        /// Your email (default: author.email)
949
        #[arg(long)]
950
        email: Option<String>,
951
        /// Record the author in this repository only, not in the user config
952
        #[arg(long)]
953
        local: bool,
954
        /// Expire the identity this many days from now
955
        #[arg(long)]
956
        expires: Option<u64>,
957
    },
958
    /// Show the configured identity
959
    Show,
960
    /// Write your identity object to a file, to hand to a policy holder
961
    Export {
962
        /// File to write (default: <key>.identity, or <key>.pem with --pem, in the current directory)
963
        path: Option<PathBuf>,
964
        /// Write the Ed25519 public key as PEM instead, as cosign's --key and
965
        /// other DSSE verifiers take it
966
        #[arg(long)]
967
        pem: bool,
968
    },
969
    /// Sign a host's challenge (hex, at least 16 bytes) to prove you hold your key; prints the signature as hex
970
    SignChallenge {
971
        /// The host's challenge, as hex
972
        challenge: String,
973
        /// Machine-readable output: one JSON document on stdout
974
        #[arg(long)]
975
        json: bool,
976
    },
977
    /// Move to a fresh key pair; the policy follows if it names your key
978
    Rotate,
979
    /// Re-issue your identity with a new expiry (in days from now; 0 = never)
980
    Renew {
981
        /// Days from now until it expires; 0 for never
982
        #[arg(long)]
983
        expires: u64,
984
    },
985
    /// Revoke a key: yours by default, or any key if you hold a policy root
986
    Revoke {
987
        /// KeyId prefix (default: your own key)
988
        key: Option<String>,
989
        /// Why, recorded in the revocation
990
        #[arg(long, default_value = "")]
991
        reason: String,
992
    },
993
    /// Keys allowed to sign or seal on your behalf
994
    Delegate {
995
        #[command(subcommand)]
996
        cmd: DelegateCmd,
997
    },
998
}
999
1000
#[derive(Subcommand)]
1001
enum DelegateCmd {
1002
    /// Add a delegate from an exported identity file
1003
    Add {
1004
        /// The delegates' exported identity files: one rotation for all of them
1005
        #[arg(required = true)]
1006
        identity_file: Vec<PathBuf>,
1007
        /// What it may do for you: changes, refs, seal (comma-separated) or all.
1008
        /// An agent gets `changes`; a host that lands for you needs `changes,refs`
1009
        #[arg(long, default_value = "changes")]
1010
        scope: String,
1011
        /// How long for: 30m, 8h, 7d, or a number of days (default: until removed)
1012
        #[arg(long)]
1013
        expires: Option<String>,
1014
    },
1015
    /// Remove a delegate by KeyId prefix
1016
    Remove {
1017
        /// KeyId prefix of the delegate
1018
        key: String,
1019
    },
1020
    /// List delegates
1021
    List,
1022
}
1023
1024
#[derive(Subcommand)]
1025
enum GitCmd {
1026
    /// Export the current bookmark to a Git repository (created bare if absent)
1027
    Export {
1028
        /// Git repository to write to (created bare if absent)
1029
        git_dir: PathBuf,
1030
        /// Git branch to write (default: the bookmark name)
1031
        #[arg(long)]
1032
        branch: Option<String>,
1033
    },
1034
    /// Fetch a branch from a Git remote (path or URL) into the current bookmark
1035
    Fetch {
1036
        /// Git remote: a path or URL
1037
        url: String,
1038
        /// Branch to fetch
1039
        #[arg(long, default_value = "main")]
1040
        branch: String,
1041
        /// Author your own commits (Git author email = your identity's) with your key; sets git.claim
1042
        #[arg(long)]
1043
        claim: bool,
1044
    },
1045
    /// Push the current bookmark to a branch of a Git remote (fetch first)
1046
    Push {
1047
        /// Git remote: a path or URL
1048
        url: String,
1049
        /// Branch to push to
1050
        #[arg(long, default_value = "main")]
1051
        branch: String,
1052
    },
1053
    /// 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
1054
    Recover,
1055
    /// Check this repository's import of a Git branch: every commit's tree must be reproduced exactly
1056
    Verify {
1057
        /// The Git repository the import came from
1058
        git_dir: PathBuf,
1059
        /// Branch that was imported
1060
        #[arg(long, default_value = "main")]
1061
        branch: String,
1062
        /// Rebuild only the last N commits (the others are followed, not checked)
1063
        #[arg(long, value_name = "N")]
1064
        last: Option<usize>,
1065
        /// Stop after N differences (0: check every commit whatever it finds)
1066
        #[arg(long, value_name = "N", default_value_t = 50)]
1067
        max_differences: usize,
1068
    },
1069
    /// Import a Git branch into a new Oxygen repository at DEST
1070
    Import {
1071
        /// Git repository to read
1072
        git_dir: PathBuf,
1073
        /// Directory for the new Oxygen repository
1074
        dest: PathBuf,
1075
        /// Branch to import
1076
        #[arg(long, default_value = "main")]
1077
        branch: String,
1078
        /// Author your own commits (Git author email = your identity's) with your key; sets git.claim
1079
        #[arg(long)]
1080
        claim: bool,
1081
    },
1082
}
1083
1084
#[derive(Subcommand)]
1085
enum PolicyCmd {
1086
    /// Create the initial policy with your identity as the only root
1087
    Init,
1088
    /// Show the current policy
1089
    Show {
1090
        /// Machine-readable output: one JSON document on stdout
1091
        #[arg(long)]
1092
        json: bool,
1093
    },
1094
    /// Allow an identity (from `oxy identity export`) to update bookmarks
1095
    Grant {
1096
        /// The identity to grant, exported with `oxy identity export`
1097
        identity_file: PathBuf,
1098
        /// Reference pattern the grant applies to (default: every bookmark)
1099
        #[arg(long)]
1100
        pattern: Option<String>,
1101
        /// Where to write the proposal when more root signatures are needed
1102
        #[arg(long)]
1103
        out: Option<PathBuf>,
1104
    },
1105
    /// Allow holders of an issuer's certificates for SUBJECT to sign (keyless)
1106
    GrantSubject {
1107
        /// Who: `repo:OWNER/NAME:bookmark:main`, `agent:NAME@ACCOUNT`; `*` matches any run of characters
1108
        subject: String,
1109
        /// The issuer's identity file, e.g. a hub's /.well-known/oxyhub-key
1110
        #[arg(long)]
1111
        issuer: PathBuf,
1112
        /// What its keys may sign: changes, refs, seal
1113
        #[arg(long, default_value = "changes,refs")]
1114
        scope: String,
1115
        /// Reference pattern the grant applies to (default: every bookmark)
1116
        #[arg(long)]
1117
        pattern: Option<String>,
1118
        /// Where to write the proposal when more root signatures are needed
1119
        #[arg(long)]
1120
        out: Option<PathBuf>,
1121
    },
1122
    /// Revoke a key (KeyId prefix of an identity in the policy)
1123
    Revoke {
1124
        /// KeyId prefix of the identity
1125
        key: String,
1126
        /// Where to write the proposal when more root signatures are needed
1127
        #[arg(long)]
1128
        out: Option<PathBuf>,
1129
    },
1130
    /// Manage root keys and the signature threshold for policy updates
1131
    Root {
1132
        #[command(subcommand)]
1133
        cmd: RootCmd,
1134
    },
1135
    /// Add your root signature to a proposal file; applies it once the threshold is met
1136
    Sign {
1137
        /// The proposal file to sign
1138
        proposal: PathBuf,
1139
        /// Where to write the proposal if it still needs signatures (default: in place)
1140
        #[arg(long)]
1141
        out: Option<PathBuf>,
1142
    },
1143
}
1144
1145
#[derive(Subcommand)]
1146
enum RootCmd {
1147
    /// Make an exported identity a root key
1148
    Add {
1149
        /// The identity to make a root, exported with `oxy identity export`
1150
        identity_file: PathBuf,
1151
        /// Where to write the proposal when more root signatures are needed
1152
        #[arg(long)]
1153
        out: Option<PathBuf>,
1154
    },
1155
    /// Remove a root key by KeyId prefix
1156
    Remove {
1157
        /// KeyId prefix of the root key
1158
        key: String,
1159
        /// Where to write the proposal when more root signatures are needed
1160
        #[arg(long)]
1161
        out: Option<PathBuf>,
1162
    },
1163
    /// Require this many root signatures on policy updates
1164
    Threshold {
1165
        /// Number of root signatures
1166
        n: u32,
1167
        /// Where to write the proposal when more root signatures are needed
1168
        #[arg(long)]
1169
        out: Option<PathBuf>,
1170
    },
1171
}
1172
1173
/// Open the repository containing the current directory.
1174122×
fn open() -> Result<Repo> {
1175122×
    let repo = Repo::open(&std::env::current_dir()?).context("opening repository")?;
1176122×
    match AT_OP.get().and_then(|o| o.as_deref()) {
11770×
        Some(op) => Ok(repo.at_op(op)?),
1178122×
        None => Ok(repo),
1179
    }
1180122×
}
1181
1182
/// `oxy man`: every page into `dir`, or the top-level page on stdout.
11832×
fn man(dir: Option<PathBuf>) -> Result<i32> {
1184
    use clap::CommandFactory;
11852×
    let cmd = Cli::command();
11862×
    match dir {
11871×
        Some(dir) => {
11881×
            std::fs::create_dir_all(&dir)?;
11891×
            clap_mangen::generate_to(cmd, &dir)?;
11901×
            let pages = std::fs::read_dir(&dir)?
1191126×
                .filter(|e| {
1192126×
                    e.as_ref()
1193126×
                        .is_ok_and(|e| e.path().extension().is_some_and(|x| x == "1"))
1194126×
                })
11951×
                .count();
11961×
            println!(
1197
                "{}",
11981×
                ui::done(format!("Wrote {pages} man pages to {}", dir.display()))
1199
            );
1200
        }
12011×
        None => clap_mangen::Man::new(cmd).render(&mut std::io::stdout())?,
1202
    }
12032×
    Ok(0)
12042×
}
1205
1206
/// Parse arguments and run; returns the process exit code.
1207152×
pub fn run() -> Result<i32> {
1208
    // The cloud stores (s3://, gs://, az://) for remotes kept on them.
1209152×
    oxy_strata::register();
1210152×
    let cli = Cli::parse();
1211152×
    ui::init(cli.plain);
1212152×
    AT_OP.set(cli.at_op.clone()).ok();
12130×
    match cli.cmd {
12144×
        Cmd::Completions { shell } => {
1215
            use clap::CommandFactory;
12164×
            clap_complete::generate(shell, &mut Cli::command(), "oxy", &mut std::io::stdout());
12174×
            Ok(0)
1218
        }
12192×
        Cmd::Man { dir } => man(dir),
122014×
        Cmd::Init { path, bare, store } => workspace::init(path, bare, store.as_deref()),
12218×
        Cmd::Status { json } => workspace::status(json),
1222
        Cmd::Prompt {
12230×
            format,
12240×
            glyphs,
12250×
            color,
12260×
        } => workspace::prompt(&format, glyphs, color.as_deref()),
1227
        Cmd::Commit {
122826×
            message,
122926×
            file,
123026×
            depends_on,
123126×
            paths,
123226×
            interactive,
123326×
            hunks,
1234
        } => {
123526×
            let message = match (message, file) {
123625×
                (Some(m), _) => m,
12371×
                (None, Some(f)) if f.as_os_str() == "-" => {
12380×
                    let mut s = String::new();
12390×
                    std::io::Read::read_to_string(&mut std::io::stdin(), &mut s)?;
12400×
                    s
1241
                }
12421×
                (None, Some(f)) => std::fs::read_to_string(&f).map_err(|e| {
12430×
                    anyhow::anyhow!("reading the message from {}: {e}", f.display())
12440×
                })?,
12450×
                (None, None) => anyhow::bail!("a commit message is required (-m or -F)"),
1246
            };
124726×
            workspace::commit(&message, &depends_on, &paths, interactive, &hunks)
1248
        }
12492×
        Cmd::Cat { path, change } => workspace::cat(&path, change.as_deref()),
12501×
        Cmd::Root { json } => workspace::root(json),
12511×
        Cmd::Version { json } => workspace::version(json),
12522×
        Cmd::Discard { paths, hunks } => workspace::discard(&paths, &hunks),
12532×
        Cmd::Hunks { json } => workspace::hunks(json),
12540×
        Cmd::Squash { change, into } => workspace::squash(&change, &into),
1255
        Cmd::Rebase {
12560×
            change,
12570×
            onto,
12580×
            into_working_copy,
12590×
        } => workspace::rebase(&change, &onto, into_working_copy),
12600×
        Cmd::Blame { path, json } => workspace::blame(&path, json),
12611×
        Cmd::Bisect { cmd } => match cmd {
12620×
            BisectCmd::Start => workspace::bisect_start(),
12630×
            BisectCmd::Good { changes } => workspace::bisect_mark(Some(true), &changes),
12640×
            BisectCmd::Bad { changes } => workspace::bisect_mark(Some(false), &changes),
12650×
            BisectCmd::Skip => workspace::bisect_mark(None, &[]),
12660×
            BisectCmd::Run { command } => workspace::bisect_run(&command),
12671×
            BisectCmd::Status { json } => workspace::bisect_status(json),
12680×
            BisectCmd::Reset => workspace::bisect_reset(),
1269
        },
1270
        Cmd::Log {
12718×
            revset,
12728×
            limit,
12738×
            verbose,
12748×
            path,
12758×
            lines,
12768×
            json,
12778×
        } => workspace::log(
12788×
            revset.as_deref(),
12798×
            limit,
12808×
            verbose,
12818×
            path.as_deref(),
12828×
            lines.as_deref(),
12838×
            json,
1284
        ),
12851×
        Cmd::Diff { change, json } => workspace::diff(change.as_deref(), json),
1286
        Cmd::Describe {
12874×
            message,
12884×
            change,
12894×
            json,
12904×
        } => match message {
12910×
            Some(m) => workspace::describe(&m, change.as_deref()),
12924×
            None if change.is_some() => {
12930×
                anyhow::bail!(
1294
                    "naming works on the working copy; to change a head's message pass -m"
1295
                )
1296
            }
12974×
            None => workspace::describe_name(json),
1298
        },
1299
        Cmd::Amend {
13000×
            message,
13010×
            into,
13020×
            paths,
13030×
        } => workspace::amend(message.as_deref(), into.as_deref(), &paths),
13040×
        Cmd::Split { change, paths } => workspace::split(&change, &paths),
1305
        Cmd::Abandon {
13060×
            change,
13070×
            revset,
13080×
            yes,
13090×
        } => workspace::abandon(change.as_deref(), revset.as_deref(), yes),
1310
        Cmd::Show {
13113×
            change,
13123×
            revset,
13133×
            stat,
13143×
            json,
13153×
        } => workspace::show(change.as_deref(), revset.as_deref(), stat, json),
1316
        Cmd::Checkout {
13170×
            changes,
13180×
            discard,
13190×
            carry,
13200×
        } => workspace::checkout(&changes, discard, carry),
13211×
        Cmd::Resolve { json } => workspace::resolve(json),
13220×
        Cmd::Undo => workspace::undo(),
1323
        Cmd::Gc {
13242×
            now,
13252×
            expire_snapshots,
13262×
            remote,
13272×
        } => match remote {
13282×
            Some(name) => workspace::gc_remote(&name, now),
13290×
            None => workspace::gc(now, expire_snapshots),
1330
        },
13310×
        Cmd::Fsck { json } => workspace::fsck(json),
13320×
        Cmd::Doctor { offline, json } => workspace::doctor(offline, json),
13330×
        Cmd::Checkpoint => workspace::checkpoint(),
13341×
        Cmd::Op { cmd } => match cmd {
13351×
            OpCmd::Log { limit, json } => workspace::op_log(limit, json),
13360×
            OpCmd::Restore { op, discard } => workspace::op_restore(&op, discard),
13370×
            OpCmd::Revert { op } => workspace::op_revert(&op),
1338
        },
1339
        Cmd::Clone {
13405×
            url,
13415×
            dest,
13425×
            max_blob,
13435×
            sparse,
13445×
            depth,
13455×
            recursive,
13465×
        } => sync::clone(&url, dest, max_blob.as_deref(), &sparse, depth, recursive),
13470×
        Cmd::Deepen { depth, remote } => sync::deepen(&remote, depth),
13480×
        Cmd::Sparse { paths } => workspace::sparse(&paths),
13490×
        Cmd::Lock { path } => workspace::lock(&path),
13500×
        Cmd::Unlock { path } => workspace::unlock(&path),
13511×
        Cmd::Workspace { cmd } => match cmd {
13520×
            WorkspaceCmd::Add { path, changes } => workspace::workspace_add(&path, &changes),
13531×
            WorkspaceCmd::List { json } => workspace::workspace_list(json),
13540×
            WorkspaceCmd::Forget { workspace } => workspace::workspace_forget(&workspace),
1355
        },
135617×
        Cmd::Bookmark { cmd } => match cmd {
1357
            BookmarkCmd::Create {
13586×
                name,
13596×
                changes,
13606×
                upto,
13616×
                only,
13626×
            } => workspace::bookmark_create(&name, &changes, upto, only),
1363
            BookmarkCmd::Set {
13643×
                name,
13653×
                changes,
13663×
                upto,
13673×
                only,
13683×
            } => workspace::bookmark_set(&name, &changes, upto, only),
13690×
            BookmarkCmd::Delete { name } => workspace::bookmark_delete(&name),
13705×
            BookmarkCmd::List { all, verbose, json } => {
13715×
                workspace::bookmark_list(all, verbose, json)
1372
            }
13730×
            BookmarkCmd::Show { name, json } => workspace::bookmark_show(name.as_deref(), json),
1374
            BookmarkCmd::Switch {
13753×
                name,
13763×
                discard,
13773×
                carry,
13783×
            } => workspace::bookmark_switch(&name, discard, carry),
1379
        },
13800×
        Cmd::Merge { bookmark } => workspace::merge(&bookmark),
13810×
        Cmd::Auth { cmd } => match cmd {
1382
            AuthCmd::Login {
13830×
                hub,
13840×
                with_token,
13850×
                ca,
13860×
            } => auth::login(hub.as_deref(), with_token, ca),
13870×
            AuthCmd::Status => auth::status(),
13880×
            AuthCmd::Logout { hub } => auth::logout(hub.as_deref()),
13890×
            AuthCmd::Grant { hub } => auth::grant(hub.as_deref()),
1390
        },
13911×
        Cmd::Submodule { cmd } => match cmd {
1392
            SubmoduleCmd::Add {
13930×
                url,
13940×
                path,
13950×
                bookmark,
13960×
            } => sync::submodule_add(&url, &path, bookmark.as_deref()),
13970×
            SubmoduleCmd::Update { init, paths } => sync::submodule_update(init, &paths),
13981×
            SubmoduleCmd::Status { json } => sync::submodule_status(json),
13990×
            SubmoduleCmd::Remove { path } => sync::submodule_remove(&path),
1400
        },
1401
        Cmd::Witness {
1402
            cmd:
1403
                WitnessCmd::Serve {
14040×
                    name,
14050×
                    logs,
14060×
                    state,
14070×
                    bind,
14080×
                    tls_cert,
14090×
                    tls_key,
1410
                },
14110×
        } => tlog::witness_serve(&name, &logs, state, &bind, tls_cert.zip(tls_key)),
14120×
        Cmd::Tlog { cmd } => match cmd {
1413
            TlogCmd::Verify {
14140×
                hub,
14150×
                key,
14160×
                all,
14170×
                json,
14180×
            } => tlog::verify(hub.as_deref(), key.as_deref(), all, json),
1419
        },
142010×
        Cmd::Receipt { cmd } => match cmd {
14212×
            ReceiptCmd::List { rev, json } => receipt::list(rev.as_deref(), json),
1422
            ReceiptCmd::Show {
14231×
                receipt: r,
14241×
                rev,
14251×
                json,
14261×
            } => receipt::show(&r, rev.as_deref(), json),
1427
            ReceiptCmd::Export {
14283×
                receipt: r,
14293×
                file,
14303×
                rev,
14313×
                format,
14323×
            } => receipt::export(&r, &file, rev.as_deref(), &format),
14332×
            ReceiptCmd::Verify { file, json } => receipt::verify(&file, json),
14342×
            ReceiptCmd::Import { file } => receipt::import(&file),
1435
        },
14363×
        Cmd::Tag { cmd } => match cmd {
1437
            TagCmd::Create {
14382×
                name,
14392×
                changes,
14402×
                message,
14412×
            } => workspace::tag_create(&name, &changes, &message),
14421×
            TagCmd::List { json } => workspace::tag_list(json),
1443
        },
144410×
        Cmd::Remote { cmd } => match cmd {
1445
            RemoteCmd::Add {
14464×
                name,
14474×
                url,
14484×
                profile,
14494×
                region,
14504×
                endpoint,
14514×
                credentials,
14524×
            } => sync::remote_add(
14534×
                &name,
14544×
                &url,
14554×
                &[
14564×
                    ("profile", profile),
14574×
                    ("region", region),
14584×
                    ("endpoint", endpoint),
14594×
                    ("credentials", credentials),
14604×
                ],
1461
            ),
14623×
            RemoteCmd::Check { name } => sync::remote_check(&name),
14631×
            RemoteCmd::Remove { name } => sync::remote_remove(&name),
14642×
            RemoteCmd::List { json } => sync::remote_list(json),
1465
        },
14661×
        Cmd::Fetch { remote, json } => sync::fetch(remote.as_deref(), json),
14674×
        Cmd::Pull { remote, json } => sync::pull(remote.as_deref(), json),
1468
        Cmd::Push {
14697×
            remote,
14707×
            force,
14717×
            bookmark,
14727×
            delete,
14737×
            json,
14747×
        } => match delete {
14750×
            Some(name) => sync::push_delete(remote.as_deref(), &name, json),
14767×
            None => sync::push(remote.as_deref(), force, bookmark.as_deref(), json),
1477
        },
1478
        Cmd::Serve {
14790×
            root,
14800×
            bind,
14810×
            tokens,
14820×
            tls_cert,
14830×
            tls_key,
14840×
        } => sync::serve(root, &bind, tokens, tls_cert.zip(tls_key)),
14853×
        Cmd::Identity { cmd } => match cmd {
1486
            IdentityCmd::Create {
14872×
                name,
14882×
                email,
14892×
                local,
14902×
                expires,
14912×
            } => identity::create(name, email, local, expires),
14920×
            IdentityCmd::Show => identity::show(),
14931×
            IdentityCmd::Export { path, pem } => identity::export(path, pem),
14940×
            IdentityCmd::SignChallenge { challenge, json } => {
14950×
                identity::sign_challenge(&challenge, json)
1496
            }
14970×
            IdentityCmd::Rotate => identity::rotate(),
14980×
            IdentityCmd::Renew { expires } => identity::renew(expires),
14990×
            IdentityCmd::Revoke { key, reason } => identity::revoke(key.as_deref(), &reason),
15000×
            IdentityCmd::Delegate { cmd } => match cmd {
1501
                DelegateCmd::Add {
15020×
                    identity_file,
15030×
                    scope,
15040×
                    expires,
15050×
                } => identity::delegate_add(&identity_file, &scope, expires.as_deref()),
15060×
                DelegateCmd::Remove { key } => identity::delegate_remove(&key),
15070×
                DelegateCmd::List => identity::delegate_list(),
1508
            },
1509
        },
1510
        Cmd::Git {
15110×
            cmd: GitCmd::Export { git_dir, branch },
15120×
        } => sync::git_export(&git_dir, branch.as_deref()),
1513
        Cmd::Git {
15140×
            cmd: GitCmd::Fetch { url, branch, claim },
15150×
        } => sync::git_fetch(&url, &branch, claim),
1516
        Cmd::Git {
15170×
            cmd: GitCmd::Push { url, branch },
15180×
        } => sync::git_push(&url, &branch),
1519
        Cmd::Git {
1520
            cmd: GitCmd::Recover,
15210×
        } => sync::git_recover(),
1522
        Cmd::Git {
1523
            cmd:
1524
                GitCmd::Import {
15250×
                    git_dir,
15260×
                    dest,
15270×
                    branch,
15280×
                    claim,
1529
                },
15300×
        } => sync::git_import(&git_dir, &dest, &branch, claim),
1531
        Cmd::Git {
1532
            cmd:
1533
                GitCmd::Verify {
15340×
                    git_dir,
15350×
                    branch,
15360×
                    last,
15370×
                    max_differences,
1538
                },
15390×
        } => sync::git_verify(&git_dir, &branch, last, max_differences),
15405×
        Cmd::Policy { cmd } => match cmd {
15411×
            PolicyCmd::Init => identity::policy_init(),
15423×
            PolicyCmd::Show { json } => identity::policy_show(json),
1543
            PolicyCmd::Grant {
15440×
                identity_file,
15450×
                pattern,
15460×
                out,
15470×
            } => identity::policy_grant(&identity_file, pattern.as_deref(), out),
1548
            PolicyCmd::GrantSubject {
15491×
                subject,
15501×
                issuer,
15511×
                scope,
15521×
                pattern,
15531×
                out,
15541×
            } => identity::policy_grant_subject(&subject, &issuer, &scope, pattern.as_deref(), out),
15550×
            PolicyCmd::Revoke { key, out } => identity::policy_revoke(&key, out),
15560×
            PolicyCmd::Root { cmd } => match cmd {
15570×
                RootCmd::Add { identity_file, out } => {
15580×
                    identity::policy_root_add(&identity_file, out)
1559
                }
15600×
                RootCmd::Remove { key, out } => identity::policy_root_remove(&key, out),
15610×
                RootCmd::Threshold { n, out } => identity::policy_threshold(n, out),
1562
            },
15630×
            PolicyCmd::Sign { proposal, out } => identity::policy_sign(&proposal, out),
1564
        },
1565
        Cmd::Seal {
15660×
            flow: Some(url),
15670×
            job: Some(job),
15680×
            reject,
15690×
            json,
1570
            ..
15710×
        } => approve::seal(&url, &job, reject, json),
1572
        Cmd::Seal {
15730×
            changes,
15740×
            proposal: Some(url),
15750×
            json,
1576
            ..
15770×
        } if changes.is_empty() => proposal::seal(&url, json),
15780×
        Cmd::Seal { changes, json, .. } => identity::seal(&changes, json),
15790×
        Cmd::Proposal { cmd } => match cmd {
15800×
            ProposalCmd::Show { url, json } => proposal::show(&url, json),
15810×
            ProposalCmd::Land { url, force } => proposal::land(&url, force),
1582
        },
1583
        Cmd::Verify {
15841×
            change,
15851×
            revset,
15861×
            json,
15871×
        } => identity::verify(change.as_deref(), revset.as_deref(), json),
1588
        Cmd::Config {
15891×
            key,
15901×
            value,
15911×
            user,
15921×
            unset,
15931×
        } => identity::config(&key, value.as_deref().unwrap_or(""), user, unset),
1594
    }
1595152×
}
1596
1597
#[cfg(test)]
1598
mod help_tests {
1599
    use super::Cli;
1600
    use clap::CommandFactory;
1601
1602
    /// Every command and every argument explains itself, so `--help`,
1603
    /// completions and the man pages are complete.
1604
    #[test]
16051×
    fn every_command_and_argument_has_help() {
1606126×
        fn walk(cmd: &clap::Command, path: &str, missing: &mut Vec<String>) {
1607126×
            let here = format!("{path} {}", cmd.get_name()).trim().to_string();
1608126×
            if cmd.get_about().is_none() && !path.is_empty() {
16090×
                missing.push(format!("{here} (command)"));
1610126×
            }
1611233×
            for a in cmd.get_arguments() {
1612233×
                let id = a.get_id().as_str();
1613233×
                if id == "help" || id == "version" || (a.is_global_set() && !path.is_empty()) {
16140×
                    continue;
1615233×
                }
1616233×
                if a.get_help().is_none() && a.get_long_help().is_none() {
16170×
                    missing.push(format!("{here} {id}"));
1618233×
                }
1619
            }
1620126×
            for sub in cmd.get_subcommands() {
1621125×
                walk(sub, &here, missing);
1622125×
            }
1623126×
        }
16241×
        let mut missing = Vec::new();
16251×
        walk(&Cli::command(), "", &mut missing);
16261×
        assert!(
16271×
            missing.is_empty(),
1628
            "{} without help:\n{}",
16290×
            missing.len(),
16300×
            missing.join("\n")
1631
        );
16321×
    }
1633
}