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