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