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