OXYGENHUB
# d256e826ac5d oxygen / src / cli / mod.rs
48.7 KiB · Rust · last changed A repository kept on a store: oxy init --store 1 month ago source blame history raw
1
//! Command-line definitions and dispatch.
2
3
mod auth;
4
mod format;
5
mod identity;
6
mod json;
7
mod proposal;
8
mod receipt;
9
mod sync;
10
pub mod ui;
11
mod workspace;
12
13
use anyhow::{Context, Result};
14
use clap::{Parser, Subcommand};
15
use oxy_core::repo::Repo;
16
use std::path::PathBuf;
17
18
#[derive(Parser)]
19
#[command(
20
    name = "oxy",
21
    version = env!("OXY_VERSION_LONG"),
22
    about = "Oxygen: breathing fresh air into version control"
23
)]
24
struct Cli {
25
    /// Plain output: no colour, no spinner (also implied by NO_COLOR or a non-terminal)
26
    #[arg(long, global = true)]
27
    plain: bool,
28
    /// Read the repository as it was after operation OP (an ID from oxy op log, @ or @-); commands that would change it are refused
29
    #[arg(long, global = true, value_name = "OP")]
30
    at_op: Option<String>,
31
    #[command(subcommand)]
32
    cmd: Cmd,
33
}
34
35
/// `--at-op`, for `open` to apply.
36
static AT_OP: std::sync::OnceLock<Option<String>> = std::sync::OnceLock::new();
37
38
#[derive(Subcommand)]
39
enum Cmd {
40
    /// Create a repository in PATH (default: current directory)
41
    Init {
42
        /// Directory to create the repository in (default: the current directory)
43
        path: Option<PathBuf>,
44
        /// No working copy: an object store and references only, for hosting
45
        #[arg(long)]
46
        bare: bool,
47
        /// Keep the objects and the operation log on this store
48
        /// (dir://PATH, s3://BUCKET/PREFIX, gs://…, az://…) instead of
49
        /// in .oxy, with a local cache in front (storage.cache, 2 GiB)
50
        #[arg(long, value_name = "URL")]
51
        store: Option<String>,
52
    },
53
    /// Clone a repository from a local path or an http(s) URL
54
    Clone {
55
        /// Local path or http(s) URL of the repository
56
        url: String,
57
        /// Directory to clone into (default: the last part of the URL)
58
        dest: Option<PathBuf>,
59
        /// Leave blobs larger than this (e.g. 1M) to be fetched on first read
60
        #[arg(long)]
61
        max_blob: Option<String>,
62
        /// Materialize only these paths (repeatable); implies lazy blobs
63
        #[arg(long = "sparse")]
64
        sparse: Vec<String>,
65
        /// Shallow clone: fetch only this many levels of history below the heads
66
        #[arg(long)]
67
        depth: Option<u32>,
68
        /// Clone the subrepos too (as oxy submodule update --init)
69
        #[arg(long)]
70
        recursive: bool,
71
    },
72
    /// Fetch more history below a shallow clone's boundary
73
    Deepen {
74
        /// Levels of history to add below the boundary
75
        #[arg(default_value_t = 10)]
76
        depth: u32,
77
        /// Remote to fetch the history from
78
        #[arg(long, default_value = "origin")]
79
        remote: String,
80
    },
81
    /// Show or set the sparse filter (paths to materialize); re-checks out the bookmark
82
    Sparse {
83
        /// Paths to materialize; none prints the current filter
84
        paths: Vec<String>,
85
    },
86
    /// Show the working copy: changed paths and conflicts
87
    Status {
88
        /// Machine-readable output: paths, and every conflict with its kind and contributing changes
89
        #[arg(long)]
90
        json: bool,
91
    },
92
    /// One-line summary for shell prompts; fast and records nothing
93
    Prompt {
94
        /// 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
95
        #[arg(long, default_value = oxy_core::repo::DEFAULT_PROMPT_FORMAT)]
96
        format: String,
97
        /// Glyph format (%i %b %c %s%U%O) instead of the plain default
98
        #[arg(long)]
99
        glyphs: bool,
100
        /// Colour by state (cyan clean, yellow dirty, red conflicted): raw escapes, or guarded for a bash or zsh PS1
101
        #[arg(long, value_parser = ["raw", "bash", "zsh"])]
102
        color: Option<String>,
103
    },
104
    /// Record the working copy as a change on the current bookmark
105
    Commit {
106
        /// The change's message: a subject line, then optionally a blank line and a body
107
        #[arg(short, long, required_unless_present = "file", conflicts_with = "file")]
108
        message: Option<String>,
109
        /// Read the message from FILE (`-` for standard input)
110
        #[arg(short = 'F', long, value_name = "FILE")]
111
        file: Option<PathBuf>,
112
        /// Extra explicit dependencies (ChangeId prefix, #hash prefix)
113
        #[arg(long = "depends-on")]
114
        depends_on: Vec<String>,
115
        /// Commit only these paths; the rest stays as uncommitted work
116
        paths: Vec<String>,
117
        /// Choose hunks one by one
118
        #[arg(short, long)]
119
        interactive: bool,
120
        /// Commit these hunks (as `oxy hunks` numbers them), comma separated
121
        #[arg(long, value_delimiter = ',')]
122
        hunks: Vec<usize>,
123
    },
124
    /// Fold CHANGE into one of its dependencies (keeps that change's id)
125
    Squash {
126
        /// The change to fold (ChangeId prefix, #hash prefix)
127
        change: String,
128
        /// The dependency that absorbs it
129
        #[arg(long)]
130
        into: String,
131
    },
132
    /// Re-express CHANGE against another base state
133
    Rebase {
134
        /// The change to re-express (ChangeId prefix, #hash prefix)
135
        change: String,
136
        /// The changes, bookmark or tag whose state becomes the new base
137
        #[arg(long, required = true, num_args = 1..)]
138
        onto: Vec<String>,
139
        /// Where the rebase would be conflicted, merge the target into the
140
        /// current bookmark instead, leaving the conflict in the working
141
        /// copy to fix and commit
142
        #[arg(long)]
143
        into_working_copy: bool,
144
    },
145
    /// Show which change introduced each line of a file
146
    Blame {
147
        /// File to annotate, relative to the repository root
148
        path: String,
149
        /// Machine-readable output: one JSON document on stdout
150
        #[arg(long)]
151
        json: bool,
152
    },
153
    /// Find the change that introduced a regression
154
    Bisect {
155
        #[command(subcommand)]
156
        cmd: BisectCmd,
157
    },
158
    /// List changes reachable from the bookmark and the working copy
159
    Log {
160
        /// Show the changes a revset selects: `main..feature & author(andy)`,
161
        /// `touches("src/**") & date(-7d..)` (see docs/revset_query_language.md)
162
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with_all = ["path", "lines"])]
163
        revset: Option<String>,
164
        /// Show at most this many changes
165
        #[arg(short = 'n', long)]
166
        limit: Option<usize>,
167
        /// Show full messages, dependencies, and signatures
168
        #[arg(short, long)]
169
        verbose: bool,
170
        /// Only changes touching this path (renames followed)
171
        #[arg(long)]
172
        path: Option<String>,
173
        /// Only changes that wrote or deleted lines START to END of PATH
174
        /// (numbered as in the working copy's base), or deleted lines from
175
        /// between them: the history of a function
176
        #[arg(short = 'L', value_name = "START,END:PATH", conflicts_with = "path")]
177
        lines: Option<String>,
178
        /// Machine-readable output: one JSON document on stdout
179
        #[arg(long)]
180
        json: bool,
181
    },
182
    /// Show what the working copy changes against its base
183
    Diff {
184
        /// A change instead of the working copy
185
        change: Option<String>,
186
        /// Machine-readable output: one JSON document on stdout
187
        #[arg(long)]
188
        json: bool,
189
    },
190
    /// Print a file as it is in a state (default: the working copy's base)
191
    Cat {
192
        /// File to print, relative to the repository root
193
        path: String,
194
        /// A change, bookmark, or tag
195
        #[arg(short = 'r', long)]
196
        change: Option<String>,
197
    },
198
    /// Print the repository root, workspace, and bookmark
199
    Root {
200
        /// Machine-readable output: one JSON document on stdout
201
        #[arg(long)]
202
        json: bool,
203
    },
204
    /// Print the version of oxy, its repository format, and protocol
205
    Version {
206
        /// Machine-readable output: one JSON document on stdout
207
        #[arg(long)]
208
        json: bool,
209
    },
210
    /// Restore paths to the working copy's base, or undo chosen hunks
211
    Discard {
212
        /// Paths to restore; none with --hunks, or everything with neither
213
        paths: Vec<String>,
214
        /// Hunk indices as `oxy hunks` numbers them, comma separated
215
        #[arg(long, value_delimiter = ',')]
216
        hunks: Vec<usize>,
217
    },
218
    /// List the working copy's hunks, numbered as commit --hunks expects
219
    Hunks {
220
        /// Machine-readable output: one JSON document on stdout
221
        #[arg(long)]
222
        json: bool,
223
    },
224
    /// With -m, change the message of a head; without, name the working
225
    /// copy for a build: its tag, or the nearest tag plus distance and
226
    /// change, or the bookmark and change, and -dirty
227
    Describe {
228
        /// The new message
229
        #[arg(short, long)]
230
        message: Option<String>,
231
        /// The head to describe (default: the one the working copy sits on)
232
        change: Option<String>,
233
        /// Machine-readable output (naming only)
234
        #[arg(long, conflicts_with = "message")]
235
        json: bool,
236
    },
237
    /// Fold the working copy into the head it sits on, or into CHANGE with --into
238
    Amend {
239
        /// Replace the message too
240
        #[arg(short, long)]
241
        message: Option<String>,
242
        /// Amend an older change; the edits must touch only lines it already knows
243
        #[arg(long)]
244
        into: Option<String>,
245
    },
246
    /// Split a head: the named paths become a separate first change
247
    Split {
248
        /// The head to split
249
        change: String,
250
        /// Paths whose edits become the first change
251
        paths: Vec<String>,
252
    },
253
    /// Drop a change from the bookmark; its content stays on disk as uncommitted work
254
    Abandon {
255
        /// The change to drop (ChangeId prefix, #hash prefix)
256
        #[arg(required_unless_present = "revset")]
257
        change: Option<String>,
258
        /// Drop every change a revset selects, newest first
259
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
260
        revset: Option<String>,
261
        /// Drop more than five changes without asking
262
        #[arg(long, short = 'y')]
263
        yes: bool,
264
    },
265
    /// Show one change (ChangeId prefix, #hash prefix, or @), or those a revset selects
266
    Show {
267
        /// ChangeId prefix, #hash prefix, or @ for the working copy
268
        #[arg(required_unless_present = "revset")]
269
        change: Option<String>,
270
        /// Show every change a revset selects
271
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
272
        revset: Option<String>,
273
        /// Machine-readable output: one JSON document on stdout
274
        #[arg(long)]
275
        json: bool,
276
    },
277
    /// Move the working copy to the state formed by CHANGE... (default: the bookmark heads)
278
    Checkout {
279
        /// Changes whose state to check out (default: the bookmark heads)
280
        changes: Vec<String>,
281
        /// Throw away uncommitted working-copy changes
282
        #[arg(long)]
283
        discard: bool,
284
        /// Take uncommitted changes along; refused when the target has
285
        /// other versions of the files they touch
286
        #[arg(long, conflicts_with = "discard")]
287
        carry: bool,
288
    },
289
    /// Report which conflicts of the working copy's base are resolved by the current files
290
    Resolve {
291
        /// Machine-readable output: one JSON document on stdout
292
        #[arg(long)]
293
        json: bool,
294
    },
295
    /// Undo the last operation
296
    Undo,
297
    /// Write a checkpoint of the current bookmark's state now
298
    Checkpoint,
299
    /// Print a shell completion script: `oxy completions bash > ~/.local/share/bash-completion/completions/oxy`
300
    Completions {
301
        /// bash, zsh, fish, elvish or powershell
302
        shell: clap_complete::Shell,
303
    },
304
    /// Write man pages (oxy.1 and one per command) into DIR, or print oxy.1
305
    Man {
306
        /// Directory to write every page into, e.g. ~/.local/share/man/man1
307
        #[arg(long)]
308
        dir: Option<PathBuf>,
309
    },
310
    /// Check the identity, configuration and remotes, and say what to do about any problem
311
    Doctor {
312
        /// Do not contact the remotes
313
        #[arg(long)]
314
        offline: bool,
315
        /// Machine-readable output: one JSON document on stdout
316
        #[arg(long)]
317
        json: bool,
318
    },
319
    /// Check the repository's integrity: objects, operation log, references, signatures, checkpoints
320
    Fsck {
321
        /// Machine-readable output: one JSON document on stdout
322
        #[arg(long)]
323
        json: bool,
324
    },
325
    /// Prune unreachable objects older than the grace period and repack everything into one pack
326
    Gc {
327
        /// Ignore the grace period (core.gc-grace) and prune immediately
328
        #[arg(long)]
329
        now: bool,
330
    },
331
    /// List operations
332
    #[command(name = "op")]
333
    Op {
334
        #[command(subcommand)]
335
        cmd: OpCmd,
336
    },
337
    /// Take the advisory local lock on a lockable file, making it writable
338
    Lock {
339
        /// The lockable file
340
        path: String,
341
    },
342
    /// Release the local lock and make the file read-only again
343
    Unlock {
344
        /// The locked file
345
        path: String,
346
    },
347
    /// Workspaces: extra checkout directories sharing this repository
348
    Workspace {
349
        #[command(subcommand)]
350
        cmd: WorkspaceCmd,
351
    },
352
    /// Bookmarks: named states; each workspace works on one
353
    Bookmark {
354
        #[command(subcommand)]
355
        cmd: BookmarkCmd,
356
    },
357
    /// Union another bookmark's heads into the current one (no merge change)
358
    Merge {
359
        /// The bookmark whose heads to add
360
        bookmark: String,
361
    },
362
    /// Sign in to a hub once, for every repository on it
363
    Auth {
364
        #[command(subcommand)]
365
        cmd: AuthCmd,
366
    },
367
    /// Subrepositories: nested repositories pinned to a state
368
    Submodule {
369
        #[command(subcommand)]
370
        cmd: SubmoduleCmd,
371
    },
372
    /// Execution receipts: signed records of what a runner ran on a state
373
    Receipt {
374
        #[command(subcommand)]
375
        cmd: ReceiptCmd,
376
    },
377
    /// Tags: immutable named states
378
    Tag {
379
        #[command(subcommand)]
380
        cmd: TagCmd,
381
    },
382
    /// Manage remotes
383
    Remote {
384
        #[command(subcommand)]
385
        cmd: RemoteCmd,
386
    },
387
    /// Fetch every bookmark of a remote into its tracking references
388
    Fetch {
389
        /// Remote name (default: origin)
390
        remote: Option<String>,
391
        /// Machine-readable output: one JSON document on stdout
392
        #[arg(long)]
393
        json: bool,
394
    },
395
    /// Fetch, then union the remote bookmark into the local one (no merge change)
396
    Pull {
397
        /// Remote name (default: origin)
398
        remote: Option<String>,
399
        /// Machine-readable output: one JSON document on stdout
400
        #[arg(long)]
401
        json: bool,
402
    },
403
    /// Push the current bookmark to a remote
404
    Push {
405
        /// Remote name (default: origin)
406
        remote: Option<String>,
407
        /// Allow dropping heads the remote has
408
        #[arg(long)]
409
        force: bool,
410
        /// Push this bookmark instead of the workspace's current one
411
        #[arg(short = 'b', long)]
412
        bookmark: Option<String>,
413
        /// Delete this bookmark on the remote (never its default bookmark);
414
        /// the local bookmark is kept
415
        #[arg(long, value_name = "NAME", conflicts_with_all = ["bookmark", "force"])]
416
        delete: Option<String>,
417
        /// Machine-readable output: one JSON document on stdout
418
        #[arg(long)]
419
        json: bool,
420
    },
421
    /// Serve repositories under ROOT over HTTPS (with --tls-cert/--tls-key) or plain HTTP
422
    Serve {
423
        /// Directory with one repository per subdirectory
424
        #[arg(long, default_value = ".")]
425
        root: PathBuf,
426
        /// Address and port to listen on
427
        #[arg(long, default_value = "127.0.0.1:8890")]
428
        bind: String,
429
        /// Bearer token allowed to push (repeatable); none means open
430
        #[arg(long = "token")]
431
        tokens: Vec<String>,
432
        /// PEM certificate chain; enables HTTPS together with --tls-key
433
        #[arg(long, requires = "tls_key")]
434
        tls_cert: Option<PathBuf>,
435
        /// PEM private key
436
        #[arg(long, requires = "tls_cert")]
437
        tls_key: Option<PathBuf>,
438
    },
439
    /// Manage the signing identity
440
    Identity {
441
        #[command(subcommand)]
442
        cmd: IdentityCmd,
443
    },
444
    /// Seal changes with your key: named ones, or every change on the current bookmark you can authenticate but have not
445
    Seal {
446
        /// Changes to seal (default: every change on the bookmark you can authenticate and have not sealed)
447
        changes: Vec<String>,
448
        /// Seal every change of a hub proposal and push the seal (your approval)
449
        #[arg(long, conflicts_with = "changes")]
450
        proposal: Option<String>,
451
        /// Machine-readable output: one JSON document on stdout
452
        #[arg(long)]
453
        json: bool,
454
    },
455
    /// Hub proposals: show one, or land it from this client
456
    Proposal {
457
        #[command(subcommand)]
458
        cmd: ProposalCmd,
459
    },
460
    /// Verify the signatures on a change (default: every change in the log)
461
    Verify {
462
        /// The change to verify (default: every change in the log)
463
        change: Option<String>,
464
        /// Verify every change a revset selects: `release..main & unsigned()`
465
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
466
        revset: Option<String>,
467
        /// Machine-readable output: one JSON document on stdout
468
        #[arg(long)]
469
        json: bool,
470
    },
471
    /// Git interoperability
472
    Git {
473
        #[command(subcommand)]
474
        cmd: GitCmd,
475
    },
476
    /// Manage the trust policy (who may update which bookmarks)
477
    Policy {
478
        #[command(subcommand)]
479
        cmd: PolicyCmd,
480
    },
481
    /// Set a configuration key (author.*, core.sign, core.op-retention, core.gc-grace, core.checkpoint-interval, filter.max-blob, filter.paths, workspace.bookmark, remote.<name>.url|token|ca, auth.helper with --user)
482
    Config {
483
        /// The key, such as author.name or remote.origin.token
484
        key: String,
485
        /// The value to set (none with --unset)
486
        #[arg(required_unless_present = "unset")]
487
        value: Option<String>,
488
        /// Write to the user file (~/.config/oxy/config.toml) instead of this repository
489
        #[arg(long)]
490
        user: bool,
491
        /// Remove the key from this repository's file (or the user file with --user)
492
        #[arg(long)]
493
        unset: bool,
494
    },
495
}
496
497
#[derive(Subcommand)]
498
enum OpCmd {
499
    /// List operations, newest first, with what each changed
500
    Log {
501
        /// Show only the latest N (snapshots folded together count as one)
502
        #[arg(short = 'n', long)]
503
        limit: Option<usize>,
504
        /// Machine-readable output: one JSON document on stdout
505
        #[arg(long)]
506
        json: bool,
507
    },
508
    /// Go back to the bookmarks and working copy as they were after OP (recorded as a new operation, so it can be undone)
509
    Restore {
510
        /// The operation: an ID prefix from oxy op log, @ or @-
511
        op: String,
512
        /// Throw away uncommitted working-copy changes
513
        #[arg(long)]
514
        discard: bool,
515
    },
516
    /// Undo OP alone, keeping every operation after it: the bookmarks it moved go back
517
    Revert {
518
        /// The operation: an ID prefix from oxy op log
519
        op: String,
520
    },
521
}
522
523
#[derive(Subcommand)]
524
enum WorkspaceCmd {
525
    /// Create a workspace at PATH checked out on CHANGE... (default: the bookmark heads)
526
    Add {
527
        /// Directory for the new workspace (must be empty or absent)
528
        path: PathBuf,
529
        /// Changes whose state to check out there
530
        changes: Vec<String>,
531
    },
532
    /// List workspaces and their working-copy changes
533
    List {
534
        /// Machine-readable output: one JSON document on stdout
535
        #[arg(long)]
536
        json: bool,
537
    },
538
    /// Stop tracking a workspace (by id prefix or path); its files stay
539
    Forget {
540
        /// Workspace id prefix or path
541
        workspace: String,
542
    },
543
}
544
545
#[derive(Subcommand)]
546
enum BisectCmd {
547
    /// Begin; remembers where the working copy was
548
    Start,
549
    /// Mark CHANGE... (or the state under test) as good
550
    Good {
551
        /// Changes known to be good (default: the state under test)
552
        changes: Vec<String>,
553
    },
554
    /// Mark CHANGE... (or the state under test) as bad
555
    Bad {
556
        /// Changes known to be bad (default: the state under test)
557
        changes: Vec<String>,
558
    },
559
    /// The state under test cannot be tested; try another
560
    Skip,
561
    /// Run a command for each step: exit 0 good, 125 skip, else bad
562
    Run {
563
        /// Command and arguments to run at each step
564
        #[arg(required = true, trailing_var_arg = true)]
565
        command: Vec<String>,
566
    },
567
    /// Where the search stands
568
    Status {
569
        /// Machine-readable output: one JSON document on stdout
570
        #[arg(long)]
571
        json: bool,
572
    },
573
    /// Restore the working copy and forget the search
574
    Reset,
575
}
576
577
#[derive(Subcommand)]
578
enum BookmarkCmd {
579
    /// Create a bookmark at CHANGE... (default: the working copy's base)
580
    Create {
581
        /// Name of the new bookmark
582
        name: String,
583
        /// Its heads (default: the working copy's base). A state is its
584
        /// heads and what they depend on: a change alone may leave out
585
        /// earlier changes of the current state, which is refused unless
586
        /// --upto or --only says which is meant
587
        changes: Vec<String>,
588
        /// Everything of the current state up to CHANGE..., as a Git
589
        /// branch at a commit would hold
590
        #[arg(long, conflicts_with = "only")]
591
        upto: bool,
592
        /// Just CHANGE... and what they depend on
593
        #[arg(long)]
594
        only: bool,
595
    },
596
    /// Point an existing bookmark at CHANGE...
597
    Set {
598
        /// The bookmark to move
599
        name: String,
600
        /// Its new heads. A change alone may leave out changes the
601
        /// bookmark now holds that were recorded before it, which is
602
        /// refused unless --upto or --only says which is meant
603
        changes: Vec<String>,
604
        /// Everything the bookmark holds up to CHANGE..., as a Git branch
605
        /// moved to a commit would hold
606
        #[arg(long, conflicts_with = "only")]
607
        upto: bool,
608
        /// Just CHANGE... and what they depend on
609
        #[arg(long)]
610
        only: bool,
611
    },
612
    /// Remove a bookmark; its changes stay
613
    Delete {
614
        /// The bookmark to remove
615
        name: String,
616
    },
617
    /// List bookmarks with their heads and difference from origin
618
    List {
619
        /// Also list remotes' bookmarks that have no local bookmark
620
        #[arg(long, short)]
621
        all: bool,
622
        /// Machine-readable output: one JSON document on stdout
623
        #[arg(long)]
624
        json: bool,
625
    },
626
    /// Make NAME this workspace's bookmark and check it out. Uncommitted work stops it; --carry takes the work along, --discard drops it
627
    Switch {
628
        /// The bookmark to work on; one only a remote has (NAME or REMOTE/NAME) is created from it
629
        name: String,
630
        /// Throw away uncommitted working-copy changes
631
        #[arg(long)]
632
        discard: bool,
633
        /// Take uncommitted changes along; refused when NAME has other
634
        /// versions of the files they touch
635
        #[arg(long, conflicts_with = "discard")]
636
        carry: bool,
637
    },
638
}
639
640
#[derive(Subcommand)]
641
enum AuthCmd {
642
    /// Sign in to HUB in the browser (device sign-in) and keep the token for
643
    /// every repository there
644
    Login {
645
        /// The hub, as https://oxygenhub.io or oxygenhub.io (default: this checkout's origin)
646
        hub: Option<String>,
647
        /// Read a token from standard input instead (for CI and scripts)
648
        #[arg(long)]
649
        with_token: bool,
650
        /// PEM file of extra roots to trust (a hub with a self-signed certificate)
651
        #[arg(long)]
652
        ca: Option<PathBuf>,
653
    },
654
    /// List the hubs you are signed in to, checking each token with its hub
655
    Status,
656
    /// Forget HUB's token and revoke it on the hub
657
    Logout {
658
        /// The hub (default: this checkout's origin, or the only one)
659
        hub: Option<String>,
660
    },
661
}
662
663
#[derive(Subcommand)]
664
enum SubmoduleCmd {
665
    /// Clone URL (Oxygen or Git) into PATH and register it in .oxymodules
666
    Add {
667
        /// URL or path of the Oxygen or Git repository
668
        url: String,
669
        /// Where to put it, relative to the repository root
670
        path: String,
671
        /// Bookmark (Oxygen) or branch (Git) to check out and track
672
        #[arg(long)]
673
        bookmark: Option<String>,
674
    },
675
    /// Bring nested repositories to their pins
676
    Update {
677
        /// Clone nested repositories that are absent
678
        #[arg(long)]
679
        init: bool,
680
        /// Subrepos to update (default: all)
681
        paths: Vec<String>,
682
    },
683
    /// List subrepos with their pins and on-disk state
684
    Status {
685
        /// Machine-readable output: one JSON document on stdout
686
        #[arg(long)]
687
        json: bool,
688
    },
689
    /// Unregister PATH; the directory stays, the node goes with the next commit
690
    Remove {
691
        /// The subrepo to unregister
692
        path: String,
693
    },
694
}
695
696
#[derive(Subcommand)]
697
enum ReceiptCmd {
698
    /// The receipts kept for a state (default: the bookmark heads)
699
    List {
700
        /// Change, bookmark or tag whose state to look at
701
        rev: Option<String>,
702
        /// Machine-readable output: one JSON document on stdout
703
        #[arg(long)]
704
        json: bool,
705
    },
706
    /// One receipt in full, and whether its signature verifies
707
    Show {
708
        /// The receipt (a prefix of its hash, as `list` shows it)
709
        receipt: String,
710
        /// Change, bookmark or tag whose state holds it
711
        #[arg(long)]
712
        rev: Option<String>,
713
        /// Machine-readable output: one JSON document on stdout
714
        #[arg(long)]
715
        json: bool,
716
    },
717
    /// Write a signed receipt to FILE
718
    Export {
719
        /// The receipt (a prefix of its hash, as `list` shows it)
720
        receipt: String,
721
        /// Where to write it
722
        file: String,
723
        /// Change, bookmark or tag whose state holds it
724
        #[arg(long)]
725
        rev: Option<String>,
726
    },
727
    /// Check a signed receipt in FILE without keeping it
728
    Verify {
729
        /// A signed receipt, as a runner or `export` writes it
730
        file: String,
731
        /// Machine-readable output: one JSON document on stdout
732
        #[arg(long)]
733
        json: bool,
734
    },
735
    /// Verify a signed receipt in FILE and keep it with its state
736
    Import {
737
        /// A signed receipt, as a runner or `export` writes it
738
        file: String,
739
    },
740
}
741
742
#[derive(Subcommand)]
743
enum TagCmd {
744
    /// Tag the state of CHANGE... (default: the bookmark heads)
745
    Create {
746
        /// Name of the tag; tags never move
747
        name: String,
748
        /// Changes whose state to tag (default: the bookmark heads)
749
        changes: Vec<String>,
750
        /// A message recorded with the tag
751
        #[arg(short, long, default_value = "")]
752
        message: String,
753
    },
754
    /// List tags and the states they name
755
    List {
756
        /// Machine-readable output: one JSON document on stdout
757
        #[arg(long)]
758
        json: bool,
759
    },
760
}
761
762
#[derive(Subcommand)]
763
enum RemoteCmd {
764
    /// Add a remote
765
    Add {
766
        /// Name to refer to the remote by, such as origin
767
        name: String,
768
        /// Local path or http(s) URL of the repository
769
        url: String,
770
    },
771
    /// Remove a remote
772
    Remove {
773
        /// The remote to remove
774
        name: String,
775
    },
776
    /// List remotes and their URLs
777
    List {
778
        /// Machine-readable output: one JSON document on stdout
779
        #[arg(long)]
780
        json: bool,
781
    },
782
}
783
784
#[derive(Subcommand)]
785
enum ProposalCmd {
786
    /// Show a proposal by its hub URL
787
    Show {
788
        /// The proposal's URL on the hub
789
        url: String,
790
        /// Machine-readable output: one JSON document on stdout
791
        #[arg(long)]
792
        json: bool,
793
    },
794
    /// Fetch the proposal's changes, set the target bookmark to the projected state, and push with your key
795
    Land {
796
        /// The proposal's URL on the hub
797
        url: String,
798
        /// Land even when the hub reports blockers
799
        #[arg(long)]
800
        force: bool,
801
    },
802
}
803
804
#[derive(Subcommand)]
805
enum IdentityCmd {
806
    /// Generate a composite Ed25519 + ML-DSA-65 key pair and make it your author identity
807
    Create {
808
        /// Your name (default: author.name)
809
        #[arg(long)]
810
        name: Option<String>,
811
        /// Your email (default: author.email)
812
        #[arg(long)]
813
        email: Option<String>,
814
        /// Record the author in this repository only, not in the user config
815
        #[arg(long)]
816
        local: bool,
817
        /// Expire the identity this many days from now
818
        #[arg(long)]
819
        expires: Option<u64>,
820
    },
821
    /// Show the configured identity
822
    Show,
823
    /// Write your identity object to a file, to hand to a policy holder
824
    Export {
825
        /// File to write (default: <key>.identity in the current directory)
826
        path: Option<PathBuf>,
827
    },
828
    /// Sign a host's challenge (hex, at least 16 bytes) to prove you hold your key; prints the signature as hex
829
    SignChallenge {
830
        /// The host's challenge, as hex
831
        challenge: String,
832
        /// Machine-readable output: one JSON document on stdout
833
        #[arg(long)]
834
        json: bool,
835
    },
836
    /// Move to a fresh key pair; the policy follows if it names your key
837
    Rotate,
838
    /// Re-issue your identity with a new expiry (in days from now; 0 = never)
839
    Renew {
840
        /// Days from now until it expires; 0 for never
841
        #[arg(long)]
842
        expires: u64,
843
    },
844
    /// Revoke a key: yours by default, or any key if you hold a policy root
845
    Revoke {
846
        /// KeyId prefix (default: your own key)
847
        key: Option<String>,
848
        /// Why, recorded in the revocation
849
        #[arg(long, default_value = "")]
850
        reason: String,
851
    },
852
    /// Keys allowed to sign or seal on your behalf
853
    Delegate {
854
        #[command(subcommand)]
855
        cmd: DelegateCmd,
856
    },
857
}
858
859
#[derive(Subcommand)]
860
enum DelegateCmd {
861
    /// Add a delegate from an exported identity file
862
    Add {
863
        /// The delegates' exported identity files: one rotation for all of them
864
        #[arg(required = true)]
865
        identity_file: Vec<PathBuf>,
866
        /// What it may do for you: changes, refs, seal (comma-separated) or all.
867
        /// An agent gets `changes`; a host that lands for you needs `changes,refs`
868
        #[arg(long, default_value = "changes")]
869
        scope: String,
870
        /// How long for: 30m, 8h, 7d, or a number of days (default: until removed)
871
        #[arg(long)]
872
        expires: Option<String>,
873
    },
874
    /// Remove a delegate by KeyId prefix
875
    Remove {
876
        /// KeyId prefix of the delegate
877
        key: String,
878
    },
879
    /// List delegates
880
    List,
881
}
882
883
#[derive(Subcommand)]
884
enum GitCmd {
885
    /// Export the current bookmark to a Git repository (created bare if absent)
886
    Export {
887
        /// Git repository to write to (created bare if absent)
888
        git_dir: PathBuf,
889
        /// Git branch to write (default: the bookmark name)
890
        #[arg(long)]
891
        branch: Option<String>,
892
    },
893
    /// Fetch a branch from a Git remote (path or URL) into the current bookmark
894
    Fetch {
895
        /// Git remote: a path or URL
896
        url: String,
897
        /// Branch to fetch
898
        #[arg(long, default_value = "main")]
899
        branch: String,
900
    },
901
    /// Push the current bookmark to a branch of a Git remote (fetch first)
902
    Push {
903
        /// Git remote: a path or URL
904
        url: String,
905
        /// Branch to push to
906
        #[arg(long, default_value = "main")]
907
        branch: String,
908
    },
909
    /// Check this repository's import of a Git branch: every commit's tree must be reproduced exactly
910
    Verify {
911
        /// The Git repository the import came from
912
        git_dir: PathBuf,
913
        /// Branch that was imported
914
        #[arg(long, default_value = "main")]
915
        branch: String,
916
    },
917
    /// Import a Git branch into a new Oxygen repository at DEST
918
    Import {
919
        /// Git repository to read
920
        git_dir: PathBuf,
921
        /// Directory for the new Oxygen repository
922
        dest: PathBuf,
923
        /// Branch to import
924
        #[arg(long, default_value = "main")]
925
        branch: String,
926
    },
927
}
928
929
#[derive(Subcommand)]
930
enum PolicyCmd {
931
    /// Create the initial policy with your identity as the only root
932
    Init,
933
    /// Show the current policy
934
    Show {
935
        /// Machine-readable output: one JSON document on stdout
936
        #[arg(long)]
937
        json: bool,
938
    },
939
    /// Allow an identity (from `oxy identity export`) to update bookmarks
940
    Grant {
941
        /// The identity to grant, exported with `oxy identity export`
942
        identity_file: PathBuf,
943
        /// Reference pattern the grant applies to (default: every bookmark)
944
        #[arg(long)]
945
        pattern: Option<String>,
946
        /// Where to write the proposal when more root signatures are needed
947
        #[arg(long)]
948
        out: Option<PathBuf>,
949
    },
950
    /// Revoke a key (KeyId prefix of an identity in the policy)
951
    Revoke {
952
        /// KeyId prefix of the identity
953
        key: String,
954
        /// Where to write the proposal when more root signatures are needed
955
        #[arg(long)]
956
        out: Option<PathBuf>,
957
    },
958
    /// Manage root keys and the signature threshold for policy updates
959
    Root {
960
        #[command(subcommand)]
961
        cmd: RootCmd,
962
    },
963
    /// Add your root signature to a proposal file; applies it once the threshold is met
964
    Sign {
965
        /// The proposal file to sign
966
        proposal: PathBuf,
967
        /// Where to write the proposal if it still needs signatures (default: in place)
968
        #[arg(long)]
969
        out: Option<PathBuf>,
970
    },
971
}
972
973
#[derive(Subcommand)]
974
enum RootCmd {
975
    /// Make an exported identity a root key
976
    Add {
977
        /// The identity to make a root, exported with `oxy identity export`
978
        identity_file: PathBuf,
979
        /// Where to write the proposal when more root signatures are needed
980
        #[arg(long)]
981
        out: Option<PathBuf>,
982
    },
983
    /// Remove a root key by KeyId prefix
984
    Remove {
985
        /// KeyId prefix of the root key
986
        key: String,
987
        /// Where to write the proposal when more root signatures are needed
988
        #[arg(long)]
989
        out: Option<PathBuf>,
990
    },
991
    /// Require this many root signatures on policy updates
992
    Threshold {
993
        /// Number of root signatures
994
        n: u32,
995
        /// Where to write the proposal when more root signatures are needed
996
        #[arg(long)]
997
        out: Option<PathBuf>,
998
    },
999
}
1000
1001
/// Open the repository containing the current directory.
1002
fn open() -> Result<Repo> {
1003
    let repo = Repo::open(&std::env::current_dir()?).context("opening repository")?;
1004
    match AT_OP.get().and_then(|o| o.as_deref()) {
1005
        Some(op) => Ok(repo.at_op(op)?),
1006
        None => Ok(repo),
1007
    }
1008
}
1009
1010
/// `oxy man`: every page into `dir`, or the top-level page on stdout.
1011
fn man(dir: Option<PathBuf>) -> Result<i32> {
1012
    use clap::CommandFactory;
1013
    let cmd = Cli::command();
1014
    match dir {
1015
        Some(dir) => {
1016
            std::fs::create_dir_all(&dir)?;
1017
            clap_mangen::generate_to(cmd, &dir)?;
1018
            let pages = std::fs::read_dir(&dir)?
1019
                .filter(|e| {
1020
                    e.as_ref()
1021
                        .is_ok_and(|e| e.path().extension().is_some_and(|x| x == "1"))
1022
                })
1023
                .count();
1024
            println!(
1025
                "{}",
1026
                ui::done(format!("Wrote {pages} man pages to {}", dir.display()))
1027
            );
1028
        }
1029
        None => clap_mangen::Man::new(cmd).render(&mut std::io::stdout())?,
1030
    }
1031
    Ok(0)
1032
}
1033
1034
/// Parse arguments and run; returns the process exit code.
1035
pub fn run() -> Result<i32> {
1036
    // The cloud stores (s3://, gs://, az://) for remotes kept on them.
1037
    oxy_strata::register();
1038
    let cli = Cli::parse();
1039
    ui::init(cli.plain);
1040
    AT_OP.set(cli.at_op.clone()).ok();
1041
    match cli.cmd {
1042
        Cmd::Completions { shell } => {
1043
            use clap::CommandFactory;
1044
            clap_complete::generate(shell, &mut Cli::command(), "oxy", &mut std::io::stdout());
1045
            Ok(0)
1046
        }
1047
        Cmd::Man { dir } => man(dir),
1048
        Cmd::Init { path, bare, store } => workspace::init(path, bare, store.as_deref()),
1049
        Cmd::Status { json } => workspace::status(json),
1050
        Cmd::Prompt {
1051
            format,
1052
            glyphs,
1053
            color,
1054
        } => workspace::prompt(&format, glyphs, color.as_deref()),
1055
        Cmd::Commit {
1056
            message,
1057
            file,
1058
            depends_on,
1059
            paths,
1060
            interactive,
1061
            hunks,
1062
        } => {
1063
            let message = match (message, file) {
1064
                (Some(m), _) => m,
1065
                (None, Some(f)) if f.as_os_str() == "-" => {
1066
                    let mut s = String::new();
1067
                    std::io::Read::read_to_string(&mut std::io::stdin(), &mut s)?;
1068
                    s
1069
                }
1070
                (None, Some(f)) => std::fs::read_to_string(&f).map_err(|e| {
1071
                    anyhow::anyhow!("reading the message from {}: {e}", f.display())
1072
                })?,
1073
                (None, None) => anyhow::bail!("a commit message is required (-m or -F)"),
1074
            };
1075
            workspace::commit(&message, &depends_on, &paths, interactive, &hunks)
1076
        }
1077
        Cmd::Cat { path, change } => workspace::cat(&path, change.as_deref()),
1078
        Cmd::Root { json } => workspace::root(json),
1079
        Cmd::Version { json } => workspace::version(json),
1080
        Cmd::Discard { paths, hunks } => workspace::discard(&paths, &hunks),
1081
        Cmd::Hunks { json } => workspace::hunks(json),
1082
        Cmd::Squash { change, into } => workspace::squash(&change, &into),
1083
        Cmd::Rebase {
1084
            change,
1085
            onto,
1086
            into_working_copy,
1087
        } => workspace::rebase(&change, &onto, into_working_copy),
1088
        Cmd::Blame { path, json } => workspace::blame(&path, json),
1089
        Cmd::Bisect { cmd } => match cmd {
1090
            BisectCmd::Start => workspace::bisect_start(),
1091
            BisectCmd::Good { changes } => workspace::bisect_mark(Some(true), &changes),
1092
            BisectCmd::Bad { changes } => workspace::bisect_mark(Some(false), &changes),
1093
            BisectCmd::Skip => workspace::bisect_mark(None, &[]),
1094
            BisectCmd::Run { command } => workspace::bisect_run(&command),
1095
            BisectCmd::Status { json } => workspace::bisect_status(json),
1096
            BisectCmd::Reset => workspace::bisect_reset(),
1097
        },
1098
        Cmd::Log {
1099
            revset,
1100
            limit,
1101
            verbose,
1102
            path,
1103
            lines,
1104
            json,
1105
        } => workspace::log(
1106
            revset.as_deref(),
1107
            limit,
1108
            verbose,
1109
            path.as_deref(),
1110
            lines.as_deref(),
1111
            json,
1112
        ),
1113
        Cmd::Diff { change, json } => workspace::diff(change.as_deref(), json),
1114
        Cmd::Describe {
1115
            message,
1116
            change,
1117
            json,
1118
        } => match message {
1119
            Some(m) => workspace::describe(&m, change.as_deref()),
1120
            None if change.is_some() => {
1121
                anyhow::bail!(
1122
                    "naming works on the working copy; to change a head's message pass -m"
1123
                )
1124
            }
1125
            None => workspace::describe_name(json),
1126
        },
1127
        Cmd::Amend { message, into } => workspace::amend(message.as_deref(), into.as_deref()),
1128
        Cmd::Split { change, paths } => workspace::split(&change, &paths),
1129
        Cmd::Abandon {
1130
            change,
1131
            revset,
1132
            yes,
1133
        } => workspace::abandon(change.as_deref(), revset.as_deref(), yes),
1134
        Cmd::Show {
1135
            change,
1136
            revset,
1137
            json,
1138
        } => workspace::show(change.as_deref(), revset.as_deref(), json),
1139
        Cmd::Checkout {
1140
            changes,
1141
            discard,
1142
            carry,
1143
        } => workspace::checkout(&changes, discard, carry),
1144
        Cmd::Resolve { json } => workspace::resolve(json),
1145
        Cmd::Undo => workspace::undo(),
1146
        Cmd::Gc { now } => workspace::gc(now),
1147
        Cmd::Fsck { json } => workspace::fsck(json),
1148
        Cmd::Doctor { offline, json } => workspace::doctor(offline, json),
1149
        Cmd::Checkpoint => workspace::checkpoint(),
1150
        Cmd::Op { cmd } => match cmd {
1151
            OpCmd::Log { limit, json } => workspace::op_log(limit, json),
1152
            OpCmd::Restore { op, discard } => workspace::op_restore(&op, discard),
1153
            OpCmd::Revert { op } => workspace::op_revert(&op),
1154
        },
1155
        Cmd::Clone {
1156
            url,
1157
            dest,
1158
            max_blob,
1159
            sparse,
1160
            depth,
1161
            recursive,
1162
        } => sync::clone(&url, dest, max_blob.as_deref(), &sparse, depth, recursive),
1163
        Cmd::Deepen { depth, remote } => sync::deepen(&remote, depth),
1164
        Cmd::Sparse { paths } => workspace::sparse(&paths),
1165
        Cmd::Lock { path } => workspace::lock(&path),
1166
        Cmd::Unlock { path } => workspace::unlock(&path),
1167
        Cmd::Workspace { cmd } => match cmd {
1168
            WorkspaceCmd::Add { path, changes } => workspace::workspace_add(&path, &changes),
1169
            WorkspaceCmd::List { json } => workspace::workspace_list(json),
1170
            WorkspaceCmd::Forget { workspace } => workspace::workspace_forget(&workspace),
1171
        },
1172
        Cmd::Bookmark { cmd } => match cmd {
1173
            BookmarkCmd::Create {
1174
                name,
1175
                changes,
1176
                upto,
1177
                only,
1178
            } => workspace::bookmark_create(&name, &changes, upto, only),
1179
            BookmarkCmd::Set {
1180
                name,
1181
                changes,
1182
                upto,
1183
                only,
1184
            } => workspace::bookmark_set(&name, &changes, upto, only),
1185
            BookmarkCmd::Delete { name } => workspace::bookmark_delete(&name),
1186
            BookmarkCmd::List { all, json } => workspace::bookmark_list(all, json),
1187
            BookmarkCmd::Switch {
1188
                name,
1189
                discard,
1190
                carry,
1191
            } => workspace::bookmark_switch(&name, discard, carry),
1192
        },
1193
        Cmd::Merge { bookmark } => workspace::merge(&bookmark),
1194
        Cmd::Auth { cmd } => match cmd {
1195
            AuthCmd::Login {
1196
                hub,
1197
                with_token,
1198
                ca,
1199
            } => auth::login(hub.as_deref(), with_token, ca),
1200
            AuthCmd::Status => auth::status(),
1201
            AuthCmd::Logout { hub } => auth::logout(hub.as_deref()),
1202
        },
1203
        Cmd::Submodule { cmd } => match cmd {
1204
            SubmoduleCmd::Add {
1205
                url,
1206
                path,
1207
                bookmark,
1208
            } => sync::submodule_add(&url, &path, bookmark.as_deref()),
1209
            SubmoduleCmd::Update { init, paths } => sync::submodule_update(init, &paths),
1210
            SubmoduleCmd::Status { json } => sync::submodule_status(json),
1211
            SubmoduleCmd::Remove { path } => sync::submodule_remove(&path),
1212
        },
1213
        Cmd::Receipt { cmd } => match cmd {
1214
            ReceiptCmd::List { rev, json } => receipt::list(rev.as_deref(), json),
1215
            ReceiptCmd::Show {
1216
                receipt: r,
1217
                rev,
1218
                json,
1219
            } => receipt::show(&r, rev.as_deref(), json),
1220
            ReceiptCmd::Export {
1221
                receipt: r,
1222
                file,
1223
                rev,
1224
            } => receipt::export(&r, &file, rev.as_deref()),
1225
            ReceiptCmd::Verify { file, json } => receipt::verify(&file, json),
1226
            ReceiptCmd::Import { file } => receipt::import(&file),
1227
        },
1228
        Cmd::Tag { cmd } => match cmd {
1229
            TagCmd::Create {
1230
                name,
1231
                changes,
1232
                message,
1233
            } => workspace::tag_create(&name, &changes, &message),
1234
            TagCmd::List { json } => workspace::tag_list(json),
1235
        },
1236
        Cmd::Remote { cmd } => match cmd {
1237
            RemoteCmd::Add { name, url } => sync::remote_add(&name, &url),
1238
            RemoteCmd::Remove { name } => sync::remote_remove(&name),
1239
            RemoteCmd::List { json } => sync::remote_list(json),
1240
        },
1241
        Cmd::Fetch { remote, json } => sync::fetch(remote.as_deref(), json),
1242
        Cmd::Pull { remote, json } => sync::pull(remote.as_deref(), json),
1243
        Cmd::Push {
1244
            remote,
1245
            force,
1246
            bookmark,
1247
            delete,
1248
            json,
1249
        } => match delete {
1250
            Some(name) => sync::push_delete(remote.as_deref(), &name, json),
1251
            None => sync::push(remote.as_deref(), force, bookmark.as_deref(), json),
1252
        },
1253
        Cmd::Serve {
1254
            root,
1255
            bind,
1256
            tokens,
1257
            tls_cert,
1258
            tls_key,
1259
        } => sync::serve(root, &bind, tokens, tls_cert.zip(tls_key)),
1260
        Cmd::Identity { cmd } => match cmd {
1261
            IdentityCmd::Create {
1262
                name,
1263
                email,
1264
                local,
1265
                expires,
1266
            } => identity::create(name, email, local, expires),
1267
            IdentityCmd::Show => identity::show(),
1268
            IdentityCmd::Export { path } => identity::export(path),
1269
            IdentityCmd::SignChallenge { challenge, json } => {
1270
                identity::sign_challenge(&challenge, json)
1271
            }
1272
            IdentityCmd::Rotate => identity::rotate(),
1273
            IdentityCmd::Renew { expires } => identity::renew(expires),
1274
            IdentityCmd::Revoke { key, reason } => identity::revoke(key.as_deref(), &reason),
1275
            IdentityCmd::Delegate { cmd } => match cmd {
1276
                DelegateCmd::Add {
1277
                    identity_file,
1278
                    scope,
1279
                    expires,
1280
                } => identity::delegate_add(&identity_file, &scope, expires.as_deref()),
1281
                DelegateCmd::Remove { key } => identity::delegate_remove(&key),
1282
                DelegateCmd::List => identity::delegate_list(),
1283
            },
1284
        },
1285
        Cmd::Git {
1286
            cmd: GitCmd::Export { git_dir, branch },
1287
        } => sync::git_export(&git_dir, branch.as_deref()),
1288
        Cmd::Git {
1289
            cmd: GitCmd::Fetch { url, branch },
1290
        } => sync::git_fetch(&url, &branch),
1291
        Cmd::Git {
1292
            cmd: GitCmd::Push { url, branch },
1293
        } => sync::git_push(&url, &branch),
1294
        Cmd::Git {
1295
            cmd:
1296
                GitCmd::Import {
1297
                    git_dir,
1298
                    dest,
1299
                    branch,
1300
                },
1301
        } => sync::git_import(&git_dir, &dest, &branch),
1302
        Cmd::Git {
1303
            cmd: GitCmd::Verify { git_dir, branch },
1304
        } => sync::git_verify(&git_dir, &branch),
1305
        Cmd::Policy { cmd } => match cmd {
1306
            PolicyCmd::Init => identity::policy_init(),
1307
            PolicyCmd::Show { json } => identity::policy_show(json),
1308
            PolicyCmd::Grant {
1309
                identity_file,
1310
                pattern,
1311
                out,
1312
            } => identity::policy_grant(&identity_file, pattern.as_deref(), out),
1313
            PolicyCmd::Revoke { key, out } => identity::policy_revoke(&key, out),
1314
            PolicyCmd::Root { cmd } => match cmd {
1315
                RootCmd::Add { identity_file, out } => {
1316
                    identity::policy_root_add(&identity_file, out)
1317
                }
1318
                RootCmd::Remove { key, out } => identity::policy_root_remove(&key, out),
1319
                RootCmd::Threshold { n, out } => identity::policy_threshold(n, out),
1320
            },
1321
            PolicyCmd::Sign { proposal, out } => identity::policy_sign(&proposal, out),
1322
        },
1323
        Cmd::Seal {
1324
            changes,
1325
            proposal: Some(url),
1326
            json,
1327
        } if changes.is_empty() => proposal::seal(&url, json),
1328
        Cmd::Seal { changes, json, .. } => identity::seal(&changes, json),
1329
        Cmd::Proposal { cmd } => match cmd {
1330
            ProposalCmd::Show { url, json } => proposal::show(&url, json),
1331
            ProposalCmd::Land { url, force } => proposal::land(&url, force),
1332
        },
1333
        Cmd::Verify {
1334
            change,
1335
            revset,
1336
            json,
1337
        } => identity::verify(change.as_deref(), revset.as_deref(), json),
1338
        Cmd::Config {
1339
            key,
1340
            value,
1341
            user,
1342
            unset,
1343
        } => identity::config(&key, value.as_deref().unwrap_or(""), user, unset),
1344
    }
1345
}
1346
1347
#[cfg(test)]
1348
mod help_tests {
1349
    use super::Cli;
1350
    use clap::CommandFactory;
1351
1352
    /// Every command and every argument explains itself, so `--help`,
1353
    /// completions and the man pages are complete.
1354
    #[test]
1355
    fn every_command_and_argument_has_help() {
1356
        fn walk(cmd: &clap::Command, path: &str, missing: &mut Vec<String>) {
1357
            let here = format!("{path} {}", cmd.get_name()).trim().to_string();
1358
            if cmd.get_about().is_none() && path != "" {
1359
                missing.push(format!("{here} (command)"));
1360
            }
1361
            for a in cmd.get_arguments() {
1362
                let id = a.get_id().as_str();
1363
                if id == "help" || id == "version" || a.is_global_set() && path != "" {
1364
                    continue;
1365
                }
1366
                if a.get_help().is_none() && a.get_long_help().is_none() {
1367
                    missing.push(format!("{here} {id}"));
1368
                }
1369
            }
1370
            for sub in cmd.get_subcommands() {
1371
                walk(sub, &here, missing);
1372
            }
1373
        }
1374
        let mut missing = Vec::new();
1375
        walk(&Cli::command(), "", &mut missing);
1376
        assert!(
1377
            missing.is_empty(),
1378
            "{} without help:\n{}",
1379
            missing.len(),
1380
            missing.join("\n")
1381
        );
1382
    }
1383
}