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