OXYGENHUB

Coverage / src/cli/mod.rs 59.8%

208 of 348 lines run, 9 of 18 functions · run #323 on main · run missed

1
//! Command-line definitions and dispatch.
2
3
mod approve;
4
mod auth;
5
mod format;
6
mod identity;
7
mod json;
8
mod proposal;
9
mod receipt;
10
mod sync;
11
mod tlog;
12
pub mod ui;
13
mod workspace;
14
15
use anyhow::{Context, Result};
16
use clap::{Parser, Subcommand};
17
use oxy_core::repo::Repo;
18
use std::path::PathBuf;
19
20
#[derive(Parser)]
21
#[command(
22
    name = "oxy",
23
    version = env!("OXY_VERSION_LONG"),
24
    about = "Oxygen: breathing fresh air into version control"
25
)]
26
struct Cli {
27
    /// Plain output: no colour, no spinner (also implied by NO_COLOR or a non-terminal)
28
    #[arg(long, global = true)]
29
    plain: bool,
30
    /// Read the repository as it was after operation OP (an ID from oxy op log, @ or @-); commands that would change it are refused
31
    #[arg(long, global = true, value_name = "OP")]
32
    at_op: Option<String>,
33
    #[command(subcommand)]
34
    cmd: Cmd,
35
}
36
37
/// `--at-op`, for `open` to apply.
38
static AT_OP: std::sync::OnceLock<Option<String>> = std::sync::OnceLock::new();
39
40
#[derive(Subcommand)]
41
enum Cmd {
42
    /// Create a repository in PATH (default: current directory)
43
    Init {
44
        /// Directory to create the repository in (default: the current directory)
45
        path: Option<PathBuf>,
46
        /// No working copy: an object store and references only, for hosting
47
        #[arg(long)]
48
        bare: bool,
49
        /// Keep the objects and the operation log on this store
50
        /// (dir://PATH, s3://BUCKET/PREFIX, gs://…, az://…) instead of
51
        /// in .oxy, with a local cache in front (storage.cache, 2 GiB)
52
        #[arg(long, value_name = "URL")]
53
        store: Option<String>,
54
    },
55
    /// Clone a repository from a local path or an http(s) URL
56
    Clone {
57
        /// Local path or http(s) URL of the repository
58
        url: String,
59
        /// Directory to clone into (default: the last part of the URL)
60
        dest: Option<PathBuf>,
61
        /// Leave blobs larger than this (e.g. 1M) to be fetched on first read
62
        #[arg(long)]
63
        max_blob: Option<String>,
64
        /// Materialize only these paths (repeatable); implies lazy blobs
65
        #[arg(long = "sparse")]
66
        sparse: Vec<String>,
67
        /// Shallow clone: fetch only this many levels of history below the heads
68
        #[arg(long)]
69
        depth: Option<u32>,
70
        /// Clone the subrepos too (as oxy submodule update --init)
71
        #[arg(long)]
72
        recursive: bool,
73
    },
74
    /// Fetch more history below a shallow clone's boundary
75
    Deepen {
76
        /// Levels of history to add below the boundary
77
        #[arg(default_value_t = 10)]
78
        depth: u32,
79
        /// Remote to fetch the history from
80
        #[arg(long, default_value = "origin")]
81
        remote: String,
82
    },
83
    /// Show or set the sparse filter (paths to materialize); re-checks out the bookmark
84
    Sparse {
85
        /// Paths to materialize; none prints the current filter
86
        paths: Vec<String>,
87
    },
88
    /// Show the working copy: changed paths and conflicts
89
    Status {
90
        /// Machine-readable output: paths, and every conflict with its kind and contributing changes
91
        #[arg(long)]
92
        json: bool,
93
    },
94
    /// One-line summary for shell prompts; fast and records nothing
95
    Prompt {
96
        /// Placeholders: %b bookmark, %c change id, %h heads, %d dirty (*), %x conflict (!), %A/%D ahead/behind (+n/-n), %a/%B raw counts, %s state glyph, %U/%O ahead/behind arrows, %i icon
97
        #[arg(long, default_value = oxy_core::repo::DEFAULT_PROMPT_FORMAT)]
98
        format: String,
99
        /// Glyph format (%i %b %c %s%U%O) instead of the plain default
100
        #[arg(long)]
101
        glyphs: bool,
102
        /// Colour by state (cyan clean, yellow dirty, red conflicted): raw escapes, or guarded for a bash or zsh PS1
103
        #[arg(long, value_parser = ["raw", "bash", "zsh"])]
104
        color: Option<String>,
105
    },
106
    /// Record the working copy as a change on the current bookmark
107
    Commit {
108
        /// The change's message: a subject line, then optionally a blank line and a body
109
        #[arg(short, long, required_unless_present = "file", conflicts_with = "file")]
110
        message: Option<String>,
111
        /// Read the message from FILE (`-` for standard input)
112
        #[arg(short = 'F', long, value_name = "FILE")]
113
        file: Option<PathBuf>,
114
        /// Extra explicit dependencies (ChangeId prefix, #hash prefix)
115
        #[arg(long = "depends-on")]
116
        depends_on: Vec<String>,
117
        /// Commit only these paths; the rest stays as uncommitted work
118
        paths: Vec<String>,
119
        /// Choose hunks one by one
120
        #[arg(short, long)]
121
        interactive: bool,
122
        /// Commit these hunks (as `oxy hunks` numbers them), comma separated
123
        #[arg(long, value_delimiter = ',')]
124
        hunks: Vec<usize>,
125
    },
126
    /// Fold CHANGE into one of its dependencies (keeps that change's id)
127
    Squash {
128
        /// The change to fold (ChangeId prefix, #hash prefix)
129
        change: String,
130
        /// The dependency that absorbs it
131
        #[arg(long)]
132
        into: String,
133
    },
134
    /// Re-express CHANGE against another base state
135
    Rebase {
136
        /// The change to re-express (ChangeId prefix, #hash prefix)
137
        change: String,
138
        /// The changes, bookmark or tag whose state becomes the new base
139
        #[arg(long, required = true, num_args = 1..)]
140
        onto: Vec<String>,
141
        /// Where the rebase would be conflicted, merge the target into the
142
        /// current bookmark instead, leaving the conflict in the working
143
        /// copy to fix and commit
144
        #[arg(long)]
145
        into_working_copy: bool,
146
    },
147
    /// Show which change introduced each line of a file
148
    Blame {
149
        /// File to annotate, relative to the repository root
150
        path: String,
151
        /// Machine-readable output: one JSON document on stdout
152
        #[arg(long)]
153
        json: bool,
154
    },
155
    /// Find the change that introduced a regression
156
    Bisect {
157
        #[command(subcommand)]
158
        cmd: BisectCmd,
159
    },
160
    /// List changes reachable from the bookmark and the working copy
161
    Log {
162
        /// Show the changes a revset selects: `main` (a bookmark name means its
163
        /// heads; `bookmark(main)` only ever the bookmark), `main..feature &
164
        /// author(andy)`, `touches("src/**") & date(-7d..)` (see
165
        /// docs/revset_query_language.md)
166
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with_all = ["path", "lines"])]
167
        revset: Option<String>,
168
        /// Show at most this many changes
169
        #[arg(short = 'n', long)]
170
        limit: Option<usize>,
171
        /// Show full messages, dependencies, and signatures
172
        #[arg(short, long)]
173
        verbose: bool,
174
        /// Only changes touching this path (renames followed)
175
        #[arg(long)]
176
        path: Option<String>,
177
        /// Only changes that wrote or deleted lines START to END of PATH
178
        /// (numbered as in the working copy's base), or deleted lines from
179
        /// between them: the history of a function
180
        #[arg(short = 'L', value_name = "START,END:PATH", conflicts_with = "path")]
181
        lines: Option<String>,
182
        /// Machine-readable output: one JSON document on stdout
183
        #[arg(long)]
184
        json: bool,
185
    },
186
    /// Show what the working copy changes against its base
187
    Diff {
188
        /// A change instead of the working copy
189
        change: Option<String>,
190
        /// Machine-readable output: one JSON document on stdout
191
        #[arg(long)]
192
        json: bool,
193
    },
194
    /// Print a file as it is in a state (default: the working copy's base)
195
    Cat {
196
        /// File to print, relative to the repository root
197
        path: String,
198
        /// A bookmark or tag (its state), or a change: a change means its
199
        /// dependency closure, the change and what it depends on, so files
200
        /// only later changes touched are absent or at older versions
201
        #[arg(short = 'r', long)]
202
        change: Option<String>,
203
    },
204
    /// Print the repository root, workspace, and bookmark
205
    Root {
206
        /// Machine-readable output: one JSON document on stdout
207
        #[arg(long)]
208
        json: bool,
209
    },
210
    /// Print the version of oxy, its repository format, and protocol
211
    Version {
212
        /// Machine-readable output: one JSON document on stdout
213
        #[arg(long)]
214
        json: bool,
215
    },
216
    /// Restore paths to the working copy's base, or undo chosen hunks
217
    Discard {
218
        /// Paths to restore; none with --hunks, or everything with neither
219
        paths: Vec<String>,
220
        /// Hunk indices as `oxy hunks` numbers them, comma separated
221
        #[arg(long, value_delimiter = ',')]
222
        hunks: Vec<usize>,
223
    },
224
    /// List the working copy's hunks, numbered as commit --hunks expects
225
    Hunks {
226
        /// Machine-readable output: one JSON document on stdout
227
        #[arg(long)]
228
        json: bool,
229
    },
230
    /// With -m, change the message of a head; without, name the working
231
    /// copy for a build: its tag, or the nearest tag plus distance and
232
    /// change, or the bookmark and change, and -dirty
233
    Describe {
234
        /// The new message
235
        #[arg(short, long)]
236
        message: Option<String>,
237
        /// The head to describe (default: the one the working copy sits on)
238
        change: Option<String>,
239
        /// Machine-readable output (naming only)
240
        #[arg(long, conflicts_with = "message")]
241
        json: bool,
242
    },
243
    /// Fold the working copy into the head it sits on, or into CHANGE with --into
244
    Amend {
245
        /// Replace the message too
246
        #[arg(short, long)]
247
        message: Option<String>,
248
        /// Amend an older change; the edits must touch only lines it already knows
249
        #[arg(long)]
250
        into: Option<String>,
251
    },
252
    /// Split a head: the named paths become a separate first change
253
    Split {
254
        /// The head to split
255
        change: String,
256
        /// Paths whose edits become the first change
257
        paths: Vec<String>,
258
    },
259
    /// Drop a change from the bookmark; its content stays on disk as uncommitted work
260
    Abandon {
261
        /// The change to drop (ChangeId prefix, #hash prefix)
262
        #[arg(required_unless_present = "revset")]
263
        change: Option<String>,
264
        /// Drop every change a revset selects, newest first
265
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
266
        revset: Option<String>,
267
        /// Drop more than five changes without asking
268
        #[arg(long, short = 'y')]
269
        yes: bool,
270
    },
271
    /// Show one change (ChangeId prefix, #hash prefix, or @), or those a revset selects
272
    Show {
273
        /// ChangeId prefix, #hash prefix, or @ for the working copy
274
        #[arg(required_unless_present = "revset")]
275
        change: Option<String>,
276
        /// Show every change a revset selects
277
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
278
        revset: Option<String>,
279
        /// Machine-readable output: one JSON document on stdout
280
        #[arg(long)]
281
        json: bool,
282
    },
283
    /// Move the working copy to the state formed by CHANGE... (default: the bookmark heads)
284
    Checkout {
285
        /// Changes whose state to check out (default: the bookmark heads)
286
        changes: Vec<String>,
287
        /// Throw away uncommitted working-copy changes
288
        #[arg(long)]
289
        discard: bool,
290
        /// Take uncommitted changes along; refused when the target has
291
        /// other versions of the files they touch
292
        #[arg(long, conflicts_with = "discard")]
293
        carry: bool,
294
    },
295
    /// Report which conflicts of the working copy's base are resolved by the current files
296
    Resolve {
297
        /// Machine-readable output: one JSON document on stdout
298
        #[arg(long)]
299
        json: bool,
300
    },
301
    /// Undo the last operation
302
    Undo,
303
    /// Write a checkpoint of the current bookmark's state now
304
    Checkpoint,
305
    /// Print a shell completion script: `oxy completions bash > ~/.local/share/bash-completion/completions/oxy`
306
    Completions {
307
        /// bash, zsh, fish, elvish or powershell
308
        shell: clap_complete::Shell,
309
    },
310
    /// Write man pages (oxy.1 and one per command) into DIR, or print oxy.1
311
    Man {
312
        /// Directory to write every page into, e.g. ~/.local/share/man/man1
313
        #[arg(long)]
314
        dir: Option<PathBuf>,
315
    },
316
    /// Check the identity, configuration and remotes, and say what to do about any problem
317
    Doctor {
318
        /// Do not contact the remotes
319
        #[arg(long)]
320
        offline: bool,
321
        /// Machine-readable output: one JSON document on stdout
322
        #[arg(long)]
323
        json: bool,
324
    },
325
    /// Check the repository's integrity: objects, operation log, references, signatures, checkpoints
326
    Fsck {
327
        /// Machine-readable output: one JSON document on stdout
328
        #[arg(long)]
329
        json: bool,
330
    },
331
    /// Prune unreachable objects older than the grace period and repack everything into one pack
332
    Gc {
333
        /// Ignore the grace period (core.gc-grace) and prune immediately
334
        #[arg(long)]
335
        now: bool,
336
        /// Keep no past working-copy snapshots, only each workspace's current one, so files only they held go (core.snapshot-retention, default 7 days)
337
        #[arg(long)]
338
        expire_snapshots: bool,
339
        /// Instead: fold the bundles of a remote kept on a store into one, and remove the ones a gc superseded 7 days ago (or now, with --now)
340
        #[arg(long, value_name = "NAME")]
341
        remote: Option<String>,
342
    },
343
    /// List operations
344
    #[command(name = "op")]
345
    Op {
346
        #[command(subcommand)]
347
        cmd: OpCmd,
348
    },
349
    /// Take the advisory local lock on a lockable file, making it writable
350
    Lock {
351
        /// The lockable file
352
        path: String,
353
    },
354
    /// Release the local lock and make the file read-only again
355
    Unlock {
356
        /// The locked file
357
        path: String,
358
    },
359
    /// Workspaces: extra checkout directories sharing this repository
360
    Workspace {
361
        #[command(subcommand)]
362
        cmd: WorkspaceCmd,
363
    },
364
    /// Bookmarks: named states; each workspace works on one
365
    Bookmark {
366
        #[command(subcommand)]
367
        cmd: BookmarkCmd,
368
    },
369
    /// Union another bookmark's heads into the current one (no merge change)
370
    Merge {
371
        /// The bookmark whose heads to add
372
        bookmark: String,
373
    },
374
    /// Sign in to a hub once, for every repository on it
375
    Auth {
376
        #[command(subcommand)]
377
        cmd: AuthCmd,
378
    },
379
    /// Subrepositories: nested repositories pinned to a state
380
    Submodule {
381
        #[command(subcommand)]
382
        cmd: SubmoduleCmd,
383
    },
384
    /// Hubs' transparency logs: check that a hub shows everyone the same
385
    /// history (spec §14.8)
386
    Tlog {
387
        #[command(subcommand)]
388
        cmd: TlogCmd,
389
    },
390
    /// Execution receipts: signed records of what a runner ran on a state
391
    Receipt {
392
        #[command(subcommand)]
393
        cmd: ReceiptCmd,
394
    },
395
    /// Tags: immutable named states
396
    Tag {
397
        #[command(subcommand)]
398
        cmd: TagCmd,
399
    },
400
    /// Manage remotes
401
    Remote {
402
        #[command(subcommand)]
403
        cmd: RemoteCmd,
404
    },
405
    /// Fetch every bookmark of a remote into its tracking references
406
    Fetch {
407
        /// Remote name (default: origin)
408
        remote: Option<String>,
409
        /// Machine-readable output: one JSON document on stdout
410
        #[arg(long)]
411
        json: bool,
412
    },
413
    /// Fetch, then union the remote bookmark into the local one (no merge change)
414
    Pull {
415
        /// Remote name (default: origin)
416
        remote: Option<String>,
417
        /// Machine-readable output: one JSON document on stdout
418
        #[arg(long)]
419
        json: bool,
420
    },
421
    /// Push the current bookmark to a remote
422
    Push {
423
        /// Remote name (default: origin)
424
        remote: Option<String>,
425
        /// Allow dropping heads the remote has
426
        #[arg(long)]
427
        force: bool,
428
        /// Push this bookmark instead of the workspace's current one
429
        #[arg(short = 'b', long)]
430
        bookmark: Option<String>,
431
        /// Delete this bookmark on the remote (never its default bookmark);
432
        /// the local bookmark is kept
433
        #[arg(long, value_name = "NAME", conflicts_with_all = ["bookmark", "force"])]
434
        delete: Option<String>,
435
        /// Machine-readable output: one JSON document on stdout
436
        #[arg(long)]
437
        json: bool,
438
    },
439
    /// Serve repositories under ROOT over HTTPS (with --tls-cert/--tls-key) or plain HTTP
440
    Serve {
441
        /// Directory with one repository per subdirectory
442
        #[arg(long, default_value = ".")]
443
        root: PathBuf,
444
        /// Address and port to listen on
445
        #[arg(long, default_value = "127.0.0.1:8890")]
446
        bind: String,
447
        /// Bearer token allowed to push (repeatable); none means open
448
        #[arg(long = "token")]
449
        tokens: Vec<String>,
450
        /// PEM certificate chain; enables HTTPS together with --tls-key
451
        #[arg(long, requires = "tls_key")]
452
        tls_cert: Option<PathBuf>,
453
        /// PEM private key
454
        #[arg(long, requires = "tls_cert")]
455
        tls_key: Option<PathBuf>,
456
    },
457
    /// Manage the signing identity
458
    Identity {
459
        #[command(subcommand)]
460
        cmd: IdentityCmd,
461
    },
462
    /// Seal changes with your key: named ones, or every change on the current bookmark you can authenticate but have not
463
    Seal {
464
        /// Changes to seal (default: every change on the bookmark you can authenticate and have not sealed)
465
        changes: Vec<String>,
466
        /// Seal every change of a hub proposal and push the seal (your approval)
467
        #[arg(long, conflicts_with = "changes")]
468
        proposal: Option<String>,
469
        /// Approve a job of a hub run that waits for a sealed approval: `--flow https://hub/OWNER/NAME/flow/N --job apply`
470
        #[arg(long, conflicts_with_all = ["changes", "proposal"], requires = "job")]
471
        flow: Option<String>,
472
        /// The job to approve, with --flow
473
        #[arg(long, requires = "flow")]
474
        job: Option<String>,
475
        /// Reject the job instead of approving it, with --flow
476
        #[arg(long, requires = "flow")]
477
        reject: bool,
478
        /// Machine-readable output: one JSON document on stdout
479
        #[arg(long)]
480
        json: bool,
481
    },
482
    /// Hub proposals: show one, or land it from this client
483
    Proposal {
484
        #[command(subcommand)]
485
        cmd: ProposalCmd,
486
    },
487
    /// Verify the signatures on a change (default: every change in the log)
488
    Verify {
489
        /// The change to verify (default: every change in the log)
490
        change: Option<String>,
491
        /// Verify every change a revset selects: `release..main & unsigned()`
492
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
493
        revset: Option<String>,
494
        /// Machine-readable output: one JSON document on stdout
495
        #[arg(long)]
496
        json: bool,
497
    },
498
    /// Git interoperability
499
    Git {
500
        #[command(subcommand)]
501
        cmd: GitCmd,
502
    },
503
    /// Manage the trust policy (who may update which bookmarks)
504
    Policy {
505
        #[command(subcommand)]
506
        cmd: PolicyCmd,
507
    },
508
    /// 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)
509
    Config {
510
        /// The key, such as author.name or remote.origin.token
511
        key: String,
512
        /// The value to set (none with --unset); `-` reads it from standard input, out of the shell's history
513
        #[arg(required_unless_present = "unset")]
514
        value: Option<String>,
515
        /// Write to the user file (~/.config/oxy/config.toml) instead of this repository
516
        #[arg(long)]
517
        user: bool,
518
        /// Remove the key from this repository's file (or the user file with --user)
519
        #[arg(long)]
520
        unset: bool,
521
    },
522
}
523
524
#[derive(Subcommand)]
525
enum OpCmd {
526
    /// List operations, newest first, with what each changed
527
    Log {
528
        /// Show only the latest N (snapshots folded together count as one)
529
        #[arg(short = 'n', long)]
530
        limit: Option<usize>,
531
        /// Machine-readable output: one JSON document on stdout
532
        #[arg(long)]
533
        json: bool,
534
    },
535
    /// Go back to the bookmarks and working copy as they were after OP (recorded as a new operation, so it can be undone)
536
    Restore {
537
        /// The operation: an ID prefix from oxy op log, @ or @-
538
        op: String,
539
        /// Throw away uncommitted working-copy changes
540
        #[arg(long)]
541
        discard: bool,
542
    },
543
    /// Undo OP alone, keeping every operation after it: the bookmarks it moved go back
544
    Revert {
545
        /// The operation: an ID prefix from oxy op log
546
        op: String,
547
    },
548
}
549
550
#[derive(Subcommand)]
551
enum WorkspaceCmd {
552
    /// Create a workspace at PATH checked out on CHANGE... (default: the bookmark heads)
553
    Add {
554
        /// Directory for the new workspace (must be empty or absent)
555
        path: PathBuf,
556
        /// Changes whose state to check out there
557
        changes: Vec<String>,
558
    },
559
    /// List workspaces and their working-copy changes
560
    List {
561
        /// Machine-readable output: one JSON document on stdout
562
        #[arg(long)]
563
        json: bool,
564
    },
565
    /// Stop tracking a workspace (by id prefix or path); its files stay
566
    Forget {
567
        /// Workspace id prefix or path
568
        workspace: String,
569
    },
570
}
571
572
#[derive(Subcommand)]
573
enum BisectCmd {
574
    /// Begin; remembers where the working copy was
575
    Start,
576
    /// Mark CHANGE... (or the state under test) as good
577
    Good {
578
        /// Changes known to be good (default: the state under test)
579
        changes: Vec<String>,
580
    },
581
    /// Mark CHANGE... (or the state under test) as bad
582
    Bad {
583
        /// Changes known to be bad (default: the state under test)
584
        changes: Vec<String>,
585
    },
586
    /// The state under test cannot be tested; try another
587
    Skip,
588
    /// Run a command for each step: exit 0 good, 125 skip, else bad
589
    Run {
590
        /// Command and arguments to run at each step
591
        #[arg(required = true, trailing_var_arg = true)]
592
        command: Vec<String>,
593
    },
594
    /// Where the search stands
595
    Status {
596
        /// Machine-readable output: one JSON document on stdout
597
        #[arg(long)]
598
        json: bool,
599
    },
600
    /// Restore the working copy and forget the search
601
    Reset,
602
}
603
604
#[derive(Subcommand)]
605
enum BookmarkCmd {
606
    /// Create a bookmark at CHANGE... (default: the working copy's base)
607
    Create {
608
        /// Name of the new bookmark
609
        name: String,
610
        /// Its heads (default: the working copy's base). A state is its
611
        /// heads and what they depend on: a change alone may leave out
612
        /// earlier changes of the current state, which is refused unless
613
        /// --upto or --only says which is meant
614
        changes: Vec<String>,
615
        /// Everything of the current state up to CHANGE..., as a Git
616
        /// branch at a commit would hold
617
        #[arg(long, conflicts_with = "only")]
618
        upto: bool,
619
        /// Just CHANGE... and what they depend on. Other changes to the
620
        /// same files are left out, so a file can come out partly edited;
621
        /// to add one change to a bookmark's work, give the bookmark's
622
        /// heads with it instead: `bookmark set NAME <its heads> CHANGE`
623
        #[arg(long)]
624
        only: bool,
625
    },
626
    /// Point an existing bookmark at CHANGE...
627
    Set {
628
        /// The bookmark to move
629
        name: String,
630
        /// Its new heads. A change alone may leave out changes the
631
        /// bookmark now holds that were recorded before it, which is
632
        /// refused unless --upto or --only says which is meant
633
        changes: Vec<String>,
634
        /// Everything the bookmark holds up to CHANGE..., as a Git branch
635
        /// moved to a commit would hold
636
        #[arg(long, conflicts_with = "only")]
637
        upto: bool,
638
        /// Just CHANGE... and what they depend on. Other changes to the
639
        /// same files are left out, so a file can come out partly edited;
640
        /// to add one change to a bookmark's work, give the bookmark's
641
        /// heads with it instead: `bookmark set NAME <its heads> CHANGE`
642
        #[arg(long)]
643
        only: bool,
644
    },
645
    /// Remove a bookmark; its changes stay
646
    Delete {
647
        /// The bookmark to remove
648
        name: String,
649
    },
650
    /// List bookmarks with their heads and difference from origin
651
    List {
652
        /// Also list remotes' bookmarks that have no local bookmark
653
        #[arg(long, short)]
654
        all: bool,
655
        /// Each head of every bookmark, as `bookmark show` prints them
656
        #[arg(long, short)]
657
        verbose: bool,
658
        /// Machine-readable output: one JSON document on stdout
659
        #[arg(long)]
660
        json: bool,
661
    },
662
    /// A bookmark's heads: each change nothing else on it depends on,
663
    /// newest first. A bookmark name is also a revset for its heads
664
    /// (`oxy log -r NAME`, or `bookmark(NAME)` to mean only the bookmark)
665
    Show {
666
        /// The bookmark, or REMOTE/NAME (default: the current one)
667
        name: Option<String>,
668
        /// Machine-readable output: one JSON document on stdout
669
        #[arg(long)]
670
        json: bool,
671
    },
672
    /// Make NAME this workspace's bookmark and check it out. Uncommitted work stops it; --carry takes the work along, --discard drops it
673
    Switch {
674
        /// The bookmark to work on; one only a remote has (NAME or REMOTE/NAME) is created from it
675
        name: String,
676
        /// Throw away uncommitted working-copy changes
677
        #[arg(long)]
678
        discard: bool,
679
        /// Take uncommitted changes along; refused when NAME has other
680
        /// versions of the files they touch
681
        #[arg(long, conflicts_with = "discard")]
682
        carry: bool,
683
    },
684
}
685
686
#[derive(Subcommand)]
687
enum TlogCmd {
688
    /// Check a hub's whole log: its checkpoint against the log key and the
689
    /// last checkpoint seen, and every entry against the root it signed;
690
    /// then list this repository's entries (or a key's, or all)
691
    Verify {
692
        /// The hub, as https://oxygenhub.io (default: this checkout's remote)
693
        hub: Option<String>,
694
        /// List the entries a key signed (a KeyId) instead
695
        #[arg(long, conflicts_with = "all")]
696
        key: Option<String>,
697
        /// List every entry
698
        #[arg(long)]
699
        all: bool,
700
        /// Machine-readable output
701
        #[arg(long)]
702
        json: bool,
703
    },
704
}
705
706
#[derive(Subcommand)]
707
enum AuthCmd {
708
    /// Sign in to HUB in the browser (device sign-in) and keep the token for
709
    /// every repository there
710
    Login {
711
        /// The hub, as https://oxygenhub.io or oxygenhub.io (default: this checkout's origin)
712
        hub: Option<String>,
713
        /// Read a token from standard input instead (for CI and scripts)
714
        #[arg(long)]
715
        with_token: bool,
716
        /// PEM file of extra roots to trust (a hub with a self-signed certificate)
717
        #[arg(long)]
718
        ca: Option<PathBuf>,
719
    },
720
    /// List the hubs you are signed in to, checking each token with its hub
721
    Status,
722
    /// Forget HUB's token and revoke it on the hub
723
    Logout {
724
        /// The hub (default: this checkout's origin, or the only one)
725
        hub: Option<String>,
726
    },
727
    /// Keep an agent grant token (from `oh agent grant`) for keyless
728
    /// signing: with `author.signer = keyless`, commits and pushes are
729
    /// signed by fresh keys the hub certifies, in the grantor's name
730
    /// (the token is read from standard input, so it stays out of the
731
    /// shell's history)
732
    Grant {
733
        /// The hub (default: this checkout's origin)
734
        hub: Option<String>,
735
    },
736
}
737
738
#[derive(Subcommand)]
739
enum SubmoduleCmd {
740
    /// Clone URL (Oxygen or Git) into PATH and register it in .oxymodules
741
    Add {
742
        /// URL or path of the Oxygen or Git repository
743
        url: String,
744
        /// Where to put it, relative to the repository root
745
        path: String,
746
        /// Bookmark (Oxygen) or branch (Git) to check out and track
747
        #[arg(long)]
748
        bookmark: Option<String>,
749
    },
750
    /// Bring nested repositories to their pins
751
    Update {
752
        /// Clone nested repositories that are absent
753
        #[arg(long)]
754
        init: bool,
755
        /// Subrepos to update (default: all)
756
        paths: Vec<String>,
757
    },
758
    /// List subrepos with their pins and on-disk state
759
    Status {
760
        /// Machine-readable output: one JSON document on stdout
761
        #[arg(long)]
762
        json: bool,
763
    },
764
    /// Unregister PATH; the directory stays, the node goes with the next commit
765
    Remove {
766
        /// The subrepo to unregister
767
        path: String,
768
    },
769
}
770
771
#[derive(Subcommand)]
772
enum ReceiptCmd {
773
    /// The receipts kept for a state (default: the bookmark heads)
774
    List {
775
        /// Change, bookmark or tag whose state to look at
776
        rev: Option<String>,
777
        /// Machine-readable output: one JSON document on stdout
778
        #[arg(long)]
779
        json: bool,
780
    },
781
    /// One receipt in full, and whether its signature verifies
782
    Show {
783
        /// The receipt (a prefix of its hash, as `list` shows it)
784
        receipt: String,
785
        /// Change, bookmark or tag whose state holds it
786
        #[arg(long)]
787
        rev: Option<String>,
788
        /// Machine-readable output: one JSON document on stdout
789
        #[arg(long)]
790
        json: bool,
791
    },
792
    /// Write a signed receipt to FILE
793
    Export {
794
        /// The receipt (a prefix of its hash, as `list` shows it)
795
        receipt: String,
796
        /// Where to write it
797
        file: String,
798
        /// Change, bookmark or tag whose state holds it
799
        #[arg(long)]
800
        rev: Option<String>,
801
        /// `oxygen`: the runner's signed receipt, as `verify` and `import`
802
        /// read it. `slsa`: SLSA provenance in a DSSE envelope, signed with
803
        /// your key, for in-toto and cosign (`oxy identity export --pem`
804
        /// gives the key they check it with)
805
        #[arg(long, default_value = "oxygen", value_parser = ["oxygen", "slsa"])]
806
        format: String,
807
    },
808
    /// Check a signed receipt in FILE without keeping it
809
    Verify {
810
        /// A signed receipt, as a runner or `export` writes it
811
        file: String,
812
        /// Machine-readable output: one JSON document on stdout
813
        #[arg(long)]
814
        json: bool,
815
    },
816
    /// Verify a signed receipt in FILE and keep it with its state
817
    Import {
818
        /// A signed receipt, as a runner or `export` writes it
819
        file: String,
820
    },
821
}
822
823
#[derive(Subcommand)]
824
enum TagCmd {
825
    /// Tag the state of CHANGE... (default: the bookmark heads)
826
    Create {
827
        /// Name of the tag; tags never move
828
        name: String,
829
        /// Changes whose state to tag (default: the bookmark heads)
830
        changes: Vec<String>,
831
        /// A message recorded with the tag
832
        #[arg(short, long, default_value = "")]
833
        message: String,
834
    },
835
    /// List tags and the states they name
836
    List {
837
        /// Machine-readable output: one JSON document on stdout
838
        #[arg(long)]
839
        json: bool,
840
    },
841
}
842
843
#[derive(Subcommand)]
844
enum RemoteCmd {
845
    /// Add a remote
846
    Add {
847
        /// Name to refer to the remote by, such as origin
848
        name: String,
849
        /// 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
850
        url: String,
851
        /// For an s3:// store: the AWS profile to use (default: AWS_PROFILE, else "default")
852
        #[arg(long)]
853
        profile: Option<String>,
854
        /// For an s3:// store: its region (default: the environment, the profile, else asked of S3)
855
        #[arg(long)]
856
        region: Option<String>,
857
        /// For an s3://, gs:// or az:// store: another endpoint, such as an S3-compatible service
858
        #[arg(long)]
859
        endpoint: Option<String>,
860
        /// For a gs:// store: a service account key file, or application default credentials
861
        #[arg(long)]
862
        credentials: Option<String>,
863
    },
864
    /// Check a remote: that it is reachable with the credentials in hand, what it holds, and (for a store) that it behaves
865
    Check {
866
        /// The remote to check
867
        name: String,
868
    },
869
    /// Remove a remote
870
    Remove {
871
        /// The remote to remove
872
        name: String,
873
    },
874
    /// List remotes and their URLs
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 ProposalCmd {
884
    /// Show a proposal by its hub URL
885
    Show {
886
        /// The proposal's URL on the hub
887
        url: String,
888
        /// Machine-readable output: one JSON document on stdout
889
        #[arg(long)]
890
        json: bool,
891
    },
892
    /// Fetch the proposal's changes, set the target bookmark to the projected state, and push with your key
893
    Land {
894
        /// The proposal's URL on the hub
895
        url: String,
896
        /// Land even when the hub reports blockers
897
        #[arg(long)]
898
        force: bool,
899
    },
900
}
901
902
#[derive(Subcommand)]
903
enum IdentityCmd {
904
    /// Generate a composite Ed25519 + ML-DSA-65 key pair and make it your author identity
905
    Create {
906
        /// Your name (default: author.name)
907
        #[arg(long)]
908
        name: Option<String>,
909
        /// Your email (default: author.email)
910
        #[arg(long)]
911
        email: Option<String>,
912
        /// Record the author in this repository only, not in the user config
913
        #[arg(long)]
914
        local: bool,
915
        /// Expire the identity this many days from now
916
        #[arg(long)]
917
        expires: Option<u64>,
918
    },
919
    /// Show the configured identity
920
    Show,
921
    /// Write your identity object to a file, to hand to a policy holder
922
    Export {
923
        /// File to write (default: <key>.identity, or <key>.pem with --pem, in the current directory)
924
        path: Option<PathBuf>,
925
        /// Write the Ed25519 public key as PEM instead, as cosign's --key and
926
        /// other DSSE verifiers take it
927
        #[arg(long)]
928
        pem: bool,
929
    },
930
    /// Sign a host's challenge (hex, at least 16 bytes) to prove you hold your key; prints the signature as hex
931
    SignChallenge {
932
        /// The host's challenge, as hex
933
        challenge: String,
934
        /// Machine-readable output: one JSON document on stdout
935
        #[arg(long)]
936
        json: bool,
937
    },
938
    /// Move to a fresh key pair; the policy follows if it names your key
939
    Rotate,
940
    /// Re-issue your identity with a new expiry (in days from now; 0 = never)
941
    Renew {
942
        /// Days from now until it expires; 0 for never
943
        #[arg(long)]
944
        expires: u64,
945
    },
946
    /// Revoke a key: yours by default, or any key if you hold a policy root
947
    Revoke {
948
        /// KeyId prefix (default: your own key)
949
        key: Option<String>,
950
        /// Why, recorded in the revocation
951
        #[arg(long, default_value = "")]
952
        reason: String,
953
    },
954
    /// Keys allowed to sign or seal on your behalf
955
    Delegate {
956
        #[command(subcommand)]
957
        cmd: DelegateCmd,
958
    },
959
}
960
961
#[derive(Subcommand)]
962
enum DelegateCmd {
963
    /// Add a delegate from an exported identity file
964
    Add {
965
        /// The delegates' exported identity files: one rotation for all of them
966
        #[arg(required = true)]
967
        identity_file: Vec<PathBuf>,
968
        /// What it may do for you: changes, refs, seal (comma-separated) or all.
969
        /// An agent gets `changes`; a host that lands for you needs `changes,refs`
970
        #[arg(long, default_value = "changes")]
971
        scope: String,
972
        /// How long for: 30m, 8h, 7d, or a number of days (default: until removed)
973
        #[arg(long)]
974
        expires: Option<String>,
975
    },
976
    /// Remove a delegate by KeyId prefix
977
    Remove {
978
        /// KeyId prefix of the delegate
979
        key: String,
980
    },
981
    /// List delegates
982
    List,
983
}
984
985
#[derive(Subcommand)]
986
enum GitCmd {
987
    /// Export the current bookmark to a Git repository (created bare if absent)
988
    Export {
989
        /// Git repository to write to (created bare if absent)
990
        git_dir: PathBuf,
991
        /// Git branch to write (default: the bookmark name)
992
        #[arg(long)]
993
        branch: Option<String>,
994
    },
995
    /// Fetch a branch from a Git remote (path or URL) into the current bookmark
996
    Fetch {
997
        /// Git remote: a path or URL
998
        url: String,
999
        /// Branch to fetch
1000
        #[arg(long, default_value = "main")]
1001
        branch: String,
1002
        /// Author your own commits (Git author email = your identity's) with your key; sets git.claim
1003
        #[arg(long)]
1004
        claim: bool,
1005
    },
1006
    /// Push the current bookmark to a branch of a Git remote (fetch first)
1007
    Push {
1008
        /// Git remote: a path or URL
1009
        url: String,
1010
        /// Branch to push to
1011
        #[arg(long, default_value = "main")]
1012
        branch: String,
1013
    },
1014
    /// 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
1015
    Recover,
1016
    /// Check this repository's import of a Git branch: every commit's tree must be reproduced exactly
1017
    Verify {
1018
        /// The Git repository the import came from
1019
        git_dir: PathBuf,
1020
        /// Branch that was imported
1021
        #[arg(long, default_value = "main")]
1022
        branch: String,
1023
        /// Rebuild only the last N commits (the others are followed, not checked)
1024
        #[arg(long, value_name = "N")]
1025
        last: Option<usize>,
1026
        /// Stop after N differences (0: check every commit whatever it finds)
1027
        #[arg(long, value_name = "N", default_value_t = 50)]
1028
        max_differences: usize,
1029
    },
1030
    /// Import a Git branch into a new Oxygen repository at DEST
1031
    Import {
1032
        /// Git repository to read
1033
        git_dir: PathBuf,
1034
        /// Directory for the new Oxygen repository
1035
        dest: PathBuf,
1036
        /// Branch to import
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
}
1044
1045
#[derive(Subcommand)]
1046
enum PolicyCmd {
1047
    /// Create the initial policy with your identity as the only root
1048
    Init,
1049
    /// Show the current policy
1050
    Show {
1051
        /// Machine-readable output: one JSON document on stdout
1052
        #[arg(long)]
1053
        json: bool,
1054
    },
1055
    /// Allow an identity (from `oxy identity export`) to update bookmarks
1056
    Grant {
1057
        /// The identity to grant, exported with `oxy identity export`
1058
        identity_file: PathBuf,
1059
        /// Reference pattern the grant applies to (default: every bookmark)
1060
        #[arg(long)]
1061
        pattern: Option<String>,
1062
        /// Where to write the proposal when more root signatures are needed
1063
        #[arg(long)]
1064
        out: Option<PathBuf>,
1065
    },
1066
    /// Allow holders of an issuer's certificates for SUBJECT to sign (keyless)
1067
    GrantSubject {
1068
        /// Who: `repo:OWNER/NAME:bookmark:main`, `agent:NAME@ACCOUNT`; `*` matches any run of characters
1069
        subject: String,
1070
        /// The issuer's identity file, e.g. a hub's /.well-known/oxyhub-key
1071
        #[arg(long)]
1072
        issuer: PathBuf,
1073
        /// What its keys may sign: changes, refs, seal
1074
        #[arg(long, default_value = "changes,refs")]
1075
        scope: String,
1076
        /// Reference pattern the grant applies to (default: every bookmark)
1077
        #[arg(long)]
1078
        pattern: Option<String>,
1079
        /// Where to write the proposal when more root signatures are needed
1080
        #[arg(long)]
1081
        out: Option<PathBuf>,
1082
    },
1083
    /// Revoke a key (KeyId prefix of an identity in the policy)
1084
    Revoke {
1085
        /// KeyId prefix of the identity
1086
        key: String,
1087
        /// Where to write the proposal when more root signatures are needed
1088
        #[arg(long)]
1089
        out: Option<PathBuf>,
1090
    },
1091
    /// Manage root keys and the signature threshold for policy updates
1092
    Root {
1093
        #[command(subcommand)]
1094
        cmd: RootCmd,
1095
    },
1096
    /// Add your root signature to a proposal file; applies it once the threshold is met
1097
    Sign {
1098
        /// The proposal file to sign
1099
        proposal: PathBuf,
1100
        /// Where to write the proposal if it still needs signatures (default: in place)
1101
        #[arg(long)]
1102
        out: Option<PathBuf>,
1103
    },
1104
}
1105
1106
#[derive(Subcommand)]
1107
enum RootCmd {
1108
    /// Make an exported identity a root key
1109
    Add {
1110
        /// The identity to make a root, exported with `oxy identity export`
1111
        identity_file: PathBuf,
1112
        /// Where to write the proposal when more root signatures are needed
1113
        #[arg(long)]
1114
        out: Option<PathBuf>,
1115
    },
1116
    /// Remove a root key by KeyId prefix
1117
    Remove {
1118
        /// KeyId prefix of the root key
1119
        key: String,
1120
        /// Where to write the proposal when more root signatures are needed
1121
        #[arg(long)]
1122
        out: Option<PathBuf>,
1123
    },
1124
    /// Require this many root signatures on policy updates
1125
    Threshold {
1126
        /// Number of root signatures
1127
        n: u32,
1128
        /// Where to write the proposal when more root signatures are needed
1129
        #[arg(long)]
1130
        out: Option<PathBuf>,
1131
    },
1132
}
1133
1134
/// Open the repository containing the current directory.
1135121×
fn open() -> Result<Repo> {
1136121×
    let repo = Repo::open(&std::env::current_dir()?).context("opening repository")?;
1137121×
    match AT_OP.get().and_then(|o| o.as_deref()) {
11380×
        Some(op) => Ok(repo.at_op(op)?),
1139121×
        None => Ok(repo),
1140
    }
1141121×
}
1142
1143
/// `oxy man`: every page into `dir`, or the top-level page on stdout.
11442×
fn man(dir: Option<PathBuf>) -> Result<i32> {
1145
    use clap::CommandFactory;
11462×
    let cmd = Cli::command();
11472×
    match dir {
11481×
        Some(dir) => {
11491×
            std::fs::create_dir_all(&dir)?;
11501×
            clap_mangen::generate_to(cmd, &dir)?;
11511×
            let pages = std::fs::read_dir(&dir)?
1152124×
                .filter(|e| {
1153124×
                    e.as_ref()
1154124×
                        .is_ok_and(|e| e.path().extension().is_some_and(|x| x == "1"))
1155124×
                })
11561×
                .count();
11571×
            println!(
1158
                "{}",
11591×
                ui::done(format!("Wrote {pages} man pages to {}", dir.display()))
1160
            );
1161
        }
11621×
        None => clap_mangen::Man::new(cmd).render(&mut std::io::stdout())?,
1163
    }
11642×
    Ok(0)
11652×
}
1166
1167
/// Parse arguments and run; returns the process exit code.
1168151×
pub fn run() -> Result<i32> {
1169
    // The cloud stores (s3://, gs://, az://) for remotes kept on them.
1170151×
    oxy_strata::register();
1171151×
    let cli = Cli::parse();
1172151×
    ui::init(cli.plain);
1173151×
    AT_OP.set(cli.at_op.clone()).ok();
11740×
    match cli.cmd {
11754×
        Cmd::Completions { shell } => {
1176
            use clap::CommandFactory;
11774×
            clap_complete::generate(shell, &mut Cli::command(), "oxy", &mut std::io::stdout());
11784×
            Ok(0)
1179
        }
11802×
        Cmd::Man { dir } => man(dir),
118114×
        Cmd::Init { path, bare, store } => workspace::init(path, bare, store.as_deref()),
11828×
        Cmd::Status { json } => workspace::status(json),
1183
        Cmd::Prompt {
11840×
            format,
11850×
            glyphs,
11860×
            color,
11870×
        } => workspace::prompt(&format, glyphs, color.as_deref()),
1188
        Cmd::Commit {
118926×
            message,
119026×
            file,
119126×
            depends_on,
119226×
            paths,
119326×
            interactive,
119426×
            hunks,
1195
        } => {
119626×
            let message = match (message, file) {
119725×
                (Some(m), _) => m,
11981×
                (None, Some(f)) if f.as_os_str() == "-" => {
11990×
                    let mut s = String::new();
12000×
                    std::io::Read::read_to_string(&mut std::io::stdin(), &mut s)?;
12010×
                    s
1202
                }
12031×
                (None, Some(f)) => std::fs::read_to_string(&f).map_err(|e| {
12040×
                    anyhow::anyhow!("reading the message from {}: {e}", f.display())
12050×
                })?,
12060×
                (None, None) => anyhow::bail!("a commit message is required (-m or -F)"),
1207
            };
120826×
            workspace::commit(&message, &depends_on, &paths, interactive, &hunks)
1209
        }
12102×
        Cmd::Cat { path, change } => workspace::cat(&path, change.as_deref()),
12111×
        Cmd::Root { json } => workspace::root(json),
12121×
        Cmd::Version { json } => workspace::version(json),
12132×
        Cmd::Discard { paths, hunks } => workspace::discard(&paths, &hunks),
12142×
        Cmd::Hunks { json } => workspace::hunks(json),
12150×
        Cmd::Squash { change, into } => workspace::squash(&change, &into),
1216
        Cmd::Rebase {
12170×
            change,
12180×
            onto,
12190×
            into_working_copy,
12200×
        } => workspace::rebase(&change, &onto, into_working_copy),
12210×
        Cmd::Blame { path, json } => workspace::blame(&path, json),
12221×
        Cmd::Bisect { cmd } => match cmd {
12230×
            BisectCmd::Start => workspace::bisect_start(),
12240×
            BisectCmd::Good { changes } => workspace::bisect_mark(Some(true), &changes),
12250×
            BisectCmd::Bad { changes } => workspace::bisect_mark(Some(false), &changes),
12260×
            BisectCmd::Skip => workspace::bisect_mark(None, &[]),
12270×
            BisectCmd::Run { command } => workspace::bisect_run(&command),
12281×
            BisectCmd::Status { json } => workspace::bisect_status(json),
12290×
            BisectCmd::Reset => workspace::bisect_reset(),
1230
        },
1231
        Cmd::Log {
12328×
            revset,
12338×
            limit,
12348×
            verbose,
12358×
            path,
12368×
            lines,
12378×
            json,
12388×
        } => workspace::log(
12398×
            revset.as_deref(),
12408×
            limit,
12418×
            verbose,
12428×
            path.as_deref(),
12438×
            lines.as_deref(),
12448×
            json,
1245
        ),
12461×
        Cmd::Diff { change, json } => workspace::diff(change.as_deref(), json),
1247
        Cmd::Describe {
12484×
            message,
12494×
            change,
12504×
            json,
12514×
        } => match message {
12520×
            Some(m) => workspace::describe(&m, change.as_deref()),
12534×
            None if change.is_some() => {
12540×
                anyhow::bail!(
1255
                    "naming works on the working copy; to change a head's message pass -m"
1256
                )
1257
            }
12584×
            None => workspace::describe_name(json),
1259
        },
12600×
        Cmd::Amend { message, into } => workspace::amend(message.as_deref(), into.as_deref()),
12610×
        Cmd::Split { change, paths } => workspace::split(&change, &paths),
1262
        Cmd::Abandon {
12630×
            change,
12640×
            revset,
12650×
            yes,
12660×
        } => workspace::abandon(change.as_deref(), revset.as_deref(), yes),
1267
        Cmd::Show {
12682×
            change,
12692×
            revset,
12702×
            json,
12712×
        } => workspace::show(change.as_deref(), revset.as_deref(), json),
1272
        Cmd::Checkout {
12730×
            changes,
12740×
            discard,
12750×
            carry,
12760×
        } => workspace::checkout(&changes, discard, carry),
12771×
        Cmd::Resolve { json } => workspace::resolve(json),
12780×
        Cmd::Undo => workspace::undo(),
1279
        Cmd::Gc {
12802×
            now,
12812×
            expire_snapshots,
12822×
            remote,
12832×
        } => match remote {
12842×
            Some(name) => workspace::gc_remote(&name, now),
12850×
            None => workspace::gc(now, expire_snapshots),
1286
        },
12870×
        Cmd::Fsck { json } => workspace::fsck(json),
12880×
        Cmd::Doctor { offline, json } => workspace::doctor(offline, json),
12890×
        Cmd::Checkpoint => workspace::checkpoint(),
12901×
        Cmd::Op { cmd } => match cmd {
12911×
            OpCmd::Log { limit, json } => workspace::op_log(limit, json),
12920×
            OpCmd::Restore { op, discard } => workspace::op_restore(&op, discard),
12930×
            OpCmd::Revert { op } => workspace::op_revert(&op),
1294
        },
1295
        Cmd::Clone {
12965×
            url,
12975×
            dest,
12985×
            max_blob,
12995×
            sparse,
13005×
            depth,
13015×
            recursive,
13025×
        } => sync::clone(&url, dest, max_blob.as_deref(), &sparse, depth, recursive),
13030×
        Cmd::Deepen { depth, remote } => sync::deepen(&remote, depth),
13040×
        Cmd::Sparse { paths } => workspace::sparse(&paths),
13050×
        Cmd::Lock { path } => workspace::lock(&path),
13060×
        Cmd::Unlock { path } => workspace::unlock(&path),
13071×
        Cmd::Workspace { cmd } => match cmd {
13080×
            WorkspaceCmd::Add { path, changes } => workspace::workspace_add(&path, &changes),
13091×
            WorkspaceCmd::List { json } => workspace::workspace_list(json),
13100×
            WorkspaceCmd::Forget { workspace } => workspace::workspace_forget(&workspace),
1311
        },
131217×
        Cmd::Bookmark { cmd } => match cmd {
1313
            BookmarkCmd::Create {
13146×
                name,
13156×
                changes,
13166×
                upto,
13176×
                only,
13186×
            } => workspace::bookmark_create(&name, &changes, upto, only),
1319
            BookmarkCmd::Set {
13203×
                name,
13213×
                changes,
13223×
                upto,
13233×
                only,
13243×
            } => workspace::bookmark_set(&name, &changes, upto, only),
13250×
            BookmarkCmd::Delete { name } => workspace::bookmark_delete(&name),
13265×
            BookmarkCmd::List { all, verbose, json } => {
13275×
                workspace::bookmark_list(all, verbose, json)
1328
            }
13290×
            BookmarkCmd::Show { name, json } => workspace::bookmark_show(name.as_deref(), json),
1330
            BookmarkCmd::Switch {
13313×
                name,
13323×
                discard,
13333×
                carry,
13343×
            } => workspace::bookmark_switch(&name, discard, carry),
1335
        },
13360×
        Cmd::Merge { bookmark } => workspace::merge(&bookmark),
13370×
        Cmd::Auth { cmd } => match cmd {
1338
            AuthCmd::Login {
13390×
                hub,
13400×
                with_token,
13410×
                ca,
13420×
            } => auth::login(hub.as_deref(), with_token, ca),
13430×
            AuthCmd::Status => auth::status(),
13440×
            AuthCmd::Logout { hub } => auth::logout(hub.as_deref()),
13450×
            AuthCmd::Grant { hub } => auth::grant(hub.as_deref()),
1346
        },
13471×
        Cmd::Submodule { cmd } => match cmd {
1348
            SubmoduleCmd::Add {
13490×
                url,
13500×
                path,
13510×
                bookmark,
13520×
            } => sync::submodule_add(&url, &path, bookmark.as_deref()),
13530×
            SubmoduleCmd::Update { init, paths } => sync::submodule_update(init, &paths),
13541×
            SubmoduleCmd::Status { json } => sync::submodule_status(json),
13550×
            SubmoduleCmd::Remove { path } => sync::submodule_remove(&path),
1356
        },
13570×
        Cmd::Tlog { cmd } => match cmd {
1358
            TlogCmd::Verify {
13590×
                hub,
13600×
                key,
13610×
                all,
13620×
                json,
13630×
            } => tlog::verify(hub.as_deref(), key.as_deref(), all, json),
1364
        },
136510×
        Cmd::Receipt { cmd } => match cmd {
13662×
            ReceiptCmd::List { rev, json } => receipt::list(rev.as_deref(), json),
1367
            ReceiptCmd::Show {
13681×
                receipt: r,
13691×
                rev,
13701×
                json,
13711×
            } => receipt::show(&r, rev.as_deref(), json),
1372
            ReceiptCmd::Export {
13733×
                receipt: r,
13743×
                file,
13753×
                rev,
13763×
                format,
13773×
            } => receipt::export(&r, &file, rev.as_deref(), &format),
13782×
            ReceiptCmd::Verify { file, json } => receipt::verify(&file, json),
13792×
            ReceiptCmd::Import { file } => receipt::import(&file),
1380
        },
13813×
        Cmd::Tag { cmd } => match cmd {
1382
            TagCmd::Create {
13832×
                name,
13842×
                changes,
13852×
                message,
13862×
            } => workspace::tag_create(&name, &changes, &message),
13871×
            TagCmd::List { json } => workspace::tag_list(json),
1388
        },
138910×
        Cmd::Remote { cmd } => match cmd {
1390
            RemoteCmd::Add {
13914×
                name,
13924×
                url,
13934×
                profile,
13944×
                region,
13954×
                endpoint,
13964×
                credentials,
13974×
            } => sync::remote_add(
13984×
                &name,
13994×
                &url,
14004×
                &[
14014×
                    ("profile", profile),
14024×
                    ("region", region),
14034×
                    ("endpoint", endpoint),
14044×
                    ("credentials", credentials),
14054×
                ],
1406
            ),
14073×
            RemoteCmd::Check { name } => sync::remote_check(&name),
14081×
            RemoteCmd::Remove { name } => sync::remote_remove(&name),
14092×
            RemoteCmd::List { json } => sync::remote_list(json),
1410
        },
14111×
        Cmd::Fetch { remote, json } => sync::fetch(remote.as_deref(), json),
14124×
        Cmd::Pull { remote, json } => sync::pull(remote.as_deref(), json),
1413
        Cmd::Push {
14147×
            remote,
14157×
            force,
14167×
            bookmark,
14177×
            delete,
14187×
            json,
14197×
        } => match delete {
14200×
            Some(name) => sync::push_delete(remote.as_deref(), &name, json),
14217×
            None => sync::push(remote.as_deref(), force, bookmark.as_deref(), json),
1422
        },
1423
        Cmd::Serve {
14240×
            root,
14250×
            bind,
14260×
            tokens,
14270×
            tls_cert,
14280×
            tls_key,
14290×
        } => sync::serve(root, &bind, tokens, tls_cert.zip(tls_key)),
14303×
        Cmd::Identity { cmd } => match cmd {
1431
            IdentityCmd::Create {
14322×
                name,
14332×
                email,
14342×
                local,
14352×
                expires,
14362×
            } => identity::create(name, email, local, expires),
14370×
            IdentityCmd::Show => identity::show(),
14381×
            IdentityCmd::Export { path, pem } => identity::export(path, pem),
14390×
            IdentityCmd::SignChallenge { challenge, json } => {
14400×
                identity::sign_challenge(&challenge, json)
1441
            }
14420×
            IdentityCmd::Rotate => identity::rotate(),
14430×
            IdentityCmd::Renew { expires } => identity::renew(expires),
14440×
            IdentityCmd::Revoke { key, reason } => identity::revoke(key.as_deref(), &reason),
14450×
            IdentityCmd::Delegate { cmd } => match cmd {
1446
                DelegateCmd::Add {
14470×
                    identity_file,
14480×
                    scope,
14490×
                    expires,
14500×
                } => identity::delegate_add(&identity_file, &scope, expires.as_deref()),
14510×
                DelegateCmd::Remove { key } => identity::delegate_remove(&key),
14520×
                DelegateCmd::List => identity::delegate_list(),
1453
            },
1454
        },
1455
        Cmd::Git {
14560×
            cmd: GitCmd::Export { git_dir, branch },
14570×
        } => sync::git_export(&git_dir, branch.as_deref()),
1458
        Cmd::Git {
14590×
            cmd: GitCmd::Fetch { url, branch, claim },
14600×
        } => sync::git_fetch(&url, &branch, claim),
1461
        Cmd::Git {
14620×
            cmd: GitCmd::Push { url, branch },
14630×
        } => sync::git_push(&url, &branch),
1464
        Cmd::Git {
1465
            cmd: GitCmd::Recover,
14660×
        } => sync::git_recover(),
1467
        Cmd::Git {
1468
            cmd:
1469
                GitCmd::Import {
14700×
                    git_dir,
14710×
                    dest,
14720×
                    branch,
14730×
                    claim,
1474
                },
14750×
        } => sync::git_import(&git_dir, &dest, &branch, claim),
1476
        Cmd::Git {
1477
            cmd:
1478
                GitCmd::Verify {
14790×
                    git_dir,
14800×
                    branch,
14810×
                    last,
14820×
                    max_differences,
1483
                },
14840×
        } => sync::git_verify(&git_dir, &branch, last, max_differences),
14855×
        Cmd::Policy { cmd } => match cmd {
14861×
            PolicyCmd::Init => identity::policy_init(),
14873×
            PolicyCmd::Show { json } => identity::policy_show(json),
1488
            PolicyCmd::Grant {
14890×
                identity_file,
14900×
                pattern,
14910×
                out,
14920×
            } => identity::policy_grant(&identity_file, pattern.as_deref(), out),
1493
            PolicyCmd::GrantSubject {
14941×
                subject,
14951×
                issuer,
14961×
                scope,
14971×
                pattern,
14981×
                out,
14991×
            } => identity::policy_grant_subject(&subject, &issuer, &scope, pattern.as_deref(), out),
15000×
            PolicyCmd::Revoke { key, out } => identity::policy_revoke(&key, out),
15010×
            PolicyCmd::Root { cmd } => match cmd {
15020×
                RootCmd::Add { identity_file, out } => {
15030×
                    identity::policy_root_add(&identity_file, out)
1504
                }
15050×
                RootCmd::Remove { key, out } => identity::policy_root_remove(&key, out),
15060×
                RootCmd::Threshold { n, out } => identity::policy_threshold(n, out),
1507
            },
15080×
            PolicyCmd::Sign { proposal, out } => identity::policy_sign(&proposal, out),
1509
        },
1510
        Cmd::Seal {
15110×
            flow: Some(url),
15120×
            job: Some(job),
15130×
            reject,
15140×
            json,
1515
            ..
15160×
        } => approve::seal(&url, &job, reject, json),
1517
        Cmd::Seal {
15180×
            changes,
15190×
            proposal: Some(url),
15200×
            json,
1521
            ..
15220×
        } if changes.is_empty() => proposal::seal(&url, json),
15230×
        Cmd::Seal { changes, json, .. } => identity::seal(&changes, json),
15240×
        Cmd::Proposal { cmd } => match cmd {
15250×
            ProposalCmd::Show { url, json } => proposal::show(&url, json),
15260×
            ProposalCmd::Land { url, force } => proposal::land(&url, force),
1527
        },
1528
        Cmd::Verify {
15291×
            change,
15301×
            revset,
15311×
            json,
15321×
        } => identity::verify(change.as_deref(), revset.as_deref(), json),
1533
        Cmd::Config {
15341×
            key,
15351×
            value,
15361×
            user,
15371×
            unset,
15381×
        } => identity::config(&key, value.as_deref().unwrap_or(""), user, unset),
1539
    }
1540151×
}
1541
1542
#[cfg(test)]
1543
mod help_tests {
1544
    use super::Cli;
1545
    use clap::CommandFactory;
1546
1547
    /// Every command and every argument explains itself, so `--help`,
1548
    /// completions and the man pages are complete.
1549
    #[test]
15501×
    fn every_command_and_argument_has_help() {
1551124×
        fn walk(cmd: &clap::Command, path: &str, missing: &mut Vec<String>) {
1552124×
            let here = format!("{path} {}", cmd.get_name()).trim().to_string();
1553124×
            if cmd.get_about().is_none() && !path.is_empty() {
15540×
                missing.push(format!("{here} (command)"));
1555124×
            }
1556225×
            for a in cmd.get_arguments() {
1557225×
                let id = a.get_id().as_str();
1558225×
                if id == "help" || id == "version" || (a.is_global_set() && !path.is_empty()) {
15590×
                    continue;
1560225×
                }
1561225×
                if a.get_help().is_none() && a.get_long_help().is_none() {
15620×
                    missing.push(format!("{here} {id}"));
1563225×
                }
1564
            }
1565124×
            for sub in cmd.get_subcommands() {
1566123×
                walk(sub, &here, missing);
1567123×
            }
1568124×
        }
15691×
        let mut missing = Vec::new();
15701×
        walk(&Cli::command(), "", &mut missing);
15711×
        assert!(
15721×
            missing.is_empty(),
1573
            "{} without help:\n{}",
15740×
            missing.len(),
15750×
            missing.join("\n")
1576
        );
15771×
    }
1578
}