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