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