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