OXYGENHUB
# 68a924846379 oxygen / src / cli / mod.rs
46.5 KiB · Rust · last changed Scoped, expiring delegates, and revocation by the delegator 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
        /// What it may do for you: changes, refs, seal (comma-separated) or all.
839
        /// An agent gets `changes`; a host that lands for you needs `changes,refs`
840
        #[arg(long, default_value = "changes")]
841
        scope: String,
842
        /// How long for: 30m, 8h, 7d, or a number of days (default: until removed)
843
        #[arg(long)]
844
        expires: Option<String>,
845
    },
846
    /// Remove a delegate by KeyId prefix
847
    Remove {
848
        /// KeyId prefix of the delegate
849
        key: String,
850
    },
851
    /// List delegates
852
    List,
853
}
854
855
#[derive(Subcommand)]
856
enum GitCmd {
857
    /// Export the current bookmark to a Git repository (created bare if absent)
858
    Export {
859
        /// Git repository to write to (created bare if absent)
860
        git_dir: PathBuf,
861
        /// Git branch to write (default: the bookmark name)
862
        #[arg(long)]
863
        branch: Option<String>,
864
    },
865
    /// Fetch a branch from a Git remote (path or URL) into the current bookmark
866
    Fetch {
867
        /// Git remote: a path or URL
868
        url: String,
869
        /// Branch to fetch
870
        #[arg(long, default_value = "main")]
871
        branch: String,
872
    },
873
    /// Push the current bookmark to a branch of a Git remote (fetch first)
874
    Push {
875
        /// Git remote: a path or URL
876
        url: String,
877
        /// Branch to push to
878
        #[arg(long, default_value = "main")]
879
        branch: String,
880
    },
881
    /// Check this repository's import of a Git branch: every commit's tree must be reproduced exactly
882
    Verify {
883
        /// The Git repository the import came from
884
        git_dir: PathBuf,
885
        /// Branch that was imported
886
        #[arg(long, default_value = "main")]
887
        branch: String,
888
    },
889
    /// Import a Git branch into a new Oxygen repository at DEST
890
    Import {
891
        /// Git repository to read
892
        git_dir: PathBuf,
893
        /// Directory for the new Oxygen repository
894
        dest: PathBuf,
895
        /// Branch to import
896
        #[arg(long, default_value = "main")]
897
        branch: String,
898
    },
899
}
900
901
#[derive(Subcommand)]
902
enum PolicyCmd {
903
    /// Create the initial policy with your identity as the only root
904
    Init,
905
    /// Show the current policy
906
    Show {
907
        /// Machine-readable output: one JSON document on stdout
908
        #[arg(long)]
909
        json: bool,
910
    },
911
    /// Allow an identity (from `oxy identity export`) to update bookmarks
912
    Grant {
913
        /// The identity to grant, exported with `oxy identity export`
914
        identity_file: PathBuf,
915
        /// Reference pattern the grant applies to (default: every bookmark)
916
        #[arg(long)]
917
        pattern: Option<String>,
918
        /// Where to write the proposal when more root signatures are needed
919
        #[arg(long)]
920
        out: Option<PathBuf>,
921
    },
922
    /// Revoke a key (KeyId prefix of an identity in the policy)
923
    Revoke {
924
        /// KeyId prefix of the identity
925
        key: String,
926
        /// Where to write the proposal when more root signatures are needed
927
        #[arg(long)]
928
        out: Option<PathBuf>,
929
    },
930
    /// Manage root keys and the signature threshold for policy updates
931
    Root {
932
        #[command(subcommand)]
933
        cmd: RootCmd,
934
    },
935
    /// Add your root signature to a proposal file; applies it once the threshold is met
936
    Sign {
937
        /// The proposal file to sign
938
        proposal: PathBuf,
939
        /// Where to write the proposal if it still needs signatures (default: in place)
940
        #[arg(long)]
941
        out: Option<PathBuf>,
942
    },
943
}
944
945
#[derive(Subcommand)]
946
enum RootCmd {
947
    /// Make an exported identity a root key
948
    Add {
949
        /// The identity to make a root, exported with `oxy identity export`
950
        identity_file: PathBuf,
951
        /// Where to write the proposal when more root signatures are needed
952
        #[arg(long)]
953
        out: Option<PathBuf>,
954
    },
955
    /// Remove a root key by KeyId prefix
956
    Remove {
957
        /// KeyId prefix of the root key
958
        key: String,
959
        /// Where to write the proposal when more root signatures are needed
960
        #[arg(long)]
961
        out: Option<PathBuf>,
962
    },
963
    /// Require this many root signatures on policy updates
964
    Threshold {
965
        /// Number of root signatures
966
        n: u32,
967
        /// Where to write the proposal when more root signatures are needed
968
        #[arg(long)]
969
        out: Option<PathBuf>,
970
    },
971
}
972
973
/// Open the repository containing the current directory.
974
fn open() -> Result<Repo> {
975
    let repo = Repo::open(&std::env::current_dir()?).context("opening repository")?;
976
    match AT_OP.get().and_then(|o| o.as_deref()) {
977
        Some(op) => Ok(repo.at_op(op)?),
978
        None => Ok(repo),
979
    }
980
}
981
982
/// `oxy man`: every page into `dir`, or the top-level page on stdout.
983
fn man(dir: Option<PathBuf>) -> Result<i32> {
984
    use clap::CommandFactory;
985
    let cmd = Cli::command();
986
    match dir {
987
        Some(dir) => {
988
            std::fs::create_dir_all(&dir)?;
989
            clap_mangen::generate_to(cmd, &dir)?;
990
            let pages = std::fs::read_dir(&dir)?
991
                .filter(|e| {
992
                    e.as_ref()
993
                        .is_ok_and(|e| e.path().extension().is_some_and(|x| x == "1"))
994
                })
995
                .count();
996
            println!(
997
                "{}",
998
                ui::done(format!("Wrote {pages} man pages to {}", dir.display()))
999
            );
1000
        }
1001
        None => clap_mangen::Man::new(cmd).render(&mut std::io::stdout())?,
1002
    }
1003
    Ok(0)
1004
}
1005
1006
/// Parse arguments and run; returns the process exit code.
1007
pub fn run() -> Result<i32> {
1008
    let cli = Cli::parse();
1009
    ui::init(cli.plain);
1010
    AT_OP.set(cli.at_op.clone()).ok();
1011
    match cli.cmd {
1012
        Cmd::Completions { shell } => {
1013
            use clap::CommandFactory;
1014
            clap_complete::generate(shell, &mut Cli::command(), "oxy", &mut std::io::stdout());
1015
            Ok(0)
1016
        }
1017
        Cmd::Man { dir } => man(dir),
1018
        Cmd::Init { path, bare } => workspace::init(path, bare),
1019
        Cmd::Status { json } => workspace::status(json),
1020
        Cmd::Prompt {
1021
            format,
1022
            glyphs,
1023
            color,
1024
        } => workspace::prompt(&format, glyphs, color.as_deref()),
1025
        Cmd::Commit {
1026
            message,
1027
            file,
1028
            depends_on,
1029
            paths,
1030
            interactive,
1031
            hunks,
1032
        } => {
1033
            let message = match (message, file) {
1034
                (Some(m), _) => m,
1035
                (None, Some(f)) if f.as_os_str() == "-" => {
1036
                    let mut s = String::new();
1037
                    std::io::Read::read_to_string(&mut std::io::stdin(), &mut s)?;
1038
                    s
1039
                }
1040
                (None, Some(f)) => std::fs::read_to_string(&f).map_err(|e| {
1041
                    anyhow::anyhow!("reading the message from {}: {e}", f.display())
1042
                })?,
1043
                (None, None) => anyhow::bail!("a commit message is required (-m or -F)"),
1044
            };
1045
            workspace::commit(&message, &depends_on, &paths, interactive, &hunks)
1046
        }
1047
        Cmd::Cat { path, change } => workspace::cat(&path, change.as_deref()),
1048
        Cmd::Root { json } => workspace::root(json),
1049
        Cmd::Version { json } => workspace::version(json),
1050
        Cmd::Discard { paths, hunks } => workspace::discard(&paths, &hunks),
1051
        Cmd::Hunks { json } => workspace::hunks(json),
1052
        Cmd::Squash { change, into } => workspace::squash(&change, &into),
1053
        Cmd::Rebase {
1054
            change,
1055
            onto,
1056
            into_working_copy,
1057
        } => workspace::rebase(&change, &onto, into_working_copy),
1058
        Cmd::Blame { path, json } => workspace::blame(&path, json),
1059
        Cmd::Bisect { cmd } => match cmd {
1060
            BisectCmd::Start => workspace::bisect_start(),
1061
            BisectCmd::Good { changes } => workspace::bisect_mark(Some(true), &changes),
1062
            BisectCmd::Bad { changes } => workspace::bisect_mark(Some(false), &changes),
1063
            BisectCmd::Skip => workspace::bisect_mark(None, &[]),
1064
            BisectCmd::Run { command } => workspace::bisect_run(&command),
1065
            BisectCmd::Status { json } => workspace::bisect_status(json),
1066
            BisectCmd::Reset => workspace::bisect_reset(),
1067
        },
1068
        Cmd::Log {
1069
            limit,
1070
            verbose,
1071
            path,
1072
            lines,
1073
            json,
1074
        } => workspace::log(limit, verbose, path.as_deref(), lines.as_deref(), json),
1075
        Cmd::Diff { change, json } => workspace::diff(change.as_deref(), json),
1076
        Cmd::Describe {
1077
            message,
1078
            change,
1079
            json,
1080
        } => match message {
1081
            Some(m) => workspace::describe(&m, change.as_deref()),
1082
            None if change.is_some() => {
1083
                anyhow::bail!(
1084
                    "naming works on the working copy; to change a head's message pass -m"
1085
                )
1086
            }
1087
            None => workspace::describe_name(json),
1088
        },
1089
        Cmd::Amend { message, into } => workspace::amend(message.as_deref(), into.as_deref()),
1090
        Cmd::Split { change, paths } => workspace::split(&change, &paths),
1091
        Cmd::Abandon { change } => workspace::abandon(&change),
1092
        Cmd::Show { change, json } => workspace::show(&change, json),
1093
        Cmd::Checkout {
1094
            changes,
1095
            discard,
1096
            carry,
1097
        } => workspace::checkout(&changes, discard, carry),
1098
        Cmd::Resolve { json } => workspace::resolve(json),
1099
        Cmd::Undo => workspace::undo(),
1100
        Cmd::Gc { now } => workspace::gc(now),
1101
        Cmd::Fsck { json } => workspace::fsck(json),
1102
        Cmd::Doctor { offline, json } => workspace::doctor(offline, json),
1103
        Cmd::Checkpoint => workspace::checkpoint(),
1104
        Cmd::Op { cmd } => match cmd {
1105
            OpCmd::Log { limit, json } => workspace::op_log(limit, json),
1106
            OpCmd::Restore { op, discard } => workspace::op_restore(&op, discard),
1107
            OpCmd::Revert { op } => workspace::op_revert(&op),
1108
        },
1109
        Cmd::Clone {
1110
            url,
1111
            dest,
1112
            max_blob,
1113
            sparse,
1114
            depth,
1115
            recursive,
1116
        } => sync::clone(&url, dest, max_blob.as_deref(), &sparse, depth, recursive),
1117
        Cmd::Deepen { depth, remote } => sync::deepen(&remote, depth),
1118
        Cmd::Sparse { paths } => workspace::sparse(&paths),
1119
        Cmd::Lock { path } => workspace::lock(&path),
1120
        Cmd::Unlock { path } => workspace::unlock(&path),
1121
        Cmd::Workspace { cmd } => match cmd {
1122
            WorkspaceCmd::Add { path, changes } => workspace::workspace_add(&path, &changes),
1123
            WorkspaceCmd::List { json } => workspace::workspace_list(json),
1124
            WorkspaceCmd::Forget { workspace } => workspace::workspace_forget(&workspace),
1125
        },
1126
        Cmd::Bookmark { cmd } => match cmd {
1127
            BookmarkCmd::Create {
1128
                name,
1129
                changes,
1130
                upto,
1131
                only,
1132
            } => workspace::bookmark_create(&name, &changes, upto, only),
1133
            BookmarkCmd::Set {
1134
                name,
1135
                changes,
1136
                upto,
1137
                only,
1138
            } => workspace::bookmark_set(&name, &changes, upto, only),
1139
            BookmarkCmd::Delete { name } => workspace::bookmark_delete(&name),
1140
            BookmarkCmd::List { all, json } => workspace::bookmark_list(all, json),
1141
            BookmarkCmd::Switch {
1142
                name,
1143
                discard,
1144
                carry,
1145
            } => workspace::bookmark_switch(&name, discard, carry),
1146
        },
1147
        Cmd::Merge { bookmark } => workspace::merge(&bookmark),
1148
        Cmd::Auth { cmd } => match cmd {
1149
            AuthCmd::Login {
1150
                hub,
1151
                with_token,
1152
                ca,
1153
            } => auth::login(hub.as_deref(), with_token, ca),
1154
            AuthCmd::Status => auth::status(),
1155
            AuthCmd::Logout { hub } => auth::logout(hub.as_deref()),
1156
        },
1157
        Cmd::Submodule { cmd } => match cmd {
1158
            SubmoduleCmd::Add {
1159
                url,
1160
                path,
1161
                bookmark,
1162
            } => sync::submodule_add(&url, &path, bookmark.as_deref()),
1163
            SubmoduleCmd::Update { init, paths } => sync::submodule_update(init, &paths),
1164
            SubmoduleCmd::Status { json } => sync::submodule_status(json),
1165
            SubmoduleCmd::Remove { path } => sync::submodule_remove(&path),
1166
        },
1167
        Cmd::Receipt { cmd } => match cmd {
1168
            ReceiptCmd::List { rev, json } => receipt::list(rev.as_deref(), json),
1169
            ReceiptCmd::Show {
1170
                receipt: r,
1171
                rev,
1172
                json,
1173
            } => receipt::show(&r, rev.as_deref(), json),
1174
            ReceiptCmd::Export {
1175
                receipt: r,
1176
                file,
1177
                rev,
1178
            } => receipt::export(&r, &file, rev.as_deref()),
1179
            ReceiptCmd::Verify { file, json } => receipt::verify(&file, json),
1180
            ReceiptCmd::Import { file } => receipt::import(&file),
1181
        },
1182
        Cmd::Tag { cmd } => match cmd {
1183
            TagCmd::Create {
1184
                name,
1185
                changes,
1186
                message,
1187
            } => workspace::tag_create(&name, &changes, &message),
1188
            TagCmd::List { json } => workspace::tag_list(json),
1189
        },
1190
        Cmd::Remote { cmd } => match cmd {
1191
            RemoteCmd::Add { name, url } => sync::remote_add(&name, &url),
1192
            RemoteCmd::Remove { name } => sync::remote_remove(&name),
1193
            RemoteCmd::List { json } => sync::remote_list(json),
1194
        },
1195
        Cmd::Fetch { remote, json } => sync::fetch(remote.as_deref(), json),
1196
        Cmd::Pull { remote, json } => sync::pull(remote.as_deref(), json),
1197
        Cmd::Push {
1198
            remote,
1199
            force,
1200
            bookmark,
1201
            delete,
1202
            json,
1203
        } => match delete {
1204
            Some(name) => sync::push_delete(remote.as_deref(), &name, json),
1205
            None => sync::push(remote.as_deref(), force, bookmark.as_deref(), json),
1206
        },
1207
        Cmd::Serve {
1208
            root,
1209
            bind,
1210
            tokens,
1211
            tls_cert,
1212
            tls_key,
1213
        } => sync::serve(root, &bind, tokens, tls_cert.zip(tls_key)),
1214
        Cmd::Identity { cmd } => match cmd {
1215
            IdentityCmd::Create {
1216
                name,
1217
                email,
1218
                local,
1219
                expires,
1220
            } => identity::create(name, email, local, expires),
1221
            IdentityCmd::Show => identity::show(),
1222
            IdentityCmd::Export { path } => identity::export(path),
1223
            IdentityCmd::SignChallenge { challenge, json } => {
1224
                identity::sign_challenge(&challenge, json)
1225
            }
1226
            IdentityCmd::Rotate => identity::rotate(),
1227
            IdentityCmd::Renew { expires } => identity::renew(expires),
1228
            IdentityCmd::Revoke { key, reason } => identity::revoke(key.as_deref(), &reason),
1229
            IdentityCmd::Delegate { cmd } => match cmd {
1230
                DelegateCmd::Add {
1231
                    identity_file,
1232
                    scope,
1233
                    expires,
1234
                } => identity::delegate_add(&identity_file, &scope, expires.as_deref()),
1235
                DelegateCmd::Remove { key } => identity::delegate_remove(&key),
1236
                DelegateCmd::List => identity::delegate_list(),
1237
            },
1238
        },
1239
        Cmd::Git {
1240
            cmd: GitCmd::Export { git_dir, branch },
1241
        } => sync::git_export(&git_dir, branch.as_deref()),
1242
        Cmd::Git {
1243
            cmd: GitCmd::Fetch { url, branch },
1244
        } => sync::git_fetch(&url, &branch),
1245
        Cmd::Git {
1246
            cmd: GitCmd::Push { url, branch },
1247
        } => sync::git_push(&url, &branch),
1248
        Cmd::Git {
1249
            cmd:
1250
                GitCmd::Import {
1251
                    git_dir,
1252
                    dest,
1253
                    branch,
1254
                },
1255
        } => sync::git_import(&git_dir, &dest, &branch),
1256
        Cmd::Git {
1257
            cmd: GitCmd::Verify { git_dir, branch },
1258
        } => sync::git_verify(&git_dir, &branch),
1259
        Cmd::Policy { cmd } => match cmd {
1260
            PolicyCmd::Init => identity::policy_init(),
1261
            PolicyCmd::Show { json } => identity::policy_show(json),
1262
            PolicyCmd::Grant {
1263
                identity_file,
1264
                pattern,
1265
                out,
1266
            } => identity::policy_grant(&identity_file, pattern.as_deref(), out),
1267
            PolicyCmd::Revoke { key, out } => identity::policy_revoke(&key, out),
1268
            PolicyCmd::Root { cmd } => match cmd {
1269
                RootCmd::Add { identity_file, out } => {
1270
                    identity::policy_root_add(&identity_file, out)
1271
                }
1272
                RootCmd::Remove { key, out } => identity::policy_root_remove(&key, out),
1273
                RootCmd::Threshold { n, out } => identity::policy_threshold(n, out),
1274
            },
1275
            PolicyCmd::Sign { proposal, out } => identity::policy_sign(&proposal, out),
1276
        },
1277
        Cmd::Seal {
1278
            changes,
1279
            proposal: Some(url),
1280
            json,
1281
        } if changes.is_empty() => proposal::seal(&url, json),
1282
        Cmd::Seal { changes, json, .. } => identity::seal(&changes, json),
1283
        Cmd::Proposal { cmd } => match cmd {
1284
            ProposalCmd::Show { url, json } => proposal::show(&url, json),
1285
            ProposalCmd::Land { url, force } => proposal::land(&url, force),
1286
        },
1287
        Cmd::Verify { change, json } => identity::verify(change.as_deref(), json),
1288
        Cmd::Config { key, value, user } => identity::config(&key, &value, user),
1289
    }
1290
}
1291
1292
#[cfg(test)]
1293
mod help_tests {
1294
    use super::Cli;
1295
    use clap::CommandFactory;
1296
1297
    /// Every command and every argument explains itself, so `--help`,
1298
    /// completions and the man pages are complete.
1299
    #[test]
1300
    fn every_command_and_argument_has_help() {
1301
        fn walk(cmd: &clap::Command, path: &str, missing: &mut Vec<String>) {
1302
            let here = format!("{path} {}", cmd.get_name()).trim().to_string();
1303
            if cmd.get_about().is_none() && path != "" {
1304
                missing.push(format!("{here} (command)"));
1305
            }
1306
            for a in cmd.get_arguments() {
1307
                let id = a.get_id().as_str();
1308
                if id == "help" || id == "version" || a.is_global_set() && path != "" {
1309
                    continue;
1310
                }
1311
                if a.get_help().is_none() && a.get_long_help().is_none() {
1312
                    missing.push(format!("{here} {id}"));
1313
                }
1314
            }
1315
            for sub in cmd.get_subcommands() {
1316
                walk(sub, &here, missing);
1317
            }
1318
        }
1319
        let mut missing = Vec::new();
1320
        walk(&Cli::command(), "", &mut missing);
1321
        assert!(
1322
            missing.is_empty(),
1323
            "{} without help:\n{}",
1324
            missing.len(),
1325
            missing.join("\n")
1326
        );
1327
    }
1328
}