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