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