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