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