OXYGENHUB

Coverage / src/cli/mod.rs 58.1%

208 of 358 lines run, 9 of 18 functions · run #336 on paths-for-resolutions-and-amend · run missed

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