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