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