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