OXYGENHUB

Coverage / src/cli/mod.rs 58.6%

208 of 355 lines run, 9 of 18 functions · run #337 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
    /// a bookmark here, or a remote's (`origin/develop`) as last fetched
371
    Merge {
372
        /// The bookmark whose heads to add
373
        bookmark: String,
374
    },
375
    /// Sign in to a hub once, for every repository on it
376
    Auth {
377
        #[command(subcommand)]
378
        cmd: AuthCmd,
379
    },
380
    /// Subrepositories: nested repositories pinned to a state
381
    Submodule {
382
        #[command(subcommand)]
383
        cmd: SubmoduleCmd,
384
    },
385
    /// Witness hubs' transparency logs: cosign each checkpoint that extends
386
    /// the last one cosigned (spec §14.8)
387
    Witness {
388
        #[command(subcommand)]
389
        cmd: WitnessCmd,
390
    },
391
    /// Hubs' transparency logs: check that a hub shows everyone the same
392
    /// history (spec §14.8)
393
    Tlog {
394
        #[command(subcommand)]
395
        cmd: TlogCmd,
396
    },
397
    /// Execution receipts: signed records of what a runner ran on a state
398
    Receipt {
399
        #[command(subcommand)]
400
        cmd: ReceiptCmd,
401
    },
402
    /// Tags: immutable named states
403
    Tag {
404
        #[command(subcommand)]
405
        cmd: TagCmd,
406
    },
407
    /// Manage remotes
408
    Remote {
409
        #[command(subcommand)]
410
        cmd: RemoteCmd,
411
    },
412
    /// Fetch every bookmark of a remote into its tracking references
413
    Fetch {
414
        /// Remote name (default: origin)
415
        remote: Option<String>,
416
        /// Machine-readable output: one JSON document on stdout
417
        #[arg(long)]
418
        json: bool,
419
    },
420
    /// Fetch, then union the remote bookmark into the local one (no merge change)
421
    Pull {
422
        /// Remote name (default: origin)
423
        remote: Option<String>,
424
        /// Machine-readable output: one JSON document on stdout
425
        #[arg(long)]
426
        json: bool,
427
    },
428
    /// Push the current bookmark to a remote
429
    Push {
430
        /// Remote name (default: origin)
431
        remote: Option<String>,
432
        /// Allow dropping heads the remote has
433
        #[arg(long)]
434
        force: bool,
435
        /// Push this bookmark instead of the workspace's current one
436
        #[arg(short = 'b', long)]
437
        bookmark: Option<String>,
438
        /// Delete this bookmark on the remote (never its default bookmark);
439
        /// the local bookmark is kept
440
        #[arg(long, value_name = "NAME", conflicts_with_all = ["bookmark", "force"])]
441
        delete: Option<String>,
442
        /// Machine-readable output: one JSON document on stdout
443
        #[arg(long)]
444
        json: bool,
445
    },
446
    /// Serve repositories under ROOT over HTTPS (with --tls-cert/--tls-key) or plain HTTP
447
    Serve {
448
        /// Directory with one repository per subdirectory
449
        #[arg(long, default_value = ".")]
450
        root: PathBuf,
451
        /// Address and port to listen on
452
        #[arg(long, default_value = "127.0.0.1:8890")]
453
        bind: String,
454
        /// Bearer token allowed to push (repeatable); none means open
455
        #[arg(long = "token")]
456
        tokens: Vec<String>,
457
        /// PEM certificate chain; enables HTTPS together with --tls-key
458
        #[arg(long, requires = "tls_key")]
459
        tls_cert: Option<PathBuf>,
460
        /// PEM private key
461
        #[arg(long, requires = "tls_cert")]
462
        tls_key: Option<PathBuf>,
463
    },
464
    /// Manage the signing identity
465
    Identity {
466
        #[command(subcommand)]
467
        cmd: IdentityCmd,
468
    },
469
    /// Seal changes with your key: named ones, or every change on the current bookmark you can authenticate but have not
470
    Seal {
471
        /// Changes to seal (default: every change on the bookmark you can authenticate and have not sealed)
472
        changes: Vec<String>,
473
        /// Seal every change of a hub proposal and push the seal (your approval)
474
        #[arg(long, conflicts_with = "changes")]
475
        proposal: Option<String>,
476
        /// Approve a job of a hub run that waits for a sealed approval: `--flow https://hub/OWNER/NAME/flow/N --job apply`
477
        #[arg(long, conflicts_with_all = ["changes", "proposal"], requires = "job")]
478
        flow: Option<String>,
479
        /// The job to approve, with --flow
480
        #[arg(long, requires = "flow")]
481
        job: Option<String>,
482
        /// Reject the job instead of approving it, with --flow
483
        #[arg(long, requires = "flow")]
484
        reject: bool,
485
        /// Machine-readable output: one JSON document on stdout
486
        #[arg(long)]
487
        json: bool,
488
    },
489
    /// Hub proposals: show one, or land it from this client
490
    Proposal {
491
        #[command(subcommand)]
492
        cmd: ProposalCmd,
493
    },
494
    /// Verify the signatures on a change (default: every change in the log)
495
    Verify {
496
        /// The change to verify (default: every change in the log)
497
        change: Option<String>,
498
        /// Verify every change a revset selects: `release..main & unsigned()`
499
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
500
        revset: Option<String>,
501
        /// Machine-readable output: one JSON document on stdout
502
        #[arg(long)]
503
        json: bool,
504
    },
505
    /// Git interoperability
506
    Git {
507
        #[command(subcommand)]
508
        cmd: GitCmd,
509
    },
510
    /// Manage the trust policy (who may update which bookmarks)
511
    Policy {
512
        #[command(subcommand)]
513
        cmd: PolicyCmd,
514
    },
515
    /// 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)
516
    Config {
517
        /// The key, such as author.name or remote.origin.token
518
        key: String,
519
        /// The value to set (none with --unset); `-` reads it from standard input, out of the shell's history
520
        #[arg(required_unless_present = "unset")]
521
        value: Option<String>,
522
        /// Write to the user file (~/.config/oxy/config.toml) instead of this repository
523
        #[arg(long)]
524
        user: bool,
525
        /// Remove the key from this repository's file (or the user file with --user)
526
        #[arg(long)]
527
        unset: bool,
528
    },
529
}
530
531
#[derive(Subcommand)]
532
enum OpCmd {
533
    /// List operations, newest first, with what each changed
534
    Log {
535
        /// Show only the latest N (snapshots folded together count as one)
536
        #[arg(short = 'n', long)]
537
        limit: Option<usize>,
538
        /// Machine-readable output: one JSON document on stdout
539
        #[arg(long)]
540
        json: bool,
541
    },
542
    /// Go back to the bookmarks and working copy as they were after OP (recorded as a new operation, so it can be undone)
543
    Restore {
544
        /// The operation: an ID prefix from oxy op log, @ or @-
545
        op: String,
546
        /// Throw away uncommitted working-copy changes
547
        #[arg(long)]
548
        discard: bool,
549
    },
550
    /// Undo OP alone, keeping every operation after it: the bookmarks it moved go back
551
    Revert {
552
        /// The operation: an ID prefix from oxy op log
553
        op: String,
554
    },
555
}
556
557
#[derive(Subcommand)]
558
enum WorkspaceCmd {
559
    /// Create a workspace at PATH checked out on CHANGE... (default: the bookmark heads)
560
    Add {
561
        /// Directory for the new workspace (must be empty or absent)
562
        path: PathBuf,
563
        /// Changes whose state to check out there
564
        changes: Vec<String>,
565
    },
566
    /// List workspaces and their working-copy changes
567
    List {
568
        /// Machine-readable output: one JSON document on stdout
569
        #[arg(long)]
570
        json: bool,
571
    },
572
    /// Stop tracking a workspace (by id prefix or path); its files stay
573
    Forget {
574
        /// Workspace id prefix or path
575
        workspace: String,
576
    },
577
}
578
579
#[derive(Subcommand)]
580
enum BisectCmd {
581
    /// Begin; remembers where the working copy was
582
    Start,
583
    /// Mark CHANGE... (or the state under test) as good
584
    Good {
585
        /// Changes known to be good (default: the state under test)
586
        changes: Vec<String>,
587
    },
588
    /// Mark CHANGE... (or the state under test) as bad
589
    Bad {
590
        /// Changes known to be bad (default: the state under test)
591
        changes: Vec<String>,
592
    },
593
    /// The state under test cannot be tested; try another
594
    Skip,
595
    /// Run a command for each step: exit 0 good, 125 skip, else bad
596
    Run {
597
        /// Command and arguments to run at each step
598
        #[arg(required = true, trailing_var_arg = true)]
599
        command: Vec<String>,
600
    },
601
    /// Where the search stands
602
    Status {
603
        /// Machine-readable output: one JSON document on stdout
604
        #[arg(long)]
605
        json: bool,
606
    },
607
    /// Restore the working copy and forget the search
608
    Reset,
609
}
610
611
#[derive(Subcommand)]
612
enum BookmarkCmd {
613
    /// Create a bookmark at CHANGE... (default: the working copy's base)
614
    Create {
615
        /// Name of the new bookmark
616
        name: String,
617
        /// Its heads (default: the working copy's base). A state is its
618
        /// heads and what they depend on: a change alone may leave out
619
        /// earlier changes of the current state, which is refused unless
620
        /// --upto or --only says which is meant
621
        changes: Vec<String>,
622
        /// Everything of the current state up to CHANGE..., as a Git
623
        /// branch at a commit would hold
624
        #[arg(long, conflicts_with = "only")]
625
        upto: bool,
626
        /// Just CHANGE... and what they depend on. Other changes to the
627
        /// same files are left out, so a file can come out partly edited;
628
        /// to add one change to a bookmark's work, give the bookmark's
629
        /// heads with it instead: `bookmark set NAME <its heads> CHANGE`
630
        #[arg(long)]
631
        only: bool,
632
    },
633
    /// Point an existing bookmark at CHANGE...
634
    Set {
635
        /// The bookmark to move
636
        name: String,
637
        /// Its new heads. A change alone may leave out changes the
638
        /// bookmark now holds that were recorded before it, which is
639
        /// refused unless --upto or --only says which is meant
640
        changes: Vec<String>,
641
        /// Everything the bookmark holds up to CHANGE..., as a Git branch
642
        /// moved to a commit would hold
643
        #[arg(long, conflicts_with = "only")]
644
        upto: bool,
645
        /// Just CHANGE... and what they depend on. Other changes to the
646
        /// same files are left out, so a file can come out partly edited;
647
        /// to add one change to a bookmark's work, give the bookmark's
648
        /// heads with it instead: `bookmark set NAME <its heads> CHANGE`
649
        #[arg(long)]
650
        only: bool,
651
    },
652
    /// Remove a bookmark; its changes stay
653
    Delete {
654
        /// The bookmark to remove
655
        name: String,
656
    },
657
    /// List bookmarks with their heads and difference from origin
658
    List {
659
        /// Also list remotes' bookmarks that have no local bookmark
660
        #[arg(long, short)]
661
        all: bool,
662
        /// Each head of every bookmark, as `bookmark show` prints them
663
        #[arg(long, short)]
664
        verbose: bool,
665
        /// Machine-readable output: one JSON document on stdout
666
        #[arg(long)]
667
        json: bool,
668
    },
669
    /// A bookmark's heads: each change nothing else on it depends on,
670
    /// newest first. A bookmark name is also a revset for its heads
671
    /// (`oxy log -r NAME`, or `bookmark(NAME)` to mean only the bookmark)
672
    Show {
673
        /// The bookmark, or REMOTE/NAME (default: the current one)
674
        name: Option<String>,
675
        /// Machine-readable output: one JSON document on stdout
676
        #[arg(long)]
677
        json: bool,
678
    },
679
    /// Make NAME this workspace's bookmark and check it out. Uncommitted work stops it; --carry takes the work along, --discard drops it
680
    Switch {
681
        /// The bookmark to work on; one only a remote has (NAME or REMOTE/NAME) is created from it
682
        name: String,
683
        /// Throw away uncommitted working-copy changes
684
        #[arg(long)]
685
        discard: bool,
686
        /// Take uncommitted changes along; refused when NAME has other
687
        /// versions of the files they touch
688
        #[arg(long, conflicts_with = "discard")]
689
        carry: bool,
690
    },
691
}
692
693
#[derive(Subcommand)]
694
enum WitnessCmd {
695
    /// Serve a witness (C2SP tlog-witness: POST /add-checkpoint), signing
696
    /// with this oxy home's key (author.key)
697
    Serve {
698
        /// The witness's name in cosignatures: a host name
699
        #[arg(long)]
700
        name: String,
701
        /// A log to witness, as ORIGIN=FILE: its origin (HOST/log) and its
702
        /// key's identity file (a hub's /.well-known/oxyhub-key); repeatable
703
        #[arg(long = "log", required = true)]
704
        logs: Vec<String>,
705
        /// Where to keep what it cosigned
706
        #[arg(long, default_value = "witness-state")]
707
        state: PathBuf,
708
        /// Address and port to listen on
709
        #[arg(long, default_value = "127.0.0.1:8891")]
710
        bind: String,
711
        /// PEM certificate chain; enables HTTPS together with --tls-key
712
        #[arg(long, requires = "tls_key")]
713
        tls_cert: Option<PathBuf>,
714
        /// PEM private key for --tls-cert
715
        #[arg(long, requires = "tls_cert")]
716
        tls_key: Option<PathBuf>,
717
    },
718
}
719
720
#[derive(Subcommand)]
721
enum TlogCmd {
722
    /// Check a hub's whole log: its checkpoint against the log key and the
723
    /// last checkpoint seen, and every entry against the root it signed;
724
    /// then list this repository's entries (or a key's, or all)
725
    Verify {
726
        /// The hub, as https://oxygenhub.io (default: this checkout's remote)
727
        hub: Option<String>,
728
        /// List the entries a key signed (a KeyId) instead
729
        #[arg(long, conflicts_with = "all")]
730
        key: Option<String>,
731
        /// List every entry
732
        #[arg(long)]
733
        all: bool,
734
        /// Machine-readable output
735
        #[arg(long)]
736
        json: bool,
737
    },
738
}
739
740
#[derive(Subcommand)]
741
enum AuthCmd {
742
    /// Sign in to HUB in the browser (device sign-in) and keep the token for
743
    /// every repository there
744
    Login {
745
        /// The hub, as https://oxygenhub.io or oxygenhub.io (default: this checkout's origin)
746
        hub: Option<String>,
747
        /// Read a token from standard input instead (for CI and scripts)
748
        #[arg(long)]
749
        with_token: bool,
750
        /// PEM file of extra roots to trust (a hub with a self-signed certificate)
751
        #[arg(long)]
752
        ca: Option<PathBuf>,
753
    },
754
    /// List the hubs you are signed in to, checking each token with its hub
755
    Status,
756
    /// Forget HUB's token and revoke it on the hub
757
    Logout {
758
        /// The hub (default: this checkout's origin, or the only one)
759
        hub: Option<String>,
760
    },
761
    /// Keep an agent grant token (from `oh agent grant`) for keyless
762
    /// signing: with `author.signer = keyless`, commits and pushes are
763
    /// signed by fresh keys the hub certifies, in the grantor's name
764
    /// (the token is read from standard input, so it stays out of the
765
    /// shell's history)
766
    Grant {
767
        /// The hub (default: this checkout's origin)
768
        hub: Option<String>,
769
    },
770
}
771
772
#[derive(Subcommand)]
773
enum SubmoduleCmd {
774
    /// Clone URL (Oxygen or Git) into PATH and register it in .oxymodules
775
    Add {
776
        /// URL or path of the Oxygen or Git repository
777
        url: String,
778
        /// Where to put it, relative to the repository root
779
        path: String,
780
        /// Bookmark (Oxygen) or branch (Git) to check out and track
781
        #[arg(long)]
782
        bookmark: Option<String>,
783
    },
784
    /// Bring nested repositories to their pins
785
    Update {
786
        /// Clone nested repositories that are absent
787
        #[arg(long)]
788
        init: bool,
789
        /// Subrepos to update (default: all)
790
        paths: Vec<String>,
791
    },
792
    /// List subrepos with their pins and on-disk state
793
    Status {
794
        /// Machine-readable output: one JSON document on stdout
795
        #[arg(long)]
796
        json: bool,
797
    },
798
    /// Unregister PATH; the directory stays, the node goes with the next commit
799
    Remove {
800
        /// The subrepo to unregister
801
        path: String,
802
    },
803
}
804
805
#[derive(Subcommand)]
806
enum ReceiptCmd {
807
    /// The receipts kept for a state (default: the bookmark heads)
808
    List {
809
        /// Change, bookmark or tag whose state to look at
810
        rev: Option<String>,
811
        /// Machine-readable output: one JSON document on stdout
812
        #[arg(long)]
813
        json: bool,
814
    },
815
    /// One receipt in full, and whether its signature verifies
816
    Show {
817
        /// The receipt (a prefix of its hash, as `list` shows it)
818
        receipt: String,
819
        /// Change, bookmark or tag whose state holds it
820
        #[arg(long)]
821
        rev: Option<String>,
822
        /// Machine-readable output: one JSON document on stdout
823
        #[arg(long)]
824
        json: bool,
825
    },
826
    /// Write a signed receipt to FILE
827
    Export {
828
        /// The receipt (a prefix of its hash, as `list` shows it)
829
        receipt: String,
830
        /// Where to write it
831
        file: String,
832
        /// Change, bookmark or tag whose state holds it
833
        #[arg(long)]
834
        rev: Option<String>,
835
        /// `oxygen`: the runner's signed receipt, as `verify` and `import`
836
        /// read it. `slsa`: SLSA provenance in a DSSE envelope, signed with
837
        /// your key, for in-toto and cosign (`oxy identity export --pem`
838
        /// gives the key they check it with)
839
        #[arg(long, default_value = "oxygen", value_parser = ["oxygen", "slsa"])]
840
        format: String,
841
    },
842
    /// Check a signed receipt in FILE without keeping it
843
    Verify {
844
        /// A signed receipt, as a runner or `export` writes it
845
        file: String,
846
        /// Machine-readable output: one JSON document on stdout
847
        #[arg(long)]
848
        json: bool,
849
    },
850
    /// Verify a signed receipt in FILE and keep it with its state
851
    Import {
852
        /// A signed receipt, as a runner or `export` writes it
853
        file: String,
854
    },
855
}
856
857
#[derive(Subcommand)]
858
enum TagCmd {
859
    /// Tag the state of CHANGE... (default: the bookmark heads)
860
    Create {
861
        /// Name of the tag; tags never move
862
        name: String,
863
        /// Changes whose state to tag (default: the bookmark heads)
864
        changes: Vec<String>,
865
        /// A message recorded with the tag
866
        #[arg(short, long, default_value = "")]
867
        message: String,
868
    },
869
    /// List tags and the states they name
870
    List {
871
        /// Machine-readable output: one JSON document on stdout
872
        #[arg(long)]
873
        json: bool,
874
    },
875
}
876
877
#[derive(Subcommand)]
878
enum RemoteCmd {
879
    /// Add a remote
880
    Add {
881
        /// Name to refer to the remote by, such as origin
882
        name: String,
883
        /// 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
884
        url: String,
885
        /// For an s3:// store: the AWS profile to use (default: AWS_PROFILE, else "default")
886
        #[arg(long)]
887
        profile: Option<String>,
888
        /// For an s3:// store: its region (default: the environment, the profile, else asked of S3)
889
        #[arg(long)]
890
        region: Option<String>,
891
        /// For an s3://, gs:// or az:// store: another endpoint, such as an S3-compatible service
892
        #[arg(long)]
893
        endpoint: Option<String>,
894
        /// For a gs:// store: a service account key file, or application default credentials
895
        #[arg(long)]
896
        credentials: Option<String>,
897
    },
898
    /// Check a remote: that it is reachable with the credentials in hand, what it holds, and (for a store) that it behaves
899
    Check {
900
        /// The remote to check
901
        name: String,
902
    },
903
    /// Remove a remote
904
    Remove {
905
        /// The remote to remove
906
        name: String,
907
    },
908
    /// List remotes and their URLs
909
    List {
910
        /// Machine-readable output: one JSON document on stdout
911
        #[arg(long)]
912
        json: bool,
913
    },
914
}
915
916
#[derive(Subcommand)]
917
enum ProposalCmd {
918
    /// Show a proposal by its hub URL
919
    Show {
920
        /// The proposal's URL on the hub
921
        url: String,
922
        /// Machine-readable output: one JSON document on stdout
923
        #[arg(long)]
924
        json: bool,
925
    },
926
    /// Fetch the proposal's changes, set the target bookmark to the projected state, and push with your key
927
    Land {
928
        /// The proposal's URL on the hub
929
        url: String,
930
        /// Land even when the hub reports blockers
931
        #[arg(long)]
932
        force: bool,
933
    },
934
}
935
936
#[derive(Subcommand)]
937
enum IdentityCmd {
938
    /// Generate a composite Ed25519 + ML-DSA-65 key pair and make it your author identity
939
    Create {
940
        /// Your name (default: author.name)
941
        #[arg(long)]
942
        name: Option<String>,
943
        /// Your email (default: author.email)
944
        #[arg(long)]
945
        email: Option<String>,
946
        /// Record the author in this repository only, not in the user config
947
        #[arg(long)]
948
        local: bool,
949
        /// Expire the identity this many days from now
950
        #[arg(long)]
951
        expires: Option<u64>,
952
    },
953
    /// Show the configured identity
954
    Show,
955
    /// Write your identity object to a file, to hand to a policy holder
956
    Export {
957
        /// File to write (default: <key>.identity, or <key>.pem with --pem, in the current directory)
958
        path: Option<PathBuf>,
959
        /// Write the Ed25519 public key as PEM instead, as cosign's --key and
960
        /// other DSSE verifiers take it
961
        #[arg(long)]
962
        pem: bool,
963
    },
964
    /// Sign a host's challenge (hex, at least 16 bytes) to prove you hold your key; prints the signature as hex
965
    SignChallenge {
966
        /// The host's challenge, as hex
967
        challenge: String,
968
        /// Machine-readable output: one JSON document on stdout
969
        #[arg(long)]
970
        json: bool,
971
    },
972
    /// Move to a fresh key pair; the policy follows if it names your key
973
    Rotate,
974
    /// Re-issue your identity with a new expiry (in days from now; 0 = never)
975
    Renew {
976
        /// Days from now until it expires; 0 for never
977
        #[arg(long)]
978
        expires: u64,
979
    },
980
    /// Revoke a key: yours by default, or any key if you hold a policy root
981
    Revoke {
982
        /// KeyId prefix (default: your own key)
983
        key: Option<String>,
984
        /// Why, recorded in the revocation
985
        #[arg(long, default_value = "")]
986
        reason: String,
987
    },
988
    /// Keys allowed to sign or seal on your behalf
989
    Delegate {
990
        #[command(subcommand)]
991
        cmd: DelegateCmd,
992
    },
993
}
994
995
#[derive(Subcommand)]
996
enum DelegateCmd {
997
    /// Add a delegate from an exported identity file
998
    Add {
999
        /// The delegates' exported identity files: one rotation for all of them
1000
        #[arg(required = true)]
1001
        identity_file: Vec<PathBuf>,
1002
        /// What it may do for you: changes, refs, seal (comma-separated) or all.
1003
        /// An agent gets `changes`; a host that lands for you needs `changes,refs`
1004
        #[arg(long, default_value = "changes")]
1005
        scope: String,
1006
        /// How long for: 30m, 8h, 7d, or a number of days (default: until removed)
1007
        #[arg(long)]
1008
        expires: Option<String>,
1009
    },
1010
    /// Remove a delegate by KeyId prefix
1011
    Remove {
1012
        /// KeyId prefix of the delegate
1013
        key: String,
1014
    },
1015
    /// List delegates
1016
    List,
1017
}
1018
1019
#[derive(Subcommand)]
1020
enum GitCmd {
1021
    /// Export the current bookmark to a Git repository (created bare if absent)
1022
    Export {
1023
        /// Git repository to write to (created bare if absent)
1024
        git_dir: PathBuf,
1025
        /// Git branch to write (default: the bookmark name)
1026
        #[arg(long)]
1027
        branch: Option<String>,
1028
    },
1029
    /// Fetch a branch from a Git remote (path or URL) into the current bookmark
1030
    Fetch {
1031
        /// Git remote: a path or URL
1032
        url: String,
1033
        /// Branch to fetch
1034
        #[arg(long, default_value = "main")]
1035
        branch: String,
1036
        /// Author your own commits (Git author email = your identity's) with your key; sets git.claim
1037
        #[arg(long)]
1038
        claim: bool,
1039
    },
1040
    /// Push the current bookmark to a branch of a Git remote (fetch first)
1041
    Push {
1042
        /// Git remote: a path or URL
1043
        url: String,
1044
        /// Branch to push to
1045
        #[arg(long, default_value = "main")]
1046
        branch: String,
1047
    },
1048
    /// 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
1049
    Recover,
1050
    /// Check this repository's import of a Git branch: every commit's tree must be reproduced exactly
1051
    Verify {
1052
        /// The Git repository the import came from
1053
        git_dir: PathBuf,
1054
        /// Branch that was imported
1055
        #[arg(long, default_value = "main")]
1056
        branch: String,
1057
        /// Rebuild only the last N commits (the others are followed, not checked)
1058
        #[arg(long, value_name = "N")]
1059
        last: Option<usize>,
1060
        /// Stop after N differences (0: check every commit whatever it finds)
1061
        #[arg(long, value_name = "N", default_value_t = 50)]
1062
        max_differences: usize,
1063
    },
1064
    /// Import a Git branch into a new Oxygen repository at DEST
1065
    Import {
1066
        /// Git repository to read
1067
        git_dir: PathBuf,
1068
        /// Directory for the new Oxygen repository
1069
        dest: PathBuf,
1070
        /// Branch to import
1071
        #[arg(long, default_value = "main")]
1072
        branch: String,
1073
        /// Author your own commits (Git author email = your identity's) with your key; sets git.claim
1074
        #[arg(long)]
1075
        claim: bool,
1076
    },
1077
}
1078
1079
#[derive(Subcommand)]
1080
enum PolicyCmd {
1081
    /// Create the initial policy with your identity as the only root
1082
    Init,
1083
    /// Show the current policy
1084
    Show {
1085
        /// Machine-readable output: one JSON document on stdout
1086
        #[arg(long)]
1087
        json: bool,
1088
    },
1089
    /// Allow an identity (from `oxy identity export`) to update bookmarks
1090
    Grant {
1091
        /// The identity to grant, exported with `oxy identity export`
1092
        identity_file: PathBuf,
1093
        /// Reference pattern the grant applies to (default: every bookmark)
1094
        #[arg(long)]
1095
        pattern: Option<String>,
1096
        /// Where to write the proposal when more root signatures are needed
1097
        #[arg(long)]
1098
        out: Option<PathBuf>,
1099
    },
1100
    /// Allow holders of an issuer's certificates for SUBJECT to sign (keyless)
1101
    GrantSubject {
1102
        /// Who: `repo:OWNER/NAME:bookmark:main`, `agent:NAME@ACCOUNT`; `*` matches any run of characters
1103
        subject: String,
1104
        /// The issuer's identity file, e.g. a hub's /.well-known/oxyhub-key
1105
        #[arg(long)]
1106
        issuer: PathBuf,
1107
        /// What its keys may sign: changes, refs, seal
1108
        #[arg(long, default_value = "changes,refs")]
1109
        scope: String,
1110
        /// Reference pattern the grant applies to (default: every bookmark)
1111
        #[arg(long)]
1112
        pattern: Option<String>,
1113
        /// Where to write the proposal when more root signatures are needed
1114
        #[arg(long)]
1115
        out: Option<PathBuf>,
1116
    },
1117
    /// Revoke a key (KeyId prefix of an identity in the policy)
1118
    Revoke {
1119
        /// KeyId prefix of the identity
1120
        key: String,
1121
        /// Where to write the proposal when more root signatures are needed
1122
        #[arg(long)]
1123
        out: Option<PathBuf>,
1124
    },
1125
    /// Manage root keys and the signature threshold for policy updates
1126
    Root {
1127
        #[command(subcommand)]
1128
        cmd: RootCmd,
1129
    },
1130
    /// Add your root signature to a proposal file; applies it once the threshold is met
1131
    Sign {
1132
        /// The proposal file to sign
1133
        proposal: PathBuf,
1134
        /// Where to write the proposal if it still needs signatures (default: in place)
1135
        #[arg(long)]
1136
        out: Option<PathBuf>,
1137
    },
1138
}
1139
1140
#[derive(Subcommand)]
1141
enum RootCmd {
1142
    /// Make an exported identity a root key
1143
    Add {
1144
        /// The identity to make a root, exported with `oxy identity export`
1145
        identity_file: PathBuf,
1146
        /// Where to write the proposal when more root signatures are needed
1147
        #[arg(long)]
1148
        out: Option<PathBuf>,
1149
    },
1150
    /// Remove a root key by KeyId prefix
1151
    Remove {
1152
        /// KeyId prefix of the root key
1153
        key: String,
1154
        /// Where to write the proposal when more root signatures are needed
1155
        #[arg(long)]
1156
        out: Option<PathBuf>,
1157
    },
1158
    /// Require this many root signatures on policy updates
1159
    Threshold {
1160
        /// Number of root signatures
1161
        n: u32,
1162
        /// Where to write the proposal when more root signatures are needed
1163
        #[arg(long)]
1164
        out: Option<PathBuf>,
1165
    },
1166
}
1167
1168
/// Open the repository containing the current directory.
1169121×
fn open() -> Result<Repo> {
1170121×
    let repo = Repo::open(&std::env::current_dir()?).context("opening repository")?;
1171121×
    match AT_OP.get().and_then(|o| o.as_deref()) {
11720×
        Some(op) => Ok(repo.at_op(op)?),
1173121×
        None => Ok(repo),
1174
    }
1175121×
}
1176
1177
/// `oxy man`: every page into `dir`, or the top-level page on stdout.
11782×
fn man(dir: Option<PathBuf>) -> Result<i32> {
1179
    use clap::CommandFactory;
11802×
    let cmd = Cli::command();
11812×
    match dir {
11821×
        Some(dir) => {
11831×
            std::fs::create_dir_all(&dir)?;
11841×
            clap_mangen::generate_to(cmd, &dir)?;
11851×
            let pages = std::fs::read_dir(&dir)?
1186126×
                .filter(|e| {
1187126×
                    e.as_ref()
1188126×
                        .is_ok_and(|e| e.path().extension().is_some_and(|x| x == "1"))
1189126×
                })
11901×
                .count();
11911×
            println!(
1192
                "{}",
11931×
                ui::done(format!("Wrote {pages} man pages to {}", dir.display()))
1194
            );
1195
        }
11961×
        None => clap_mangen::Man::new(cmd).render(&mut std::io::stdout())?,
1197
    }
11982×
    Ok(0)
11992×
}
1200
1201
/// Parse arguments and run; returns the process exit code.
1202151×
pub fn run() -> Result<i32> {
1203
    // The cloud stores (s3://, gs://, az://) for remotes kept on them.
1204151×
    oxy_strata::register();
1205151×
    let cli = Cli::parse();
1206151×
    ui::init(cli.plain);
1207151×
    AT_OP.set(cli.at_op.clone()).ok();
12080×
    match cli.cmd {
12094×
        Cmd::Completions { shell } => {
1210
            use clap::CommandFactory;
12114×
            clap_complete::generate(shell, &mut Cli::command(), "oxy", &mut std::io::stdout());
12124×
            Ok(0)
1213
        }
12142×
        Cmd::Man { dir } => man(dir),
121514×
        Cmd::Init { path, bare, store } => workspace::init(path, bare, store.as_deref()),
12168×
        Cmd::Status { json } => workspace::status(json),
1217
        Cmd::Prompt {
12180×
            format,
12190×
            glyphs,
12200×
            color,
12210×
        } => workspace::prompt(&format, glyphs, color.as_deref()),
1222
        Cmd::Commit {
122326×
            message,
122426×
            file,
122526×
            depends_on,
122626×
            paths,
122726×
            interactive,
122826×
            hunks,
1229
        } => {
123026×
            let message = match (message, file) {
123125×
                (Some(m), _) => m,
12321×
                (None, Some(f)) if f.as_os_str() == "-" => {
12330×
                    let mut s = String::new();
12340×
                    std::io::Read::read_to_string(&mut std::io::stdin(), &mut s)?;
12350×
                    s
1236
                }
12371×
                (None, Some(f)) => std::fs::read_to_string(&f).map_err(|e| {
12380×
                    anyhow::anyhow!("reading the message from {}: {e}", f.display())
12390×
                })?,
12400×
                (None, None) => anyhow::bail!("a commit message is required (-m or -F)"),
1241
            };
124226×
            workspace::commit(&message, &depends_on, &paths, interactive, &hunks)
1243
        }
12442×
        Cmd::Cat { path, change } => workspace::cat(&path, change.as_deref()),
12451×
        Cmd::Root { json } => workspace::root(json),
12461×
        Cmd::Version { json } => workspace::version(json),
12472×
        Cmd::Discard { paths, hunks } => workspace::discard(&paths, &hunks),
12482×
        Cmd::Hunks { json } => workspace::hunks(json),
12490×
        Cmd::Squash { change, into } => workspace::squash(&change, &into),
1250
        Cmd::Rebase {
12510×
            change,
12520×
            onto,
12530×
            into_working_copy,
12540×
        } => workspace::rebase(&change, &onto, into_working_copy),
12550×
        Cmd::Blame { path, json } => workspace::blame(&path, json),
12561×
        Cmd::Bisect { cmd } => match cmd {
12570×
            BisectCmd::Start => workspace::bisect_start(),
12580×
            BisectCmd::Good { changes } => workspace::bisect_mark(Some(true), &changes),
12590×
            BisectCmd::Bad { changes } => workspace::bisect_mark(Some(false), &changes),
12600×
            BisectCmd::Skip => workspace::bisect_mark(None, &[]),
12610×
            BisectCmd::Run { command } => workspace::bisect_run(&command),
12621×
            BisectCmd::Status { json } => workspace::bisect_status(json),
12630×
            BisectCmd::Reset => workspace::bisect_reset(),
1264
        },
1265
        Cmd::Log {
12668×
            revset,
12678×
            limit,
12688×
            verbose,
12698×
            path,
12708×
            lines,
12718×
            json,
12728×
        } => workspace::log(
12738×
            revset.as_deref(),
12748×
            limit,
12758×
            verbose,
12768×
            path.as_deref(),
12778×
            lines.as_deref(),
12788×
            json,
1279
        ),
12801×
        Cmd::Diff { change, json } => workspace::diff(change.as_deref(), json),
1281
        Cmd::Describe {
12824×
            message,
12834×
            change,
12844×
            json,
12854×
        } => match message {
12860×
            Some(m) => workspace::describe(&m, change.as_deref()),
12874×
            None if change.is_some() => {
12880×
                anyhow::bail!(
1289
                    "naming works on the working copy; to change a head's message pass -m"
1290
                )
1291
            }
12924×
            None => workspace::describe_name(json),
1293
        },
12940×
        Cmd::Amend { message, into } => workspace::amend(message.as_deref(), into.as_deref()),
12950×
        Cmd::Split { change, paths } => workspace::split(&change, &paths),
1296
        Cmd::Abandon {
12970×
            change,
12980×
            revset,
12990×
            yes,
13000×
        } => workspace::abandon(change.as_deref(), revset.as_deref(), yes),
1301
        Cmd::Show {
13022×
            change,
13032×
            revset,
13042×
            json,
13052×
        } => workspace::show(change.as_deref(), revset.as_deref(), json),
1306
        Cmd::Checkout {
13070×
            changes,
13080×
            discard,
13090×
            carry,
13100×
        } => workspace::checkout(&changes, discard, carry),
13111×
        Cmd::Resolve { json } => workspace::resolve(json),
13120×
        Cmd::Undo => workspace::undo(),
1313
        Cmd::Gc {
13142×
            now,
13152×
            expire_snapshots,
13162×
            remote,
13172×
        } => match remote {
13182×
            Some(name) => workspace::gc_remote(&name, now),
13190×
            None => workspace::gc(now, expire_snapshots),
1320
        },
13210×
        Cmd::Fsck { json } => workspace::fsck(json),
13220×
        Cmd::Doctor { offline, json } => workspace::doctor(offline, json),
13230×
        Cmd::Checkpoint => workspace::checkpoint(),
13241×
        Cmd::Op { cmd } => match cmd {
13251×
            OpCmd::Log { limit, json } => workspace::op_log(limit, json),
13260×
            OpCmd::Restore { op, discard } => workspace::op_restore(&op, discard),
13270×
            OpCmd::Revert { op } => workspace::op_revert(&op),
1328
        },
1329
        Cmd::Clone {
13305×
            url,
13315×
            dest,
13325×
            max_blob,
13335×
            sparse,
13345×
            depth,
13355×
            recursive,
13365×
        } => sync::clone(&url, dest, max_blob.as_deref(), &sparse, depth, recursive),
13370×
        Cmd::Deepen { depth, remote } => sync::deepen(&remote, depth),
13380×
        Cmd::Sparse { paths } => workspace::sparse(&paths),
13390×
        Cmd::Lock { path } => workspace::lock(&path),
13400×
        Cmd::Unlock { path } => workspace::unlock(&path),
13411×
        Cmd::Workspace { cmd } => match cmd {
13420×
            WorkspaceCmd::Add { path, changes } => workspace::workspace_add(&path, &changes),
13431×
            WorkspaceCmd::List { json } => workspace::workspace_list(json),
13440×
            WorkspaceCmd::Forget { workspace } => workspace::workspace_forget(&workspace),
1345
        },
134617×
        Cmd::Bookmark { cmd } => match cmd {
1347
            BookmarkCmd::Create {
13486×
                name,
13496×
                changes,
13506×
                upto,
13516×
                only,
13526×
            } => workspace::bookmark_create(&name, &changes, upto, only),
1353
            BookmarkCmd::Set {
13543×
                name,
13553×
                changes,
13563×
                upto,
13573×
                only,
13583×
            } => workspace::bookmark_set(&name, &changes, upto, only),
13590×
            BookmarkCmd::Delete { name } => workspace::bookmark_delete(&name),
13605×
            BookmarkCmd::List { all, verbose, json } => {
13615×
                workspace::bookmark_list(all, verbose, json)
1362
            }
13630×
            BookmarkCmd::Show { name, json } => workspace::bookmark_show(name.as_deref(), json),
1364
            BookmarkCmd::Switch {
13653×
                name,
13663×
                discard,
13673×
                carry,
13683×
            } => workspace::bookmark_switch(&name, discard, carry),
1369
        },
13700×
        Cmd::Merge { bookmark } => workspace::merge(&bookmark),
13710×
        Cmd::Auth { cmd } => match cmd {
1372
            AuthCmd::Login {
13730×
                hub,
13740×
                with_token,
13750×
                ca,
13760×
            } => auth::login(hub.as_deref(), with_token, ca),
13770×
            AuthCmd::Status => auth::status(),
13780×
            AuthCmd::Logout { hub } => auth::logout(hub.as_deref()),
13790×
            AuthCmd::Grant { hub } => auth::grant(hub.as_deref()),
1380
        },
13811×
        Cmd::Submodule { cmd } => match cmd {
1382
            SubmoduleCmd::Add {
13830×
                url,
13840×
                path,
13850×
                bookmark,
13860×
            } => sync::submodule_add(&url, &path, bookmark.as_deref()),
13870×
            SubmoduleCmd::Update { init, paths } => sync::submodule_update(init, &paths),
13881×
            SubmoduleCmd::Status { json } => sync::submodule_status(json),
13890×
            SubmoduleCmd::Remove { path } => sync::submodule_remove(&path),
1390
        },
1391
        Cmd::Witness {
1392
            cmd:
1393
                WitnessCmd::Serve {
13940×
                    name,
13950×
                    logs,
13960×
                    state,
13970×
                    bind,
13980×
                    tls_cert,
13990×
                    tls_key,
1400
                },
14010×
        } => tlog::witness_serve(&name, &logs, state, &bind, tls_cert.zip(tls_key)),
14020×
        Cmd::Tlog { cmd } => match cmd {
1403
            TlogCmd::Verify {
14040×
                hub,
14050×
                key,
14060×
                all,
14070×
                json,
14080×
            } => tlog::verify(hub.as_deref(), key.as_deref(), all, json),
1409
        },
141010×
        Cmd::Receipt { cmd } => match cmd {
14112×
            ReceiptCmd::List { rev, json } => receipt::list(rev.as_deref(), json),
1412
            ReceiptCmd::Show {
14131×
                receipt: r,
14141×
                rev,
14151×
                json,
14161×
            } => receipt::show(&r, rev.as_deref(), json),
1417
            ReceiptCmd::Export {
14183×
                receipt: r,
14193×
                file,
14203×
                rev,
14213×
                format,
14223×
            } => receipt::export(&r, &file, rev.as_deref(), &format),
14232×
            ReceiptCmd::Verify { file, json } => receipt::verify(&file, json),
14242×
            ReceiptCmd::Import { file } => receipt::import(&file),
1425
        },
14263×
        Cmd::Tag { cmd } => match cmd {
1427
            TagCmd::Create {
14282×
                name,
14292×
                changes,
14302×
                message,
14312×
            } => workspace::tag_create(&name, &changes, &message),
14321×
            TagCmd::List { json } => workspace::tag_list(json),
1433
        },
143410×
        Cmd::Remote { cmd } => match cmd {
1435
            RemoteCmd::Add {
14364×
                name,
14374×
                url,
14384×
                profile,
14394×
                region,
14404×
                endpoint,
14414×
                credentials,
14424×
            } => sync::remote_add(
14434×
                &name,
14444×
                &url,
14454×
                &[
14464×
                    ("profile", profile),
14474×
                    ("region", region),
14484×
                    ("endpoint", endpoint),
14494×
                    ("credentials", credentials),
14504×
                ],
1451
            ),
14523×
            RemoteCmd::Check { name } => sync::remote_check(&name),
14531×
            RemoteCmd::Remove { name } => sync::remote_remove(&name),
14542×
            RemoteCmd::List { json } => sync::remote_list(json),
1455
        },
14561×
        Cmd::Fetch { remote, json } => sync::fetch(remote.as_deref(), json),
14574×
        Cmd::Pull { remote, json } => sync::pull(remote.as_deref(), json),
1458
        Cmd::Push {
14597×
            remote,
14607×
            force,
14617×
            bookmark,
14627×
            delete,
14637×
            json,
14647×
        } => match delete {
14650×
            Some(name) => sync::push_delete(remote.as_deref(), &name, json),
14667×
            None => sync::push(remote.as_deref(), force, bookmark.as_deref(), json),
1467
        },
1468
        Cmd::Serve {
14690×
            root,
14700×
            bind,
14710×
            tokens,
14720×
            tls_cert,
14730×
            tls_key,
14740×
        } => sync::serve(root, &bind, tokens, tls_cert.zip(tls_key)),
14753×
        Cmd::Identity { cmd } => match cmd {
1476
            IdentityCmd::Create {
14772×
                name,
14782×
                email,
14792×
                local,
14802×
                expires,
14812×
            } => identity::create(name, email, local, expires),
14820×
            IdentityCmd::Show => identity::show(),
14831×
            IdentityCmd::Export { path, pem } => identity::export(path, pem),
14840×
            IdentityCmd::SignChallenge { challenge, json } => {
14850×
                identity::sign_challenge(&challenge, json)
1486
            }
14870×
            IdentityCmd::Rotate => identity::rotate(),
14880×
            IdentityCmd::Renew { expires } => identity::renew(expires),
14890×
            IdentityCmd::Revoke { key, reason } => identity::revoke(key.as_deref(), &reason),
14900×
            IdentityCmd::Delegate { cmd } => match cmd {
1491
                DelegateCmd::Add {
14920×
                    identity_file,
14930×
                    scope,
14940×
                    expires,
14950×
                } => identity::delegate_add(&identity_file, &scope, expires.as_deref()),
14960×
                DelegateCmd::Remove { key } => identity::delegate_remove(&key),
14970×
                DelegateCmd::List => identity::delegate_list(),
1498
            },
1499
        },
1500
        Cmd::Git {
15010×
            cmd: GitCmd::Export { git_dir, branch },
15020×
        } => sync::git_export(&git_dir, branch.as_deref()),
1503
        Cmd::Git {
15040×
            cmd: GitCmd::Fetch { url, branch, claim },
15050×
        } => sync::git_fetch(&url, &branch, claim),
1506
        Cmd::Git {
15070×
            cmd: GitCmd::Push { url, branch },
15080×
        } => sync::git_push(&url, &branch),
1509
        Cmd::Git {
1510
            cmd: GitCmd::Recover,
15110×
        } => sync::git_recover(),
1512
        Cmd::Git {
1513
            cmd:
1514
                GitCmd::Import {
15150×
                    git_dir,
15160×
                    dest,
15170×
                    branch,
15180×
                    claim,
1519
                },
15200×
        } => sync::git_import(&git_dir, &dest, &branch, claim),
1521
        Cmd::Git {
1522
            cmd:
1523
                GitCmd::Verify {
15240×
                    git_dir,
15250×
                    branch,
15260×
                    last,
15270×
                    max_differences,
1528
                },
15290×
        } => sync::git_verify(&git_dir, &branch, last, max_differences),
15305×
        Cmd::Policy { cmd } => match cmd {
15311×
            PolicyCmd::Init => identity::policy_init(),
15323×
            PolicyCmd::Show { json } => identity::policy_show(json),
1533
            PolicyCmd::Grant {
15340×
                identity_file,
15350×
                pattern,
15360×
                out,
15370×
            } => identity::policy_grant(&identity_file, pattern.as_deref(), out),
1538
            PolicyCmd::GrantSubject {
15391×
                subject,
15401×
                issuer,
15411×
                scope,
15421×
                pattern,
15431×
                out,
15441×
            } => identity::policy_grant_subject(&subject, &issuer, &scope, pattern.as_deref(), out),
15450×
            PolicyCmd::Revoke { key, out } => identity::policy_revoke(&key, out),
15460×
            PolicyCmd::Root { cmd } => match cmd {
15470×
                RootCmd::Add { identity_file, out } => {
15480×
                    identity::policy_root_add(&identity_file, out)
1549
                }
15500×
                RootCmd::Remove { key, out } => identity::policy_root_remove(&key, out),
15510×
                RootCmd::Threshold { n, out } => identity::policy_threshold(n, out),
1552
            },
15530×
            PolicyCmd::Sign { proposal, out } => identity::policy_sign(&proposal, out),
1554
        },
1555
        Cmd::Seal {
15560×
            flow: Some(url),
15570×
            job: Some(job),
15580×
            reject,
15590×
            json,
1560
            ..
15610×
        } => approve::seal(&url, &job, reject, json),
1562
        Cmd::Seal {
15630×
            changes,
15640×
            proposal: Some(url),
15650×
            json,
1566
            ..
15670×
        } if changes.is_empty() => proposal::seal(&url, json),
15680×
        Cmd::Seal { changes, json, .. } => identity::seal(&changes, json),
15690×
        Cmd::Proposal { cmd } => match cmd {
15700×
            ProposalCmd::Show { url, json } => proposal::show(&url, json),
15710×
            ProposalCmd::Land { url, force } => proposal::land(&url, force),
1572
        },
1573
        Cmd::Verify {
15741×
            change,
15751×
            revset,
15761×
            json,
15771×
        } => identity::verify(change.as_deref(), revset.as_deref(), json),
1578
        Cmd::Config {
15791×
            key,
15801×
            value,
15811×
            user,
15821×
            unset,
15831×
        } => identity::config(&key, value.as_deref().unwrap_or(""), user, unset),
1584
    }
1585151×
}
1586
1587
#[cfg(test)]
1588
mod help_tests {
1589
    use super::Cli;
1590
    use clap::CommandFactory;
1591
1592
    /// Every command and every argument explains itself, so `--help`,
1593
    /// completions and the man pages are complete.
1594
    #[test]
15951×
    fn every_command_and_argument_has_help() {
1596126×
        fn walk(cmd: &clap::Command, path: &str, missing: &mut Vec<String>) {
1597126×
            let here = format!("{path} {}", cmd.get_name()).trim().to_string();
1598126×
            if cmd.get_about().is_none() && !path.is_empty() {
15990×
                missing.push(format!("{here} (command)"));
1600126×
            }
1601231×
            for a in cmd.get_arguments() {
1602231×
                let id = a.get_id().as_str();
1603231×
                if id == "help" || id == "version" || (a.is_global_set() && !path.is_empty()) {
16040×
                    continue;
1605231×
                }
1606231×
                if a.get_help().is_none() && a.get_long_help().is_none() {
16070×
                    missing.push(format!("{here} {id}"));
1608231×
                }
1609
            }
1610126×
            for sub in cmd.get_subcommands() {
1611125×
                walk(sub, &here, missing);
1612125×
            }
1613126×
        }
16141×
        let mut missing = Vec::new();
16151×
        walk(&Cli::command(), "", &mut missing);
16161×
        assert!(
16171×
            missing.is_empty(),
1618
            "{} without help:\n{}",
16190×
            missing.len(),
16200×
            missing.join("\n")
1621
        );
16221×
    }
1623
}