OXYGENHUB

Coverage / src/cli/mod.rs 60.3%

202 of 335 lines run, 9 of 18 functions · run #309 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
pub mod ui;
12
mod workspace;
13
14
use anyhow::{Context, Result};
15
use clap::{Parser, Subcommand};
16
use oxy_core::repo::Repo;
17
use std::path::PathBuf;
18
19
#[derive(Parser)]
20
#[command(
21
    name = "oxy",
22
    version = env!("OXY_VERSION_LONG"),
23
    about = "Oxygen: breathing fresh air into version control"
24
)]
25
struct Cli {
26
    /// Plain output: no colour, no spinner (also implied by NO_COLOR or a non-terminal)
27
    #[arg(long, global = true)]
28
    plain: bool,
29
    /// Read the repository as it was after operation OP (an ID from oxy op log, @ or @-); commands that would change it are refused
30
    #[arg(long, global = true, value_name = "OP")]
31
    at_op: Option<String>,
32
    #[command(subcommand)]
33
    cmd: Cmd,
34
}
35
36
/// `--at-op`, for `open` to apply.
37
static AT_OP: std::sync::OnceLock<Option<String>> = std::sync::OnceLock::new();
38
39
#[derive(Subcommand)]
40
enum Cmd {
41
    /// Create a repository in PATH (default: current directory)
42
    Init {
43
        /// Directory to create the repository in (default: the current directory)
44
        path: Option<PathBuf>,
45
        /// No working copy: an object store and references only, for hosting
46
        #[arg(long)]
47
        bare: bool,
48
        /// Keep the objects and the operation log on this store
49
        /// (dir://PATH, s3://BUCKET/PREFIX, gs://…, az://…) instead of
50
        /// in .oxy, with a local cache in front (storage.cache, 2 GiB)
51
        #[arg(long, value_name = "URL")]
52
        store: Option<String>,
53
    },
54
    /// Clone a repository from a local path or an http(s) URL
55
    Clone {
56
        /// Local path or http(s) URL of the repository
57
        url: String,
58
        /// Directory to clone into (default: the last part of the URL)
59
        dest: Option<PathBuf>,
60
        /// Leave blobs larger than this (e.g. 1M) to be fetched on first read
61
        #[arg(long)]
62
        max_blob: Option<String>,
63
        /// Materialize only these paths (repeatable); implies lazy blobs
64
        #[arg(long = "sparse")]
65
        sparse: Vec<String>,
66
        /// Shallow clone: fetch only this many levels of history below the heads
67
        #[arg(long)]
68
        depth: Option<u32>,
69
        /// Clone the subrepos too (as oxy submodule update --init)
70
        #[arg(long)]
71
        recursive: bool,
72
    },
73
    /// Fetch more history below a shallow clone's boundary
74
    Deepen {
75
        /// Levels of history to add below the boundary
76
        #[arg(default_value_t = 10)]
77
        depth: u32,
78
        /// Remote to fetch the history from
79
        #[arg(long, default_value = "origin")]
80
        remote: String,
81
    },
82
    /// Show or set the sparse filter (paths to materialize); re-checks out the bookmark
83
    Sparse {
84
        /// Paths to materialize; none prints the current filter
85
        paths: Vec<String>,
86
    },
87
    /// Show the working copy: changed paths and conflicts
88
    Status {
89
        /// Machine-readable output: paths, and every conflict with its kind and contributing changes
90
        #[arg(long)]
91
        json: bool,
92
    },
93
    /// One-line summary for shell prompts; fast and records nothing
94
    Prompt {
95
        /// 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
96
        #[arg(long, default_value = oxy_core::repo::DEFAULT_PROMPT_FORMAT)]
97
        format: String,
98
        /// Glyph format (%i %b %c %s%U%O) instead of the plain default
99
        #[arg(long)]
100
        glyphs: bool,
101
        /// Colour by state (cyan clean, yellow dirty, red conflicted): raw escapes, or guarded for a bash or zsh PS1
102
        #[arg(long, value_parser = ["raw", "bash", "zsh"])]
103
        color: Option<String>,
104
    },
105
    /// Record the working copy as a change on the current bookmark
106
    Commit {
107
        /// The change's message: a subject line, then optionally a blank line and a body
108
        #[arg(short, long, required_unless_present = "file", conflicts_with = "file")]
109
        message: Option<String>,
110
        /// Read the message from FILE (`-` for standard input)
111
        #[arg(short = 'F', long, value_name = "FILE")]
112
        file: Option<PathBuf>,
113
        /// Extra explicit dependencies (ChangeId prefix, #hash prefix)
114
        #[arg(long = "depends-on")]
115
        depends_on: Vec<String>,
116
        /// Commit only these paths; the rest stays as uncommitted work
117
        paths: Vec<String>,
118
        /// Choose hunks one by one
119
        #[arg(short, long)]
120
        interactive: bool,
121
        /// Commit these hunks (as `oxy hunks` numbers them), comma separated
122
        #[arg(long, value_delimiter = ',')]
123
        hunks: Vec<usize>,
124
    },
125
    /// Fold CHANGE into one of its dependencies (keeps that change's id)
126
    Squash {
127
        /// The change to fold (ChangeId prefix, #hash prefix)
128
        change: String,
129
        /// The dependency that absorbs it
130
        #[arg(long)]
131
        into: String,
132
    },
133
    /// Re-express CHANGE against another base state
134
    Rebase {
135
        /// The change to re-express (ChangeId prefix, #hash prefix)
136
        change: String,
137
        /// The changes, bookmark or tag whose state becomes the new base
138
        #[arg(long, required = true, num_args = 1..)]
139
        onto: Vec<String>,
140
        /// Where the rebase would be conflicted, merge the target into the
141
        /// current bookmark instead, leaving the conflict in the working
142
        /// copy to fix and commit
143
        #[arg(long)]
144
        into_working_copy: bool,
145
    },
146
    /// Show which change introduced each line of a file
147
    Blame {
148
        /// File to annotate, relative to the repository root
149
        path: String,
150
        /// Machine-readable output: one JSON document on stdout
151
        #[arg(long)]
152
        json: bool,
153
    },
154
    /// Find the change that introduced a regression
155
    Bisect {
156
        #[command(subcommand)]
157
        cmd: BisectCmd,
158
    },
159
    /// List changes reachable from the bookmark and the working copy
160
    Log {
161
        /// Show the changes a revset selects: `main` (a bookmark name means its
162
        /// heads; `bookmark(main)` only ever the bookmark), `main..feature &
163
        /// author(andy)`, `touches("src/**") & date(-7d..)` (see
164
        /// docs/revset_query_language.md)
165
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with_all = ["path", "lines"])]
166
        revset: Option<String>,
167
        /// Show at most this many changes
168
        #[arg(short = 'n', long)]
169
        limit: Option<usize>,
170
        /// Show full messages, dependencies, and signatures
171
        #[arg(short, long)]
172
        verbose: bool,
173
        /// Only changes touching this path (renames followed)
174
        #[arg(long)]
175
        path: Option<String>,
176
        /// Only changes that wrote or deleted lines START to END of PATH
177
        /// (numbered as in the working copy's base), or deleted lines from
178
        /// between them: the history of a function
179
        #[arg(short = 'L', value_name = "START,END:PATH", conflicts_with = "path")]
180
        lines: Option<String>,
181
        /// Machine-readable output: one JSON document on stdout
182
        #[arg(long)]
183
        json: bool,
184
    },
185
    /// Show what the working copy changes against its base
186
    Diff {
187
        /// A change instead of the working copy
188
        change: Option<String>,
189
        /// Machine-readable output: one JSON document on stdout
190
        #[arg(long)]
191
        json: bool,
192
    },
193
    /// Print a file as it is in a state (default: the working copy's base)
194
    Cat {
195
        /// File to print, relative to the repository root
196
        path: String,
197
        /// A bookmark or tag (its state), or a change: a change means its
198
        /// dependency closure, the change and what it depends on, so files
199
        /// only later changes touched are absent or at older versions
200
        #[arg(short = 'r', long)]
201
        change: Option<String>,
202
    },
203
    /// Print the repository root, workspace, and bookmark
204
    Root {
205
        /// Machine-readable output: one JSON document on stdout
206
        #[arg(long)]
207
        json: bool,
208
    },
209
    /// Print the version of oxy, its repository format, and protocol
210
    Version {
211
        /// Machine-readable output: one JSON document on stdout
212
        #[arg(long)]
213
        json: bool,
214
    },
215
    /// Restore paths to the working copy's base, or undo chosen hunks
216
    Discard {
217
        /// Paths to restore; none with --hunks, or everything with neither
218
        paths: Vec<String>,
219
        /// Hunk indices as `oxy hunks` numbers them, comma separated
220
        #[arg(long, value_delimiter = ',')]
221
        hunks: Vec<usize>,
222
    },
223
    /// List the working copy's hunks, numbered as commit --hunks expects
224
    Hunks {
225
        /// Machine-readable output: one JSON document on stdout
226
        #[arg(long)]
227
        json: bool,
228
    },
229
    /// With -m, change the message of a head; without, name the working
230
    /// copy for a build: its tag, or the nearest tag plus distance and
231
    /// change, or the bookmark and change, and -dirty
232
    Describe {
233
        /// The new message
234
        #[arg(short, long)]
235
        message: Option<String>,
236
        /// The head to describe (default: the one the working copy sits on)
237
        change: Option<String>,
238
        /// Machine-readable output (naming only)
239
        #[arg(long, conflicts_with = "message")]
240
        json: bool,
241
    },
242
    /// Fold the working copy into the head it sits on, or into CHANGE with --into
243
    Amend {
244
        /// Replace the message too
245
        #[arg(short, long)]
246
        message: Option<String>,
247
        /// Amend an older change; the edits must touch only lines it already knows
248
        #[arg(long)]
249
        into: Option<String>,
250
    },
251
    /// Split a head: the named paths become a separate first change
252
    Split {
253
        /// The head to split
254
        change: String,
255
        /// Paths whose edits become the first change
256
        paths: Vec<String>,
257
    },
258
    /// Drop a change from the bookmark; its content stays on disk as uncommitted work
259
    Abandon {
260
        /// The change to drop (ChangeId prefix, #hash prefix)
261
        #[arg(required_unless_present = "revset")]
262
        change: Option<String>,
263
        /// Drop every change a revset selects, newest first
264
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
265
        revset: Option<String>,
266
        /// Drop more than five changes without asking
267
        #[arg(long, short = 'y')]
268
        yes: bool,
269
    },
270
    /// Show one change (ChangeId prefix, #hash prefix, or @), or those a revset selects
271
    Show {
272
        /// ChangeId prefix, #hash prefix, or @ for the working copy
273
        #[arg(required_unless_present = "revset")]
274
        change: Option<String>,
275
        /// Show every change a revset selects
276
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
277
        revset: Option<String>,
278
        /// Machine-readable output: one JSON document on stdout
279
        #[arg(long)]
280
        json: bool,
281
    },
282
    /// Move the working copy to the state formed by CHANGE... (default: the bookmark heads)
283
    Checkout {
284
        /// Changes whose state to check out (default: the bookmark heads)
285
        changes: Vec<String>,
286
        /// Throw away uncommitted working-copy changes
287
        #[arg(long)]
288
        discard: bool,
289
        /// Take uncommitted changes along; refused when the target has
290
        /// other versions of the files they touch
291
        #[arg(long, conflicts_with = "discard")]
292
        carry: bool,
293
    },
294
    /// Report which conflicts of the working copy's base are resolved by the current files
295
    Resolve {
296
        /// Machine-readable output: one JSON document on stdout
297
        #[arg(long)]
298
        json: bool,
299
    },
300
    /// Undo the last operation
301
    Undo,
302
    /// Write a checkpoint of the current bookmark's state now
303
    Checkpoint,
304
    /// Print a shell completion script: `oxy completions bash > ~/.local/share/bash-completion/completions/oxy`
305
    Completions {
306
        /// bash, zsh, fish, elvish or powershell
307
        shell: clap_complete::Shell,
308
    },
309
    /// Write man pages (oxy.1 and one per command) into DIR, or print oxy.1
310
    Man {
311
        /// Directory to write every page into, e.g. ~/.local/share/man/man1
312
        #[arg(long)]
313
        dir: Option<PathBuf>,
314
    },
315
    /// Check the identity, configuration and remotes, and say what to do about any problem
316
    Doctor {
317
        /// Do not contact the remotes
318
        #[arg(long)]
319
        offline: bool,
320
        /// Machine-readable output: one JSON document on stdout
321
        #[arg(long)]
322
        json: bool,
323
    },
324
    /// Check the repository's integrity: objects, operation log, references, signatures, checkpoints
325
    Fsck {
326
        /// Machine-readable output: one JSON document on stdout
327
        #[arg(long)]
328
        json: bool,
329
    },
330
    /// Prune unreachable objects older than the grace period and repack everything into one pack
331
    Gc {
332
        /// Ignore the grace period (core.gc-grace) and prune immediately
333
        #[arg(long)]
334
        now: bool,
335
        /// Keep no past working-copy snapshots, only each workspace's current one, so files only they held go (core.snapshot-retention, default 7 days)
336
        #[arg(long)]
337
        expire_snapshots: bool,
338
        /// 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)
339
        #[arg(long, value_name = "NAME")]
340
        remote: Option<String>,
341
    },
342
    /// List operations
343
    #[command(name = "op")]
344
    Op {
345
        #[command(subcommand)]
346
        cmd: OpCmd,
347
    },
348
    /// Take the advisory local lock on a lockable file, making it writable
349
    Lock {
350
        /// The lockable file
351
        path: String,
352
    },
353
    /// Release the local lock and make the file read-only again
354
    Unlock {
355
        /// The locked file
356
        path: String,
357
    },
358
    /// Workspaces: extra checkout directories sharing this repository
359
    Workspace {
360
        #[command(subcommand)]
361
        cmd: WorkspaceCmd,
362
    },
363
    /// Bookmarks: named states; each workspace works on one
364
    Bookmark {
365
        #[command(subcommand)]
366
        cmd: BookmarkCmd,
367
    },
368
    /// Union another bookmark's heads into the current one (no merge change)
369
    Merge {
370
        /// The bookmark whose heads to add
371
        bookmark: String,
372
    },
373
    /// Sign in to a hub once, for every repository on it
374
    Auth {
375
        #[command(subcommand)]
376
        cmd: AuthCmd,
377
    },
378
    /// Subrepositories: nested repositories pinned to a state
379
    Submodule {
380
        #[command(subcommand)]
381
        cmd: SubmoduleCmd,
382
    },
383
    /// Execution receipts: signed records of what a runner ran on a state
384
    Receipt {
385
        #[command(subcommand)]
386
        cmd: ReceiptCmd,
387
    },
388
    /// Tags: immutable named states
389
    Tag {
390
        #[command(subcommand)]
391
        cmd: TagCmd,
392
    },
393
    /// Manage remotes
394
    Remote {
395
        #[command(subcommand)]
396
        cmd: RemoteCmd,
397
    },
398
    /// Fetch every bookmark of a remote into its tracking references
399
    Fetch {
400
        /// Remote name (default: origin)
401
        remote: Option<String>,
402
        /// Machine-readable output: one JSON document on stdout
403
        #[arg(long)]
404
        json: bool,
405
    },
406
    /// Fetch, then union the remote bookmark into the local one (no merge change)
407
    Pull {
408
        /// Remote name (default: origin)
409
        remote: Option<String>,
410
        /// Machine-readable output: one JSON document on stdout
411
        #[arg(long)]
412
        json: bool,
413
    },
414
    /// Push the current bookmark to a remote
415
    Push {
416
        /// Remote name (default: origin)
417
        remote: Option<String>,
418
        /// Allow dropping heads the remote has
419
        #[arg(long)]
420
        force: bool,
421
        /// Push this bookmark instead of the workspace's current one
422
        #[arg(short = 'b', long)]
423
        bookmark: Option<String>,
424
        /// Delete this bookmark on the remote (never its default bookmark);
425
        /// the local bookmark is kept
426
        #[arg(long, value_name = "NAME", conflicts_with_all = ["bookmark", "force"])]
427
        delete: Option<String>,
428
        /// Machine-readable output: one JSON document on stdout
429
        #[arg(long)]
430
        json: bool,
431
    },
432
    /// Serve repositories under ROOT over HTTPS (with --tls-cert/--tls-key) or plain HTTP
433
    Serve {
434
        /// Directory with one repository per subdirectory
435
        #[arg(long, default_value = ".")]
436
        root: PathBuf,
437
        /// Address and port to listen on
438
        #[arg(long, default_value = "127.0.0.1:8890")]
439
        bind: String,
440
        /// Bearer token allowed to push (repeatable); none means open
441
        #[arg(long = "token")]
442
        tokens: Vec<String>,
443
        /// PEM certificate chain; enables HTTPS together with --tls-key
444
        #[arg(long, requires = "tls_key")]
445
        tls_cert: Option<PathBuf>,
446
        /// PEM private key
447
        #[arg(long, requires = "tls_cert")]
448
        tls_key: Option<PathBuf>,
449
    },
450
    /// Manage the signing identity
451
    Identity {
452
        #[command(subcommand)]
453
        cmd: IdentityCmd,
454
    },
455
    /// Seal changes with your key: named ones, or every change on the current bookmark you can authenticate but have not
456
    Seal {
457
        /// Changes to seal (default: every change on the bookmark you can authenticate and have not sealed)
458
        changes: Vec<String>,
459
        /// Seal every change of a hub proposal and push the seal (your approval)
460
        #[arg(long, conflicts_with = "changes")]
461
        proposal: Option<String>,
462
        /// Approve a job of a hub run that waits for a sealed approval: `--flow https://hub/OWNER/NAME/flow/N --job apply`
463
        #[arg(long, conflicts_with_all = ["changes", "proposal"], requires = "job")]
464
        flow: Option<String>,
465
        /// The job to approve, with --flow
466
        #[arg(long, requires = "flow")]
467
        job: Option<String>,
468
        /// Reject the job instead of approving it, with --flow
469
        #[arg(long, requires = "flow")]
470
        reject: bool,
471
        /// Machine-readable output: one JSON document on stdout
472
        #[arg(long)]
473
        json: bool,
474
    },
475
    /// Hub proposals: show one, or land it from this client
476
    Proposal {
477
        #[command(subcommand)]
478
        cmd: ProposalCmd,
479
    },
480
    /// Verify the signatures on a change (default: every change in the log)
481
    Verify {
482
        /// The change to verify (default: every change in the log)
483
        change: Option<String>,
484
        /// Verify every change a revset selects: `release..main & unsigned()`
485
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
486
        revset: Option<String>,
487
        /// Machine-readable output: one JSON document on stdout
488
        #[arg(long)]
489
        json: bool,
490
    },
491
    /// Git interoperability
492
    Git {
493
        #[command(subcommand)]
494
        cmd: GitCmd,
495
    },
496
    /// Manage the trust policy (who may update which bookmarks)
497
    Policy {
498
        #[command(subcommand)]
499
        cmd: PolicyCmd,
500
    },
501
    /// 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)
502
    Config {
503
        /// The key, such as author.name or remote.origin.token
504
        key: String,
505
        /// The value to set (none with --unset); `-` reads it from standard input, out of the shell's history
506
        #[arg(required_unless_present = "unset")]
507
        value: Option<String>,
508
        /// Write to the user file (~/.config/oxy/config.toml) instead of this repository
509
        #[arg(long)]
510
        user: bool,
511
        /// Remove the key from this repository's file (or the user file with --user)
512
        #[arg(long)]
513
        unset: bool,
514
    },
515
}
516
517
#[derive(Subcommand)]
518
enum OpCmd {
519
    /// List operations, newest first, with what each changed
520
    Log {
521
        /// Show only the latest N (snapshots folded together count as one)
522
        #[arg(short = 'n', long)]
523
        limit: Option<usize>,
524
        /// Machine-readable output: one JSON document on stdout
525
        #[arg(long)]
526
        json: bool,
527
    },
528
    /// Go back to the bookmarks and working copy as they were after OP (recorded as a new operation, so it can be undone)
529
    Restore {
530
        /// The operation: an ID prefix from oxy op log, @ or @-
531
        op: String,
532
        /// Throw away uncommitted working-copy changes
533
        #[arg(long)]
534
        discard: bool,
535
    },
536
    /// Undo OP alone, keeping every operation after it: the bookmarks it moved go back
537
    Revert {
538
        /// The operation: an ID prefix from oxy op log
539
        op: String,
540
    },
541
}
542
543
#[derive(Subcommand)]
544
enum WorkspaceCmd {
545
    /// Create a workspace at PATH checked out on CHANGE... (default: the bookmark heads)
546
    Add {
547
        /// Directory for the new workspace (must be empty or absent)
548
        path: PathBuf,
549
        /// Changes whose state to check out there
550
        changes: Vec<String>,
551
    },
552
    /// List workspaces and their working-copy changes
553
    List {
554
        /// Machine-readable output: one JSON document on stdout
555
        #[arg(long)]
556
        json: bool,
557
    },
558
    /// Stop tracking a workspace (by id prefix or path); its files stay
559
    Forget {
560
        /// Workspace id prefix or path
561
        workspace: String,
562
    },
563
}
564
565
#[derive(Subcommand)]
566
enum BisectCmd {
567
    /// Begin; remembers where the working copy was
568
    Start,
569
    /// Mark CHANGE... (or the state under test) as good
570
    Good {
571
        /// Changes known to be good (default: the state under test)
572
        changes: Vec<String>,
573
    },
574
    /// Mark CHANGE... (or the state under test) as bad
575
    Bad {
576
        /// Changes known to be bad (default: the state under test)
577
        changes: Vec<String>,
578
    },
579
    /// The state under test cannot be tested; try another
580
    Skip,
581
    /// Run a command for each step: exit 0 good, 125 skip, else bad
582
    Run {
583
        /// Command and arguments to run at each step
584
        #[arg(required = true, trailing_var_arg = true)]
585
        command: Vec<String>,
586
    },
587
    /// Where the search stands
588
    Status {
589
        /// Machine-readable output: one JSON document on stdout
590
        #[arg(long)]
591
        json: bool,
592
    },
593
    /// Restore the working copy and forget the search
594
    Reset,
595
}
596
597
#[derive(Subcommand)]
598
enum BookmarkCmd {
599
    /// Create a bookmark at CHANGE... (default: the working copy's base)
600
    Create {
601
        /// Name of the new bookmark
602
        name: String,
603
        /// Its heads (default: the working copy's base). A state is its
604
        /// heads and what they depend on: a change alone may leave out
605
        /// earlier changes of the current state, which is refused unless
606
        /// --upto or --only says which is meant
607
        changes: Vec<String>,
608
        /// Everything of the current state up to CHANGE..., as a Git
609
        /// branch at a commit would hold
610
        #[arg(long, conflicts_with = "only")]
611
        upto: bool,
612
        /// Just CHANGE... and what they depend on. Other changes to the
613
        /// same files are left out, so a file can come out partly edited;
614
        /// to add one change to a bookmark's work, give the bookmark's
615
        /// heads with it instead: `bookmark set NAME <its heads> CHANGE`
616
        #[arg(long)]
617
        only: bool,
618
    },
619
    /// Point an existing bookmark at CHANGE...
620
    Set {
621
        /// The bookmark to move
622
        name: String,
623
        /// Its new heads. A change alone may leave out changes the
624
        /// bookmark now holds that were recorded before it, which is
625
        /// refused unless --upto or --only says which is meant
626
        changes: Vec<String>,
627
        /// Everything the bookmark holds up to CHANGE..., as a Git branch
628
        /// moved to a commit would hold
629
        #[arg(long, conflicts_with = "only")]
630
        upto: bool,
631
        /// Just CHANGE... and what they depend on. Other changes to the
632
        /// same files are left out, so a file can come out partly edited;
633
        /// to add one change to a bookmark's work, give the bookmark's
634
        /// heads with it instead: `bookmark set NAME <its heads> CHANGE`
635
        #[arg(long)]
636
        only: bool,
637
    },
638
    /// Remove a bookmark; its changes stay
639
    Delete {
640
        /// The bookmark to remove
641
        name: String,
642
    },
643
    /// List bookmarks with their heads and difference from origin
644
    List {
645
        /// Also list remotes' bookmarks that have no local bookmark
646
        #[arg(long, short)]
647
        all: bool,
648
        /// Each head of every bookmark, as `bookmark show` prints them
649
        #[arg(long, short)]
650
        verbose: bool,
651
        /// Machine-readable output: one JSON document on stdout
652
        #[arg(long)]
653
        json: bool,
654
    },
655
    /// A bookmark's heads: each change nothing else on it depends on,
656
    /// newest first. A bookmark name is also a revset for its heads
657
    /// (`oxy log -r NAME`, or `bookmark(NAME)` to mean only the bookmark)
658
    Show {
659
        /// The bookmark, or REMOTE/NAME (default: the current one)
660
        name: Option<String>,
661
        /// Machine-readable output: one JSON document on stdout
662
        #[arg(long)]
663
        json: bool,
664
    },
665
    /// Make NAME this workspace's bookmark and check it out. Uncommitted work stops it; --carry takes the work along, --discard drops it
666
    Switch {
667
        /// The bookmark to work on; one only a remote has (NAME or REMOTE/NAME) is created from it
668
        name: String,
669
        /// Throw away uncommitted working-copy changes
670
        #[arg(long)]
671
        discard: bool,
672
        /// Take uncommitted changes along; refused when NAME has other
673
        /// versions of the files they touch
674
        #[arg(long, conflicts_with = "discard")]
675
        carry: bool,
676
    },
677
}
678
679
#[derive(Subcommand)]
680
enum AuthCmd {
681
    /// Sign in to HUB in the browser (device sign-in) and keep the token for
682
    /// every repository there
683
    Login {
684
        /// The hub, as https://oxygenhub.io or oxygenhub.io (default: this checkout's origin)
685
        hub: Option<String>,
686
        /// Read a token from standard input instead (for CI and scripts)
687
        #[arg(long)]
688
        with_token: bool,
689
        /// PEM file of extra roots to trust (a hub with a self-signed certificate)
690
        #[arg(long)]
691
        ca: Option<PathBuf>,
692
    },
693
    /// List the hubs you are signed in to, checking each token with its hub
694
    Status,
695
    /// Forget HUB's token and revoke it on the hub
696
    Logout {
697
        /// The hub (default: this checkout's origin, or the only one)
698
        hub: Option<String>,
699
    },
700
}
701
702
#[derive(Subcommand)]
703
enum SubmoduleCmd {
704
    /// Clone URL (Oxygen or Git) into PATH and register it in .oxymodules
705
    Add {
706
        /// URL or path of the Oxygen or Git repository
707
        url: String,
708
        /// Where to put it, relative to the repository root
709
        path: String,
710
        /// Bookmark (Oxygen) or branch (Git) to check out and track
711
        #[arg(long)]
712
        bookmark: Option<String>,
713
    },
714
    /// Bring nested repositories to their pins
715
    Update {
716
        /// Clone nested repositories that are absent
717
        #[arg(long)]
718
        init: bool,
719
        /// Subrepos to update (default: all)
720
        paths: Vec<String>,
721
    },
722
    /// List subrepos with their pins and on-disk state
723
    Status {
724
        /// Machine-readable output: one JSON document on stdout
725
        #[arg(long)]
726
        json: bool,
727
    },
728
    /// Unregister PATH; the directory stays, the node goes with the next commit
729
    Remove {
730
        /// The subrepo to unregister
731
        path: String,
732
    },
733
}
734
735
#[derive(Subcommand)]
736
enum ReceiptCmd {
737
    /// The receipts kept for a state (default: the bookmark heads)
738
    List {
739
        /// Change, bookmark or tag whose state to look at
740
        rev: Option<String>,
741
        /// Machine-readable output: one JSON document on stdout
742
        #[arg(long)]
743
        json: bool,
744
    },
745
    /// One receipt in full, and whether its signature verifies
746
    Show {
747
        /// The receipt (a prefix of its hash, as `list` shows it)
748
        receipt: String,
749
        /// Change, bookmark or tag whose state holds it
750
        #[arg(long)]
751
        rev: Option<String>,
752
        /// Machine-readable output: one JSON document on stdout
753
        #[arg(long)]
754
        json: bool,
755
    },
756
    /// Write a signed receipt to FILE
757
    Export {
758
        /// The receipt (a prefix of its hash, as `list` shows it)
759
        receipt: String,
760
        /// Where to write it
761
        file: String,
762
        /// Change, bookmark or tag whose state holds it
763
        #[arg(long)]
764
        rev: Option<String>,
765
        /// `oxygen`: the runner's signed receipt, as `verify` and `import`
766
        /// read it. `slsa`: SLSA provenance in a DSSE envelope, signed with
767
        /// your key, for in-toto and cosign (`oxy identity export --pem`
768
        /// gives the key they check it with)
769
        #[arg(long, default_value = "oxygen", value_parser = ["oxygen", "slsa"])]
770
        format: String,
771
    },
772
    /// Check a signed receipt in FILE without keeping it
773
    Verify {
774
        /// A signed receipt, as a runner or `export` writes it
775
        file: String,
776
        /// Machine-readable output: one JSON document on stdout
777
        #[arg(long)]
778
        json: bool,
779
    },
780
    /// Verify a signed receipt in FILE and keep it with its state
781
    Import {
782
        /// A signed receipt, as a runner or `export` writes it
783
        file: String,
784
    },
785
}
786
787
#[derive(Subcommand)]
788
enum TagCmd {
789
    /// Tag the state of CHANGE... (default: the bookmark heads)
790
    Create {
791
        /// Name of the tag; tags never move
792
        name: String,
793
        /// Changes whose state to tag (default: the bookmark heads)
794
        changes: Vec<String>,
795
        /// A message recorded with the tag
796
        #[arg(short, long, default_value = "")]
797
        message: String,
798
    },
799
    /// List tags and the states they name
800
    List {
801
        /// Machine-readable output: one JSON document on stdout
802
        #[arg(long)]
803
        json: bool,
804
    },
805
}
806
807
#[derive(Subcommand)]
808
enum RemoteCmd {
809
    /// Add a remote
810
    Add {
811
        /// Name to refer to the remote by, such as origin
812
        name: String,
813
        /// 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
814
        url: String,
815
        /// For an s3:// store: the AWS profile to use (default: AWS_PROFILE, else "default")
816
        #[arg(long)]
817
        profile: Option<String>,
818
        /// For an s3:// store: its region (default: the environment, the profile, else asked of S3)
819
        #[arg(long)]
820
        region: Option<String>,
821
        /// For an s3://, gs:// or az:// store: another endpoint, such as an S3-compatible service
822
        #[arg(long)]
823
        endpoint: Option<String>,
824
        /// For a gs:// store: a service account key file, or application default credentials
825
        #[arg(long)]
826
        credentials: Option<String>,
827
    },
828
    /// Check a remote: that it is reachable with the credentials in hand, what it holds, and (for a store) that it behaves
829
    Check {
830
        /// The remote to check
831
        name: String,
832
    },
833
    /// Remove a remote
834
    Remove {
835
        /// The remote to remove
836
        name: String,
837
    },
838
    /// List remotes and their URLs
839
    List {
840
        /// Machine-readable output: one JSON document on stdout
841
        #[arg(long)]
842
        json: bool,
843
    },
844
}
845
846
#[derive(Subcommand)]
847
enum ProposalCmd {
848
    /// Show a proposal by its hub URL
849
    Show {
850
        /// The proposal's URL on the hub
851
        url: String,
852
        /// Machine-readable output: one JSON document on stdout
853
        #[arg(long)]
854
        json: bool,
855
    },
856
    /// Fetch the proposal's changes, set the target bookmark to the projected state, and push with your key
857
    Land {
858
        /// The proposal's URL on the hub
859
        url: String,
860
        /// Land even when the hub reports blockers
861
        #[arg(long)]
862
        force: bool,
863
    },
864
}
865
866
#[derive(Subcommand)]
867
enum IdentityCmd {
868
    /// Generate a composite Ed25519 + ML-DSA-65 key pair and make it your author identity
869
    Create {
870
        /// Your name (default: author.name)
871
        #[arg(long)]
872
        name: Option<String>,
873
        /// Your email (default: author.email)
874
        #[arg(long)]
875
        email: Option<String>,
876
        /// Record the author in this repository only, not in the user config
877
        #[arg(long)]
878
        local: bool,
879
        /// Expire the identity this many days from now
880
        #[arg(long)]
881
        expires: Option<u64>,
882
    },
883
    /// Show the configured identity
884
    Show,
885
    /// Write your identity object to a file, to hand to a policy holder
886
    Export {
887
        /// File to write (default: <key>.identity, or <key>.pem with --pem, in the current directory)
888
        path: Option<PathBuf>,
889
        /// Write the Ed25519 public key as PEM instead, as cosign's --key and
890
        /// other DSSE verifiers take it
891
        #[arg(long)]
892
        pem: bool,
893
    },
894
    /// Sign a host's challenge (hex, at least 16 bytes) to prove you hold your key; prints the signature as hex
895
    SignChallenge {
896
        /// The host's challenge, as hex
897
        challenge: String,
898
        /// Machine-readable output: one JSON document on stdout
899
        #[arg(long)]
900
        json: bool,
901
    },
902
    /// Move to a fresh key pair; the policy follows if it names your key
903
    Rotate,
904
    /// Re-issue your identity with a new expiry (in days from now; 0 = never)
905
    Renew {
906
        /// Days from now until it expires; 0 for never
907
        #[arg(long)]
908
        expires: u64,
909
    },
910
    /// Revoke a key: yours by default, or any key if you hold a policy root
911
    Revoke {
912
        /// KeyId prefix (default: your own key)
913
        key: Option<String>,
914
        /// Why, recorded in the revocation
915
        #[arg(long, default_value = "")]
916
        reason: String,
917
    },
918
    /// Keys allowed to sign or seal on your behalf
919
    Delegate {
920
        #[command(subcommand)]
921
        cmd: DelegateCmd,
922
    },
923
}
924
925
#[derive(Subcommand)]
926
enum DelegateCmd {
927
    /// Add a delegate from an exported identity file
928
    Add {
929
        /// The delegates' exported identity files: one rotation for all of them
930
        #[arg(required = true)]
931
        identity_file: Vec<PathBuf>,
932
        /// What it may do for you: changes, refs, seal (comma-separated) or all.
933
        /// An agent gets `changes`; a host that lands for you needs `changes,refs`
934
        #[arg(long, default_value = "changes")]
935
        scope: String,
936
        /// How long for: 30m, 8h, 7d, or a number of days (default: until removed)
937
        #[arg(long)]
938
        expires: Option<String>,
939
    },
940
    /// Remove a delegate by KeyId prefix
941
    Remove {
942
        /// KeyId prefix of the delegate
943
        key: String,
944
    },
945
    /// List delegates
946
    List,
947
}
948
949
#[derive(Subcommand)]
950
enum GitCmd {
951
    /// Export the current bookmark to a Git repository (created bare if absent)
952
    Export {
953
        /// Git repository to write to (created bare if absent)
954
        git_dir: PathBuf,
955
        /// Git branch to write (default: the bookmark name)
956
        #[arg(long)]
957
        branch: Option<String>,
958
    },
959
    /// Fetch a branch from a Git remote (path or URL) into the current bookmark
960
    Fetch {
961
        /// Git remote: a path or URL
962
        url: String,
963
        /// Branch to fetch
964
        #[arg(long, default_value = "main")]
965
        branch: String,
966
        /// Author your own commits (Git author email = your identity's) with your key; sets git.claim
967
        #[arg(long)]
968
        claim: bool,
969
    },
970
    /// Push the current bookmark to a branch of a Git remote (fetch first)
971
    Push {
972
        /// Git remote: a path or URL
973
        url: String,
974
        /// Branch to push to
975
        #[arg(long, default_value = "main")]
976
        branch: String,
977
    },
978
    /// 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
979
    Recover,
980
    /// Check this repository's import of a Git branch: every commit's tree must be reproduced exactly
981
    Verify {
982
        /// The Git repository the import came from
983
        git_dir: PathBuf,
984
        /// Branch that was imported
985
        #[arg(long, default_value = "main")]
986
        branch: String,
987
        /// Rebuild only the last N commits (the others are followed, not checked)
988
        #[arg(long, value_name = "N")]
989
        last: Option<usize>,
990
        /// Stop after N differences (0: check every commit whatever it finds)
991
        #[arg(long, value_name = "N", default_value_t = 50)]
992
        max_differences: usize,
993
    },
994
    /// Import a Git branch into a new Oxygen repository at DEST
995
    Import {
996
        /// Git repository to read
997
        git_dir: PathBuf,
998
        /// Directory for the new Oxygen repository
999
        dest: PathBuf,
1000
        /// Branch to import
1001
        #[arg(long, default_value = "main")]
1002
        branch: String,
1003
        /// Author your own commits (Git author email = your identity's) with your key; sets git.claim
1004
        #[arg(long)]
1005
        claim: bool,
1006
    },
1007
}
1008
1009
#[derive(Subcommand)]
1010
enum PolicyCmd {
1011
    /// Create the initial policy with your identity as the only root
1012
    Init,
1013
    /// Show the current policy
1014
    Show {
1015
        /// Machine-readable output: one JSON document on stdout
1016
        #[arg(long)]
1017
        json: bool,
1018
    },
1019
    /// Allow an identity (from `oxy identity export`) to update bookmarks
1020
    Grant {
1021
        /// The identity to grant, exported with `oxy identity export`
1022
        identity_file: PathBuf,
1023
        /// Reference pattern the grant applies to (default: every bookmark)
1024
        #[arg(long)]
1025
        pattern: Option<String>,
1026
        /// Where to write the proposal when more root signatures are needed
1027
        #[arg(long)]
1028
        out: Option<PathBuf>,
1029
    },
1030
    /// Revoke a key (KeyId prefix of an identity in the policy)
1031
    Revoke {
1032
        /// KeyId prefix of the identity
1033
        key: String,
1034
        /// Where to write the proposal when more root signatures are needed
1035
        #[arg(long)]
1036
        out: Option<PathBuf>,
1037
    },
1038
    /// Manage root keys and the signature threshold for policy updates
1039
    Root {
1040
        #[command(subcommand)]
1041
        cmd: RootCmd,
1042
    },
1043
    /// Add your root signature to a proposal file; applies it once the threshold is met
1044
    Sign {
1045
        /// The proposal file to sign
1046
        proposal: PathBuf,
1047
        /// Where to write the proposal if it still needs signatures (default: in place)
1048
        #[arg(long)]
1049
        out: Option<PathBuf>,
1050
    },
1051
}
1052
1053
#[derive(Subcommand)]
1054
enum RootCmd {
1055
    /// Make an exported identity a root key
1056
    Add {
1057
        /// The identity to make a root, exported with `oxy identity export`
1058
        identity_file: PathBuf,
1059
        /// Where to write the proposal when more root signatures are needed
1060
        #[arg(long)]
1061
        out: Option<PathBuf>,
1062
    },
1063
    /// Remove a root key by KeyId prefix
1064
    Remove {
1065
        /// KeyId prefix of the root key
1066
        key: String,
1067
        /// Where to write the proposal when more root signatures are needed
1068
        #[arg(long)]
1069
        out: Option<PathBuf>,
1070
    },
1071
    /// Require this many root signatures on policy updates
1072
    Threshold {
1073
        /// Number of root signatures
1074
        n: u32,
1075
        /// Where to write the proposal when more root signatures are needed
1076
        #[arg(long)]
1077
        out: Option<PathBuf>,
1078
    },
1079
}
1080
1081
/// Open the repository containing the current directory.
1082119×
fn open() -> Result<Repo> {
1083119×
    let repo = Repo::open(&std::env::current_dir()?).context("opening repository")?;
1084119×
    match AT_OP.get().and_then(|o| o.as_deref()) {
10850×
        Some(op) => Ok(repo.at_op(op)?),
1086119×
        None => Ok(repo),
1087
    }
1088119×
}
1089
1090
/// `oxy man`: every page into `dir`, or the top-level page on stdout.
10912×
fn man(dir: Option<PathBuf>) -> Result<i32> {
1092
    use clap::CommandFactory;
10932×
    let cmd = Cli::command();
10942×
    match dir {
10951×
        Some(dir) => {
10961×
            std::fs::create_dir_all(&dir)?;
10971×
            clap_mangen::generate_to(cmd, &dir)?;
10981×
            let pages = std::fs::read_dir(&dir)?
1099120×
                .filter(|e| {
1100120×
                    e.as_ref()
1101120×
                        .is_ok_and(|e| e.path().extension().is_some_and(|x| x == "1"))
1102120×
                })
11031×
                .count();
11041×
            println!(
1105
                "{}",
11061×
                ui::done(format!("Wrote {pages} man pages to {}", dir.display()))
1107
            );
1108
        }
11091×
        None => clap_mangen::Man::new(cmd).render(&mut std::io::stdout())?,
1110
    }
11112×
    Ok(0)
11122×
}
1113
1114
/// Parse arguments and run; returns the process exit code.
1115149×
pub fn run() -> Result<i32> {
1116
    // The cloud stores (s3://, gs://, az://) for remotes kept on them.
1117149×
    oxy_strata::register();
1118149×
    let cli = Cli::parse();
1119149×
    ui::init(cli.plain);
1120149×
    AT_OP.set(cli.at_op.clone()).ok();
11210×
    match cli.cmd {
11224×
        Cmd::Completions { shell } => {
1123
            use clap::CommandFactory;
11244×
            clap_complete::generate(shell, &mut Cli::command(), "oxy", &mut std::io::stdout());
11254×
            Ok(0)
1126
        }
11272×
        Cmd::Man { dir } => man(dir),
112814×
        Cmd::Init { path, bare, store } => workspace::init(path, bare, store.as_deref()),
11298×
        Cmd::Status { json } => workspace::status(json),
1130
        Cmd::Prompt {
11310×
            format,
11320×
            glyphs,
11330×
            color,
11340×
        } => workspace::prompt(&format, glyphs, color.as_deref()),
1135
        Cmd::Commit {
113626×
            message,
113726×
            file,
113826×
            depends_on,
113926×
            paths,
114026×
            interactive,
114126×
            hunks,
1142
        } => {
114326×
            let message = match (message, file) {
114425×
                (Some(m), _) => m,
11451×
                (None, Some(f)) if f.as_os_str() == "-" => {
11460×
                    let mut s = String::new();
11470×
                    std::io::Read::read_to_string(&mut std::io::stdin(), &mut s)?;
11480×
                    s
1149
                }
11501×
                (None, Some(f)) => std::fs::read_to_string(&f).map_err(|e| {
11510×
                    anyhow::anyhow!("reading the message from {}: {e}", f.display())
11520×
                })?,
11530×
                (None, None) => anyhow::bail!("a commit message is required (-m or -F)"),
1154
            };
115526×
            workspace::commit(&message, &depends_on, &paths, interactive, &hunks)
1156
        }
11572×
        Cmd::Cat { path, change } => workspace::cat(&path, change.as_deref()),
11581×
        Cmd::Root { json } => workspace::root(json),
11591×
        Cmd::Version { json } => workspace::version(json),
11602×
        Cmd::Discard { paths, hunks } => workspace::discard(&paths, &hunks),
11612×
        Cmd::Hunks { json } => workspace::hunks(json),
11620×
        Cmd::Squash { change, into } => workspace::squash(&change, &into),
1163
        Cmd::Rebase {
11640×
            change,
11650×
            onto,
11660×
            into_working_copy,
11670×
        } => workspace::rebase(&change, &onto, into_working_copy),
11680×
        Cmd::Blame { path, json } => workspace::blame(&path, json),
11691×
        Cmd::Bisect { cmd } => match cmd {
11700×
            BisectCmd::Start => workspace::bisect_start(),
11710×
            BisectCmd::Good { changes } => workspace::bisect_mark(Some(true), &changes),
11720×
            BisectCmd::Bad { changes } => workspace::bisect_mark(Some(false), &changes),
11730×
            BisectCmd::Skip => workspace::bisect_mark(None, &[]),
11740×
            BisectCmd::Run { command } => workspace::bisect_run(&command),
11751×
            BisectCmd::Status { json } => workspace::bisect_status(json),
11760×
            BisectCmd::Reset => workspace::bisect_reset(),
1177
        },
1178
        Cmd::Log {
11798×
            revset,
11808×
            limit,
11818×
            verbose,
11828×
            path,
11838×
            lines,
11848×
            json,
11858×
        } => workspace::log(
11868×
            revset.as_deref(),
11878×
            limit,
11888×
            verbose,
11898×
            path.as_deref(),
11908×
            lines.as_deref(),
11918×
            json,
1192
        ),
11931×
        Cmd::Diff { change, json } => workspace::diff(change.as_deref(), json),
1194
        Cmd::Describe {
11954×
            message,
11964×
            change,
11974×
            json,
11984×
        } => match message {
11990×
            Some(m) => workspace::describe(&m, change.as_deref()),
12004×
            None if change.is_some() => {
12010×
                anyhow::bail!(
1202
                    "naming works on the working copy; to change a head's message pass -m"
1203
                )
1204
            }
12054×
            None => workspace::describe_name(json),
1206
        },
12070×
        Cmd::Amend { message, into } => workspace::amend(message.as_deref(), into.as_deref()),
12080×
        Cmd::Split { change, paths } => workspace::split(&change, &paths),
1209
        Cmd::Abandon {
12100×
            change,
12110×
            revset,
12120×
            yes,
12130×
        } => workspace::abandon(change.as_deref(), revset.as_deref(), yes),
1214
        Cmd::Show {
12152×
            change,
12162×
            revset,
12172×
            json,
12182×
        } => workspace::show(change.as_deref(), revset.as_deref(), json),
1219
        Cmd::Checkout {
12200×
            changes,
12210×
            discard,
12220×
            carry,
12230×
        } => workspace::checkout(&changes, discard, carry),
12241×
        Cmd::Resolve { json } => workspace::resolve(json),
12250×
        Cmd::Undo => workspace::undo(),
1226
        Cmd::Gc {
12272×
            now,
12282×
            expire_snapshots,
12292×
            remote,
12302×
        } => match remote {
12312×
            Some(name) => workspace::gc_remote(&name, now),
12320×
            None => workspace::gc(now, expire_snapshots),
1233
        },
12340×
        Cmd::Fsck { json } => workspace::fsck(json),
12350×
        Cmd::Doctor { offline, json } => workspace::doctor(offline, json),
12360×
        Cmd::Checkpoint => workspace::checkpoint(),
12371×
        Cmd::Op { cmd } => match cmd {
12381×
            OpCmd::Log { limit, json } => workspace::op_log(limit, json),
12390×
            OpCmd::Restore { op, discard } => workspace::op_restore(&op, discard),
12400×
            OpCmd::Revert { op } => workspace::op_revert(&op),
1241
        },
1242
        Cmd::Clone {
12435×
            url,
12445×
            dest,
12455×
            max_blob,
12465×
            sparse,
12475×
            depth,
12485×
            recursive,
12495×
        } => sync::clone(&url, dest, max_blob.as_deref(), &sparse, depth, recursive),
12500×
        Cmd::Deepen { depth, remote } => sync::deepen(&remote, depth),
12510×
        Cmd::Sparse { paths } => workspace::sparse(&paths),
12520×
        Cmd::Lock { path } => workspace::lock(&path),
12530×
        Cmd::Unlock { path } => workspace::unlock(&path),
12541×
        Cmd::Workspace { cmd } => match cmd {
12550×
            WorkspaceCmd::Add { path, changes } => workspace::workspace_add(&path, &changes),
12561×
            WorkspaceCmd::List { json } => workspace::workspace_list(json),
12570×
            WorkspaceCmd::Forget { workspace } => workspace::workspace_forget(&workspace),
1258
        },
125917×
        Cmd::Bookmark { cmd } => match cmd {
1260
            BookmarkCmd::Create {
12616×
                name,
12626×
                changes,
12636×
                upto,
12646×
                only,
12656×
            } => workspace::bookmark_create(&name, &changes, upto, only),
1266
            BookmarkCmd::Set {
12673×
                name,
12683×
                changes,
12693×
                upto,
12703×
                only,
12713×
            } => workspace::bookmark_set(&name, &changes, upto, only),
12720×
            BookmarkCmd::Delete { name } => workspace::bookmark_delete(&name),
12735×
            BookmarkCmd::List { all, verbose, json } => {
12745×
                workspace::bookmark_list(all, verbose, json)
1275
            }
12760×
            BookmarkCmd::Show { name, json } => workspace::bookmark_show(name.as_deref(), json),
1277
            BookmarkCmd::Switch {
12783×
                name,
12793×
                discard,
12803×
                carry,
12813×
            } => workspace::bookmark_switch(&name, discard, carry),
1282
        },
12830×
        Cmd::Merge { bookmark } => workspace::merge(&bookmark),
12840×
        Cmd::Auth { cmd } => match cmd {
1285
            AuthCmd::Login {
12860×
                hub,
12870×
                with_token,
12880×
                ca,
12890×
            } => auth::login(hub.as_deref(), with_token, ca),
12900×
            AuthCmd::Status => auth::status(),
12910×
            AuthCmd::Logout { hub } => auth::logout(hub.as_deref()),
1292
        },
12931×
        Cmd::Submodule { cmd } => match cmd {
1294
            SubmoduleCmd::Add {
12950×
                url,
12960×
                path,
12970×
                bookmark,
12980×
            } => sync::submodule_add(&url, &path, bookmark.as_deref()),
12990×
            SubmoduleCmd::Update { init, paths } => sync::submodule_update(init, &paths),
13001×
            SubmoduleCmd::Status { json } => sync::submodule_status(json),
13010×
            SubmoduleCmd::Remove { path } => sync::submodule_remove(&path),
1302
        },
130310×
        Cmd::Receipt { cmd } => match cmd {
13042×
            ReceiptCmd::List { rev, json } => receipt::list(rev.as_deref(), json),
1305
            ReceiptCmd::Show {
13061×
                receipt: r,
13071×
                rev,
13081×
                json,
13091×
            } => receipt::show(&r, rev.as_deref(), json),
1310
            ReceiptCmd::Export {
13113×
                receipt: r,
13123×
                file,
13133×
                rev,
13143×
                format,
13153×
            } => receipt::export(&r, &file, rev.as_deref(), &format),
13162×
            ReceiptCmd::Verify { file, json } => receipt::verify(&file, json),
13172×
            ReceiptCmd::Import { file } => receipt::import(&file),
1318
        },
13193×
        Cmd::Tag { cmd } => match cmd {
1320
            TagCmd::Create {
13212×
                name,
13222×
                changes,
13232×
                message,
13242×
            } => workspace::tag_create(&name, &changes, &message),
13251×
            TagCmd::List { json } => workspace::tag_list(json),
1326
        },
132710×
        Cmd::Remote { cmd } => match cmd {
1328
            RemoteCmd::Add {
13294×
                name,
13304×
                url,
13314×
                profile,
13324×
                region,
13334×
                endpoint,
13344×
                credentials,
13354×
            } => sync::remote_add(
13364×
                &name,
13374×
                &url,
13384×
                &[
13394×
                    ("profile", profile),
13404×
                    ("region", region),
13414×
                    ("endpoint", endpoint),
13424×
                    ("credentials", credentials),
13434×
                ],
1344
            ),
13453×
            RemoteCmd::Check { name } => sync::remote_check(&name),
13461×
            RemoteCmd::Remove { name } => sync::remote_remove(&name),
13472×
            RemoteCmd::List { json } => sync::remote_list(json),
1348
        },
13491×
        Cmd::Fetch { remote, json } => sync::fetch(remote.as_deref(), json),
13504×
        Cmd::Pull { remote, json } => sync::pull(remote.as_deref(), json),
1351
        Cmd::Push {
13527×
            remote,
13537×
            force,
13547×
            bookmark,
13557×
            delete,
13567×
            json,
13577×
        } => match delete {
13580×
            Some(name) => sync::push_delete(remote.as_deref(), &name, json),
13597×
            None => sync::push(remote.as_deref(), force, bookmark.as_deref(), json),
1360
        },
1361
        Cmd::Serve {
13620×
            root,
13630×
            bind,
13640×
            tokens,
13650×
            tls_cert,
13660×
            tls_key,
13670×
        } => sync::serve(root, &bind, tokens, tls_cert.zip(tls_key)),
13683×
        Cmd::Identity { cmd } => match cmd {
1369
            IdentityCmd::Create {
13702×
                name,
13712×
                email,
13722×
                local,
13732×
                expires,
13742×
            } => identity::create(name, email, local, expires),
13750×
            IdentityCmd::Show => identity::show(),
13761×
            IdentityCmd::Export { path, pem } => identity::export(path, pem),
13770×
            IdentityCmd::SignChallenge { challenge, json } => {
13780×
                identity::sign_challenge(&challenge, json)
1379
            }
13800×
            IdentityCmd::Rotate => identity::rotate(),
13810×
            IdentityCmd::Renew { expires } => identity::renew(expires),
13820×
            IdentityCmd::Revoke { key, reason } => identity::revoke(key.as_deref(), &reason),
13830×
            IdentityCmd::Delegate { cmd } => match cmd {
1384
                DelegateCmd::Add {
13850×
                    identity_file,
13860×
                    scope,
13870×
                    expires,
13880×
                } => identity::delegate_add(&identity_file, &scope, expires.as_deref()),
13890×
                DelegateCmd::Remove { key } => identity::delegate_remove(&key),
13900×
                DelegateCmd::List => identity::delegate_list(),
1391
            },
1392
        },
1393
        Cmd::Git {
13940×
            cmd: GitCmd::Export { git_dir, branch },
13950×
        } => sync::git_export(&git_dir, branch.as_deref()),
1396
        Cmd::Git {
13970×
            cmd: GitCmd::Fetch { url, branch, claim },
13980×
        } => sync::git_fetch(&url, &branch, claim),
1399
        Cmd::Git {
14000×
            cmd: GitCmd::Push { url, branch },
14010×
        } => sync::git_push(&url, &branch),
1402
        Cmd::Git {
1403
            cmd: GitCmd::Recover,
14040×
        } => sync::git_recover(),
1405
        Cmd::Git {
1406
            cmd:
1407
                GitCmd::Import {
14080×
                    git_dir,
14090×
                    dest,
14100×
                    branch,
14110×
                    claim,
1412
                },
14130×
        } => sync::git_import(&git_dir, &dest, &branch, claim),
1414
        Cmd::Git {
1415
            cmd:
1416
                GitCmd::Verify {
14170×
                    git_dir,
14180×
                    branch,
14190×
                    last,
14200×
                    max_differences,
1421
                },
14220×
        } => sync::git_verify(&git_dir, &branch, last, max_differences),
14233×
        Cmd::Policy { cmd } => match cmd {
14241×
            PolicyCmd::Init => identity::policy_init(),
14252×
            PolicyCmd::Show { json } => identity::policy_show(json),
1426
            PolicyCmd::Grant {
14270×
                identity_file,
14280×
                pattern,
14290×
                out,
14300×
            } => identity::policy_grant(&identity_file, pattern.as_deref(), out),
14310×
            PolicyCmd::Revoke { key, out } => identity::policy_revoke(&key, out),
14320×
            PolicyCmd::Root { cmd } => match cmd {
14330×
                RootCmd::Add { identity_file, out } => {
14340×
                    identity::policy_root_add(&identity_file, out)
1435
                }
14360×
                RootCmd::Remove { key, out } => identity::policy_root_remove(&key, out),
14370×
                RootCmd::Threshold { n, out } => identity::policy_threshold(n, out),
1438
            },
14390×
            PolicyCmd::Sign { proposal, out } => identity::policy_sign(&proposal, out),
1440
        },
1441
        Cmd::Seal {
14420×
            flow: Some(url),
14430×
            job: Some(job),
14440×
            reject,
14450×
            json,
1446
            ..
14470×
        } => approve::seal(&url, &job, reject, json),
1448
        Cmd::Seal {
14490×
            changes,
14500×
            proposal: Some(url),
14510×
            json,
1452
            ..
14530×
        } if changes.is_empty() => proposal::seal(&url, json),
14540×
        Cmd::Seal { changes, json, .. } => identity::seal(&changes, json),
14550×
        Cmd::Proposal { cmd } => match cmd {
14560×
            ProposalCmd::Show { url, json } => proposal::show(&url, json),
14570×
            ProposalCmd::Land { url, force } => proposal::land(&url, force),
1458
        },
1459
        Cmd::Verify {
14601×
            change,
14611×
            revset,
14621×
            json,
14631×
        } => identity::verify(change.as_deref(), revset.as_deref(), json),
1464
        Cmd::Config {
14651×
            key,
14661×
            value,
14671×
            user,
14681×
            unset,
14691×
        } => identity::config(&key, value.as_deref().unwrap_or(""), user, unset),
1470
    }
1471149×
}
1472
1473
#[cfg(test)]
1474
mod help_tests {
1475
    use super::Cli;
1476
    use clap::CommandFactory;
1477
1478
    /// Every command and every argument explains itself, so `--help`,
1479
    /// completions and the man pages are complete.
1480
    #[test]
14811×
    fn every_command_and_argument_has_help() {
1482120×
        fn walk(cmd: &clap::Command, path: &str, missing: &mut Vec<String>) {
1483120×
            let here = format!("{path} {}", cmd.get_name()).trim().to_string();
1484120×
            if cmd.get_about().is_none() && !path.is_empty() {
14850×
                missing.push(format!("{here} (command)"));
1486120×
            }
1487215×
            for a in cmd.get_arguments() {
1488215×
                let id = a.get_id().as_str();
1489215×
                if id == "help" || id == "version" || (a.is_global_set() && !path.is_empty()) {
14900×
                    continue;
1491215×
                }
1492215×
                if a.get_help().is_none() && a.get_long_help().is_none() {
14930×
                    missing.push(format!("{here} {id}"));
1494215×
                }
1495
            }
1496120×
            for sub in cmd.get_subcommands() {
1497119×
                walk(sub, &here, missing);
1498119×
            }
1499120×
        }
15001×
        let mut missing = Vec::new();
15011×
        walk(&Cli::command(), "", &mut missing);
15021×
        assert!(
15031×
            missing.is_empty(),
1504
            "{} without help:\n{}",
15050×
            missing.len(),
15060×
            missing.join("\n")
1507
        );
15081×
    }
1509
}