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