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