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