OXYGENHUB
# 87322662f607 oxygen / src / cli / mod.rs
47.8 KiB · Rust · last changed Commit a resolution by paths, and amend only some paths 18 days 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",
21
    version,
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
69953b50 Andy McCall ↶ 238
        #[arg(long, conflicts_with = "paths")]
23b217d7 Andy McCall ↶ 239
        into: Option<String>,
69953b50 Andy McCall ↶ 240
        /// Fold in only these paths; the rest stays as uncommitted work
241
        paths: Vec<String>,
614541c3 Andy McCall ↶ 242
    },
23b217d7 Andy McCall ↶ 243
    /// Split a head: the named paths become a separate first change
d42369ab Andy McCall 244
    Split {
245
        /// The head to split
246
        change: String,
247
        /// Paths whose edits become the first change
248
        paths: Vec<String>,
249
    },
2c9ddac3 Andy McCall ↶ 250
    /// Drop a change from the bookmark; its content stays on disk as uncommitted work
d42369ab Andy McCall 251
    Abandon {
2c9ddac3 Andy McCall ↶ 252
        /// The change to drop (ChangeId prefix, #hash prefix)
253
        #[arg(required_unless_present = "revset")]
254
        change: Option<String>,
255
        /// Drop every change a revset selects, newest first
256
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
257
        revset: Option<String>,
258
        /// Drop more than five changes without asking
259
        #[arg(long, short = 'y')]
260
        yes: bool,
d42369ab Andy McCall 261
    },
2c9ddac3 Andy McCall ↶ 262
    /// Show one change (ChangeId prefix, #hash prefix, or @), or those a revset selects
c6aa5bd9 Andy McCall ↶ 263
    Show {
d42369ab Andy McCall 264
        /// ChangeId prefix, #hash prefix, or @ for the working copy
2c9ddac3 Andy McCall ↶ 265
        #[arg(required_unless_present = "revset")]
266
        change: Option<String>,
267
        /// Show every change a revset selects
268
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
269
        revset: Option<String>,
0299076f Andy McCall ↶ 270
        /// The files it touched with lines added and removed, instead of the diff
271
        #[arg(long)]
272
        stat: bool,
d42369ab Andy McCall 273
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 274
        #[arg(long)]
275
        json: bool,
276
    },
fce44ae9 Andy McCall ↶ 277
    /// Move the working copy to the state formed by CHANGE... (default: the bookmark heads)
278
    Checkout {
d42369ab Andy McCall 279
        /// Changes whose state to check out (default: the bookmark heads)
fce44ae9 Andy McCall ↶ 280
        changes: Vec<String>,
281
        /// Throw away uncommitted working-copy changes
282
        #[arg(long)]
283
        discard: bool,
1c2bd9ab Andy McCall ↶ 284
        /// Take uncommitted changes along; refused when the target has
285
        /// other versions of the files they touch
286
        #[arg(long, conflicts_with = "discard")]
287
        carry: bool,
fce44ae9 Andy McCall ↶ 288
    },
289
    /// Report which conflicts of the working copy's base are resolved by the current files
c6aa5bd9 Andy McCall ↶ 290
    Resolve {
d42369ab Andy McCall 291
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 292
        #[arg(long)]
293
        json: bool,
294
    },
fce44ae9 Andy McCall ↶ 295
    /// Undo the last operation
296
    Undo,
252e8cb2 Andy McCall ↶ 297
    /// Write a checkpoint of the current bookmark's state now
298
    Checkpoint,
d42369ab Andy McCall 299
    /// Print a shell completion script: `oxy completions bash > ~/.local/share/bash-completion/completions/oxy`
300
    Completions {
301
        /// bash, zsh, fish, elvish or powershell
302
        shell: clap_complete::Shell,
303
    },
304
    /// Write man pages (oxy.1 and one per command) into DIR, or print oxy.1
305
    Man {
306
        /// Directory to write every page into, e.g. ~/.local/share/man/man1
307
        #[arg(long)]
308
        dir: Option<PathBuf>,
309
    },
3e5772cc Andy McCall ↶ 310
    /// Check the identity, configuration and remotes, and say what to do about any problem
311
    Doctor {
312
        /// Do not contact the remotes
313
        #[arg(long)]
314
        offline: bool,
d42369ab Andy McCall 315
        /// Machine-readable output: one JSON document on stdout
3e5772cc Andy McCall ↶ 316
        #[arg(long)]
317
        json: bool,
318
    },
387335ff Andy McCall ↶ 319
    /// Check the repository's integrity: objects, operation log, references, signatures, checkpoints
320
    Fsck {
d42369ab Andy McCall 321
        /// Machine-readable output: one JSON document on stdout
387335ff Andy McCall ↶ 322
        #[arg(long)]
323
        json: bool,
324
    },
da652d63 Andy McCall ↶ 325
    /// Prune unreachable objects older than the grace period and repack everything into one pack
ba160f60 Andy McCall ↶ 326
    Gc {
327
        /// Ignore the grace period (core.gc-grace) and prune immediately
328
        #[arg(long)]
329
        now: bool,
330
    },
fce44ae9 Andy McCall ↶ 331
    /// List operations
332
    #[command(name = "op")]
333
    Op {
334
        #[command(subcommand)]
335
        cmd: OpCmd,
336
    },
cdb5beba Andy McCall ↶ 337
    /// Take the advisory local lock on a lockable file, making it writable
d42369ab Andy McCall 338
    Lock {
339
        /// The lockable file
340
        path: String,
341
    },
cdb5beba Andy McCall ↶ 342
    /// Release the local lock and make the file read-only again
d42369ab Andy McCall 343
    Unlock {
344
        /// The locked file
345
        path: String,
346
    },
4e88e774 Andy McCall ↶ 347
    /// Workspaces: extra checkout directories sharing this repository
348
    Workspace {
349
        #[command(subcommand)]
350
        cmd: WorkspaceCmd,
351
    },
7b9809e6 Andy McCall ↶ 352
    /// Bookmarks: named states; each workspace works on one
353
    Bookmark {
354
        #[command(subcommand)]
355
        cmd: BookmarkCmd,
356
    },
357
    /// Union another bookmark's heads into the current one (no merge change)
d42369ab Andy McCall 358
    Merge {
359
        /// The bookmark whose heads to add
360
        bookmark: String,
361
    },
ff1f62fe Andy McCall ↶ 362
    /// Sign in to a hub once, for every repository on it
363
    Auth {
364
        #[command(subcommand)]
365
        cmd: AuthCmd,
366
    },
4dee277c Andy McCall ↶ 367
    /// Subrepositories: nested repositories pinned to a state
368
    Submodule {
369
        #[command(subcommand)]
370
        cmd: SubmoduleCmd,
371
    },
fc1a466a Andy McCall ↶ 372
    /// Execution receipts: signed records of what a runner ran on a state
373
    Receipt {
374
        #[command(subcommand)]
375
        cmd: ReceiptCmd,
376
    },
132b884b Andy McCall ↶ 377
    /// Tags: immutable named states
378
    Tag {
379
        #[command(subcommand)]
380
        cmd: TagCmd,
381
    },
fce44ae9 Andy McCall ↶ 382
    /// Manage remotes
383
    Remote {
384
        #[command(subcommand)]
385
        cmd: RemoteCmd,
386
    },
387
    /// Fetch every bookmark of a remote into its tracking references
c6aa5bd9 Andy McCall ↶ 388
    Fetch {
d42369ab Andy McCall 389
        /// Remote name (default: origin)
c6aa5bd9 Andy McCall ↶ 390
        remote: Option<String>,
d42369ab Andy McCall 391
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 392
        #[arg(long)]
393
        json: bool,
394
    },
fce44ae9 Andy McCall ↶ 395
    /// Fetch, then union the remote bookmark into the local one (no merge change)
c6aa5bd9 Andy McCall ↶ 396
    Pull {
d42369ab Andy McCall 397
        /// Remote name (default: origin)
c6aa5bd9 Andy McCall ↶ 398
        remote: Option<String>,
d42369ab Andy McCall 399
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 400
        #[arg(long)]
401
        json: bool,
402
    },
fce44ae9 Andy McCall ↶ 403
    /// Push the current bookmark to a remote
404
    Push {
d42369ab Andy McCall 405
        /// Remote name (default: origin)
fce44ae9 Andy McCall ↶ 406
        remote: Option<String>,
407
        /// Allow dropping heads the remote has
408
        #[arg(long)]
409
        force: bool,
7b9809e6 Andy McCall ↶ 410
        /// Push this bookmark instead of the workspace's current one
411
        #[arg(short = 'b', long)]
412
        bookmark: Option<String>,
f8c69576 Andy McCall ↶ 413
        /// Delete this bookmark on the remote (never its default bookmark);
414
        /// the local bookmark is kept
415
        #[arg(long, value_name = "NAME", conflicts_with_all = ["bookmark", "force"])]
416
        delete: Option<String>,
d42369ab Andy McCall 417
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 418
        #[arg(long)]
419
        json: bool,
fce44ae9 Andy McCall ↶ 420
    },
2b5ee371 Andy McCall ↶ 421
    /// Serve repositories under ROOT over HTTPS (with --tls-cert/--tls-key) or plain HTTP
fce44ae9 Andy McCall ↶ 422
    Serve {
423
        /// Directory with one repository per subdirectory
424
        #[arg(long, default_value = ".")]
425
        root: PathBuf,
d42369ab Andy McCall 426
        /// Address and port to listen on
fce44ae9 Andy McCall ↶ 427
        #[arg(long, default_value = "127.0.0.1:8890")]
428
        bind: String,
429
        /// Bearer token allowed to push (repeatable); none means open
430
        #[arg(long = "token")]
431
        tokens: Vec<String>,
2b5ee371 Andy McCall ↶ 432
        /// PEM certificate chain; enables HTTPS together with --tls-key
433
        #[arg(long, requires = "tls_key")]
434
        tls_cert: Option<PathBuf>,
435
        /// PEM private key
436
        #[arg(long, requires = "tls_cert")]
437
        tls_key: Option<PathBuf>,
fce44ae9 Andy McCall ↶ 438
    },
439
    /// Manage the signing identity
440
    Identity {
441
        #[command(subcommand)]
442
        cmd: IdentityCmd,
443
    },
05e71ed6 Andy McCall ↶ 444
    /// Seal changes with your key: named ones, or every change on the current bookmark you can authenticate but have not
445
    Seal {
d42369ab Andy McCall 446
        /// Changes to seal (default: every change on the bookmark you can authenticate and have not sealed)
05e71ed6 Andy McCall ↶ 447
        changes: Vec<String>,
d82e4409 Andy McCall ↶ 448
        /// Seal every change of a hub proposal and push the seal (your approval)
449
        #[arg(long, conflicts_with = "changes")]
450
        proposal: Option<String>,
d42369ab Andy McCall 451
        /// Machine-readable output: one JSON document on stdout
05e71ed6 Andy McCall ↶ 452
        #[arg(long)]
453
        json: bool,
454
    },
d82e4409 Andy McCall ↶ 455
    /// Hub proposals: show one, or land it from this client
456
    Proposal {
457
        #[command(subcommand)]
458
        cmd: ProposalCmd,
459
    },
fce44ae9 Andy McCall ↶ 460
    /// Verify the signatures on a change (default: every change in the log)
c6aa5bd9 Andy McCall ↶ 461
    Verify {
d42369ab Andy McCall 462
        /// The change to verify (default: every change in the log)
c6aa5bd9 Andy McCall ↶ 463
        change: Option<String>,
2c9ddac3 Andy McCall ↶ 464
        /// Verify every change a revset selects: `release..main & unsigned()`
465
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
466
        revset: Option<String>,
d42369ab Andy McCall 467
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 468
        #[arg(long)]
469
        json: bool,
470
    },
79ab8528 Andy McCall ↶ 471
    /// Git interoperability
472
    Git {
473
        #[command(subcommand)]
474
        cmd: GitCmd,
475
    },
83e0677b Andy McCall ↶ 476
    /// Manage the trust policy (who may update which bookmarks)
477
    Policy {
478
        #[command(subcommand)]
479
        cmd: PolicyCmd,
480
    },
ff1f62fe Andy McCall ↶ 481
    /// 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 ↶ 482
    Config {
d42369ab Andy McCall 483
        /// The key, such as author.name or remote.origin.token
fce44ae9 Andy McCall ↶ 484
        key: String,
d42369ab Andy McCall 485
        /// The value to set
fce44ae9 Andy McCall ↶ 486
        value: String,
487
        /// Write to the user file (~/.config/oxy/config.toml) instead of this repository
488
        #[arg(long)]
489
        user: bool,
490
    },
491
}
492
493
#[derive(Subcommand)]
494
enum OpCmd {
98a1620a Andy McCall ↶ 495
    /// List operations, newest first, with what each changed
c6aa5bd9 Andy McCall ↶ 496
    Log {
98a1620a Andy McCall ↶ 497
        /// Show only the latest N (snapshots folded together count as one)
498
        #[arg(short = 'n', long)]
499
        limit: Option<usize>,
d42369ab Andy McCall 500
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 501
        #[arg(long)]
502
        json: bool,
98a1620a Andy McCall ↶ 503
    },
504
    /// Go back to the bookmarks and working copy as they were after OP (recorded as a new operation, so it can be undone)
505
    Restore {
506
        /// The operation: an ID prefix from oxy op log, @ or @-
507
        op: String,
508
        /// Throw away uncommitted working-copy changes
509
        #[arg(long)]
510
        discard: bool,
511
    },
512
    /// Undo OP alone, keeping every operation after it: the bookmarks it moved go back
513
    Revert {
514
        /// The operation: an ID prefix from oxy op log
515
        op: String,
c6aa5bd9 Andy McCall ↶ 516
    },
fce44ae9 Andy McCall ↶ 517
}
518
519
#[derive(Subcommand)]
4e88e774 Andy McCall ↶ 520
enum WorkspaceCmd {
521
    /// Create a workspace at PATH checked out on CHANGE... (default: the bookmark heads)
d42369ab Andy McCall 522
    Add {
523
        /// Directory for the new workspace (must be empty or absent)
524
        path: PathBuf,
525
        /// Changes whose state to check out there
526
        changes: Vec<String>,
527
    },
528
    /// List workspaces and their working-copy changes
1196b29b Andy McCall ↶ 529
    List {
d42369ab Andy McCall 530
        /// Machine-readable output: one JSON document on stdout
1196b29b Andy McCall ↶ 531
        #[arg(long)]
532
        json: bool,
533
    },
4e88e774 Andy McCall ↶ 534
    /// Stop tracking a workspace (by id prefix or path); its files stay
d42369ab Andy McCall 535
    Forget {
536
        /// Workspace id prefix or path
537
        workspace: String,
538
    },
4e88e774 Andy McCall ↶ 539
}
540
541
#[derive(Subcommand)]
957fee30 Andy McCall ↶ 542
enum BisectCmd {
543
    /// Begin; remembers where the working copy was
544
    Start,
545
    /// Mark CHANGE... (or the state under test) as good
d42369ab Andy McCall 546
    Good {
547
        /// Changes known to be good (default: the state under test)
548
        changes: Vec<String>,
549
    },
957fee30 Andy McCall ↶ 550
    /// Mark CHANGE... (or the state under test) as bad
d42369ab Andy McCall 551
    Bad {
552
        /// Changes known to be bad (default: the state under test)
553
        changes: Vec<String>,
554
    },
957fee30 Andy McCall ↶ 555
    /// The state under test cannot be tested; try another
556
    Skip,
557
    /// Run a command for each step: exit 0 good, 125 skip, else bad
558
    Run {
d42369ab Andy McCall 559
        /// Command and arguments to run at each step
957fee30 Andy McCall ↶ 560
        #[arg(required = true, trailing_var_arg = true)]
561
        command: Vec<String>,
562
    },
563
    /// Where the search stands
c6aa5bd9 Andy McCall ↶ 564
    Status {
d42369ab Andy McCall 565
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 566
        #[arg(long)]
567
        json: bool,
568
    },
957fee30 Andy McCall ↶ 569
    /// Restore the working copy and forget the search
570
    Reset,
571
}
572
573
#[derive(Subcommand)]
7b9809e6 Andy McCall ↶ 574
enum BookmarkCmd {
575
    /// Create a bookmark at CHANGE... (default: the working copy's base)
d42369ab Andy McCall 576
    Create {
577
        /// Name of the new bookmark
578
        name: String,
4fe7d604 Andy McCall ↶ 579
        /// Its heads (default: the working copy's base). A state is its
580
        /// heads and what they depend on: a change alone may leave out
581
        /// earlier changes of the current state, which is refused unless
582
        /// --upto or --only says which is meant
d42369ab Andy McCall 583
        changes: Vec<String>,
4fe7d604 Andy McCall ↶ 584
        /// Everything of the current state up to CHANGE..., as a Git
585
        /// branch at a commit would hold
586
        #[arg(long, conflicts_with = "only")]
587
        upto: bool,
588
        /// Just CHANGE... and what they depend on
589
        #[arg(long)]
590
        only: bool,
d42369ab Andy McCall 591
    },
7b9809e6 Andy McCall ↶ 592
    /// Point an existing bookmark at CHANGE...
d42369ab Andy McCall 593
    Set {
594
        /// The bookmark to move
595
        name: String,
06d16dc2 Andy McCall ↶ 596
        /// Its new heads. A change alone may leave out changes the
597
        /// bookmark now holds that were recorded before it, which is
598
        /// refused unless --upto or --only says which is meant
d42369ab Andy McCall 599
        changes: Vec<String>,
06d16dc2 Andy McCall ↶ 600
        /// Everything the bookmark holds up to CHANGE..., as a Git branch
601
        /// moved to a commit would hold
602
        #[arg(long, conflicts_with = "only")]
603
        upto: bool,
604
        /// Just CHANGE... and what they depend on
605
        #[arg(long)]
606
        only: bool,
d42369ab Andy McCall 607
    },
7b9809e6 Andy McCall ↶ 608
    /// Remove a bookmark; its changes stay
d42369ab Andy McCall 609
    Delete {
610
        /// The bookmark to remove
611
        name: String,
612
    },
7b9809e6 Andy McCall ↶ 613
    /// List bookmarks with their heads and difference from origin
c6aa5bd9 Andy McCall ↶ 614
    List {
14edbaaf Andy McCall ↶ 615
        /// Also list remotes' bookmarks that have no local bookmark
616
        #[arg(long, short)]
617
        all: bool,
d42369ab Andy McCall 618
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 619
        #[arg(long)]
620
        json: bool,
621
    },
61e3bce7 Andy McCall ↶ 622
    /// 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 ↶ 623
    Switch {
14edbaaf Andy McCall ↶ 624
        /// The bookmark to work on; one only a remote has (NAME or REMOTE/NAME) is created from it
7b9809e6 Andy McCall ↶ 625
        name: String,
626
        /// Throw away uncommitted working-copy changes
627
        #[arg(long)]
628
        discard: bool,
61e3bce7 Andy McCall ↶ 629
        /// Take uncommitted changes along; refused when NAME has other
630
        /// versions of the files they touch
631
        #[arg(long, conflicts_with = "discard")]
632
        carry: bool,
ff1f62fe Andy McCall ↶ 633
    },
634
}
635
636
#[derive(Subcommand)]
637
enum AuthCmd {
638
    /// Sign in to HUB in the browser (device sign-in) and keep the token for
639
    /// every repository there
640
    Login {
641
        /// The hub, as https://oxygenhub.io or oxygenhub.io (default: this checkout's origin)
642
        hub: Option<String>,
643
        /// Read a token from standard input instead (for CI and scripts)
644
        #[arg(long)]
645
        with_token: bool,
646
        /// PEM file of extra roots to trust (a hub with a self-signed certificate)
647
        #[arg(long)]
648
        ca: Option<PathBuf>,
7b9809e6 Andy McCall ↶ 649
    },
ff1f62fe Andy McCall ↶ 650
    /// List the hubs you are signed in to, checking each token with its hub
651
    Status,
652
    /// Forget HUB's token and revoke it on the hub
653
    Logout {
654
        /// The hub (default: this checkout's origin, or the only one)
655
        hub: Option<String>,
656
    },
7b9809e6 Andy McCall ↶ 657
}
658
659
#[derive(Subcommand)]
4dee277c Andy McCall ↶ 660
enum SubmoduleCmd {
661
    /// Clone URL (Oxygen or Git) into PATH and register it in .oxymodules
662
    Add {
d42369ab Andy McCall 663
        /// URL or path of the Oxygen or Git repository
4dee277c Andy McCall ↶ 664
        url: String,
d42369ab Andy McCall 665
        /// Where to put it, relative to the repository root
4dee277c Andy McCall ↶ 666
        path: String,
667
        /// Bookmark (Oxygen) or branch (Git) to check out and track
668
        #[arg(long)]
669
        bookmark: Option<String>,
670
    },
671
    /// Bring nested repositories to their pins
672
    Update {
673
        /// Clone nested repositories that are absent
674
        #[arg(long)]
675
        init: bool,
d42369ab Andy McCall 676
        /// Subrepos to update (default: all)
4dee277c Andy McCall ↶ 677
        paths: Vec<String>,
678
    },
679
    /// List subrepos with their pins and on-disk state
c6aa5bd9 Andy McCall ↶ 680
    Status {
d42369ab Andy McCall 681
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 682
        #[arg(long)]
683
        json: bool,
684
    },
4dee277c Andy McCall ↶ 685
    /// Unregister PATH; the directory stays, the node goes with the next commit
d42369ab Andy McCall 686
    Remove {
687
        /// The subrepo to unregister
688
        path: String,
689
    },
4dee277c Andy McCall ↶ 690
}
691
692
#[derive(Subcommand)]
fc1a466a Andy McCall ↶ 693
enum ReceiptCmd {
694
    /// The receipts kept for a state (default: the bookmark heads)
695
    List {
696
        /// Change, bookmark or tag whose state to look at
697
        rev: Option<String>,
698
        /// Machine-readable output: one JSON document on stdout
699
        #[arg(long)]
700
        json: bool,
701
    },
702
    /// One receipt in full, and whether its signature verifies
703
    Show {
704
        /// The receipt (a prefix of its hash, as `list` shows it)
705
        receipt: String,
706
        /// Change, bookmark or tag whose state holds it
707
        #[arg(long)]
708
        rev: Option<String>,
709
        /// Machine-readable output: one JSON document on stdout
710
        #[arg(long)]
711
        json: bool,
712
    },
713
    /// Write a signed receipt to FILE
714
    Export {
715
        /// The receipt (a prefix of its hash, as `list` shows it)
716
        receipt: String,
717
        /// Where to write it
718
        file: String,
719
        /// Change, bookmark or tag whose state holds it
720
        #[arg(long)]
721
        rev: Option<String>,
722
    },
723
    /// Check a signed receipt in FILE without keeping it
724
    Verify {
725
        /// A signed receipt, as a runner or `export` writes it
726
        file: String,
727
        /// Machine-readable output: one JSON document on stdout
728
        #[arg(long)]
729
        json: bool,
730
    },
731
    /// Verify a signed receipt in FILE and keep it with its state
732
    Import {
733
        /// A signed receipt, as a runner or `export` writes it
734
        file: String,
735
    },
736
}
737
738
#[derive(Subcommand)]
132b884b Andy McCall ↶ 739
enum TagCmd {
740
    /// Tag the state of CHANGE... (default: the bookmark heads)
741
    Create {
d42369ab Andy McCall 742
        /// Name of the tag; tags never move
132b884b Andy McCall ↶ 743
        name: String,
d42369ab Andy McCall 744
        /// Changes whose state to tag (default: the bookmark heads)
132b884b Andy McCall ↶ 745
        changes: Vec<String>,
d42369ab Andy McCall 746
        /// A message recorded with the tag
132b884b Andy McCall ↶ 747
        #[arg(short, long, default_value = "")]
748
        message: String,
749
    },
d42369ab Andy McCall 750
    /// List tags and the states they name
1196b29b Andy McCall ↶ 751
    List {
d42369ab Andy McCall 752
        /// Machine-readable output: one JSON document on stdout
1196b29b Andy McCall ↶ 753
        #[arg(long)]
754
        json: bool,
755
    },
132b884b Andy McCall ↶ 756
}
757
758
#[derive(Subcommand)]
fce44ae9 Andy McCall ↶ 759
enum RemoteCmd {
d42369ab Andy McCall 760
    /// Add a remote
75167672 Andy McCall 761
    Add {
d42369ab Andy McCall 762
        /// Name to refer to the remote by, such as origin
75167672 Andy McCall 763
        name: String,
d42369ab Andy McCall 764
        /// Local path or http(s) URL of the repository
75167672 Andy McCall 765
        url: String,
766
    },
d42369ab Andy McCall 767
    /// Remove a remote
75167672 Andy McCall 768
    Remove {
d42369ab Andy McCall 769
        /// The remote to remove
75167672 Andy McCall 770
        name: String,
771
    },
d42369ab Andy McCall 772
    /// List remotes and their URLs
c6aa5bd9 Andy McCall ↶ 773
    List {
d42369ab Andy McCall 774
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 775
        #[arg(long)]
776
        json: bool,
777
    },
fce44ae9 Andy McCall ↶ 778
}
779
780
#[derive(Subcommand)]
d82e4409 Andy McCall ↶ 781
enum ProposalCmd {
782
    /// Show a proposal by its hub URL
783
    Show {
d42369ab Andy McCall 784
        /// The proposal's URL on the hub
d82e4409 Andy McCall ↶ 785
        url: String,
d42369ab Andy McCall 786
        /// Machine-readable output: one JSON document on stdout
d82e4409 Andy McCall ↶ 787
        #[arg(long)]
788
        json: bool,
789
    },
790
    /// Fetch the proposal's changes, set the target bookmark to the projected state, and push with your key
791
    Land {
d42369ab Andy McCall 792
        /// The proposal's URL on the hub
d82e4409 Andy McCall ↶ 793
        url: String,
794
        /// Land even when the hub reports blockers
795
        #[arg(long)]
796
        force: bool,
797
    },
798
}
799
800
#[derive(Subcommand)]
fce44ae9 Andy McCall ↶ 801
enum IdentityCmd {
802
    /// Generate a composite Ed25519 + ML-DSA-65 key pair and make it your author identity
803
    Create {
d42369ab Andy McCall 804
        /// Your name (default: author.name)
fce44ae9 Andy McCall ↶ 805
        #[arg(long)]
806
        name: Option<String>,
d42369ab Andy McCall 807
        /// Your email (default: author.email)
fce44ae9 Andy McCall ↶ 808
        #[arg(long)]
809
        email: Option<String>,
810
        /// Record the author in this repository only, not in the user config
811
        #[arg(long)]
812
        local: bool,
28fc23d7 Andy McCall ↶ 813
        /// Expire the identity this many days from now
814
        #[arg(long)]
815
        expires: Option<u64>,
fce44ae9 Andy McCall ↶ 816
    },
817
    /// Show the configured identity
818
    Show,
83e0677b Andy McCall ↶ 819
    /// Write your identity object to a file, to hand to a policy holder
d42369ab Andy McCall 820
    Export {
e3d071ce Andy McCall ↶ 821
        /// File to write (default: <key>.identity in the current directory)
d42369ab Andy McCall 822
        path: Option<PathBuf>,
823
    },
7aa2dc93 Andy McCall ↶ 824
    /// Sign a host's challenge (hex, at least 16 bytes) to prove you hold your key; prints the signature as hex
825
    SignChallenge {
d42369ab Andy McCall 826
        /// The host's challenge, as hex
7aa2dc93 Andy McCall ↶ 827
        challenge: String,
d42369ab Andy McCall 828
        /// Machine-readable output: one JSON document on stdout
7aa2dc93 Andy McCall ↶ 829
        #[arg(long)]
830
        json: bool,
831
    },
28fc23d7 Andy McCall ↶ 832
    /// Move to a fresh key pair; the policy follows if it names your key
833
    Rotate,
834
    /// Re-issue your identity with a new expiry (in days from now; 0 = never)
835
    Renew {
d42369ab Andy McCall 836
        /// Days from now until it expires; 0 for never
28fc23d7 Andy McCall ↶ 837
        #[arg(long)]
838
        expires: u64,
839
    },
840
    /// Revoke a key: yours by default, or any key if you hold a policy root
841
    Revoke {
842
        /// KeyId prefix (default: your own key)
843
        key: Option<String>,
d42369ab Andy McCall 844
        /// Why, recorded in the revocation
28fc23d7 Andy McCall ↶ 845
        #[arg(long, default_value = "")]
846
        reason: String,
847
    },
848
    /// Keys allowed to sign or seal on your behalf
849
    Delegate {
850
        #[command(subcommand)]
851
        cmd: DelegateCmd,
852
    },
853
}
854
855
#[derive(Subcommand)]
856
enum DelegateCmd {
857
    /// Add a delegate from an exported identity file
d42369ab Andy McCall 858
    Add {
859
        /// The delegate's exported identity file
860
        identity_file: PathBuf,
861
    },
28fc23d7 Andy McCall ↶ 862
    /// Remove a delegate by KeyId prefix
d42369ab Andy McCall 863
    Remove {
864
        /// KeyId prefix of the delegate
865
        key: String,
866
    },
28fc23d7 Andy McCall ↶ 867
    /// List delegates
868
    List,
fce44ae9 Andy McCall ↶ 869
}
870
83e0677b Andy McCall ↶ 871
#[derive(Subcommand)]
79ab8528 Andy McCall ↶ 872
enum GitCmd {
873
    /// Export the current bookmark to a Git repository (created bare if absent)
30ea9c1e Andy McCall ↶ 874
    Export {
d42369ab Andy McCall 875
        /// Git repository to write to (created bare if absent)
30ea9c1e Andy McCall ↶ 876
        git_dir: PathBuf,
877
        /// Git branch to write (default: the bookmark name)
878
        #[arg(long)]
879
        branch: Option<String>,
880
    },
881
    /// Fetch a branch from a Git remote (path or URL) into the current bookmark
882
    Fetch {
d42369ab Andy McCall 883
        /// Git remote: a path or URL
30ea9c1e Andy McCall ↶ 884
        url: String,
d42369ab Andy McCall 885
        /// Branch to fetch
30ea9c1e Andy McCall ↶ 886
        #[arg(long, default_value = "main")]
887
        branch: String,
888
    },
889
    /// Push the current bookmark to a branch of a Git remote (fetch first)
890
    Push {
d42369ab Andy McCall 891
        /// Git remote: a path or URL
30ea9c1e Andy McCall ↶ 892
        url: String,
d42369ab Andy McCall 893
        /// Branch to push to
30ea9c1e Andy McCall ↶ 894
        #[arg(long, default_value = "main")]
895
        branch: String,
896
    },
62794ecc Andy McCall ↶ 897
    /// Check this repository's import of a Git branch: every commit's tree must be reproduced exactly
898
    Verify {
899
        /// The Git repository the import came from
900
        git_dir: PathBuf,
901
        /// Branch that was imported
902
        #[arg(long, default_value = "main")]
903
        branch: String,
904
    },
c3069537 Andy McCall ↶ 905
    /// Import a Git branch into a new Oxygen repository at DEST
906
    Import {
d42369ab Andy McCall 907
        /// Git repository to read
c3069537 Andy McCall ↶ 908
        git_dir: PathBuf,
d42369ab Andy McCall 909
        /// Directory for the new Oxygen repository
c3069537 Andy McCall ↶ 910
        dest: PathBuf,
d42369ab Andy McCall 911
        /// Branch to import
c3069537 Andy McCall ↶ 912
        #[arg(long, default_value = "main")]
913
        branch: String,
914
    },
79ab8528 Andy McCall ↶ 915
}
916
917
#[derive(Subcommand)]
83e0677b Andy McCall ↶ 918
enum PolicyCmd {
919
    /// Create the initial policy with your identity as the only root
920
    Init,
921
    /// Show the current policy
c6aa5bd9 Andy McCall ↶ 922
    Show {
d42369ab Andy McCall 923
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 924
        #[arg(long)]
925
        json: bool,
926
    },
83e0677b Andy McCall ↶ 927
    /// Allow an identity (from `oxy identity export`) to update bookmarks
928
    Grant {
d42369ab Andy McCall 929
        /// The identity to grant, exported with `oxy identity export`
83e0677b Andy McCall ↶ 930
        identity_file: PathBuf,
931
        /// Reference pattern the grant applies to (default: every bookmark)
932
        #[arg(long)]
933
        pattern: Option<String>,
28fc23d7 Andy McCall ↶ 934
        /// Where to write the proposal when more root signatures are needed
935
        #[arg(long)]
936
        out: Option<PathBuf>,
83e0677b Andy McCall ↶ 937
    },
938
    /// Revoke a key (KeyId prefix of an identity in the policy)
28fc23d7 Andy McCall ↶ 939
    Revoke {
d42369ab Andy McCall 940
        /// KeyId prefix of the identity
28fc23d7 Andy McCall ↶ 941
        key: String,
942
        /// Where to write the proposal when more root signatures are needed
943
        #[arg(long)]
944
        out: Option<PathBuf>,
945
    },
946
    /// Manage root keys and the signature threshold for policy updates
947
    Root {
948
        #[command(subcommand)]
949
        cmd: RootCmd,
950
    },
951
    /// Add your root signature to a proposal file; applies it once the threshold is met
952
    Sign {
d42369ab Andy McCall 953
        /// The proposal file to sign
28fc23d7 Andy McCall ↶ 954
        proposal: PathBuf,
955
        /// Where to write the proposal if it still needs signatures (default: in place)
956
        #[arg(long)]
957
        out: Option<PathBuf>,
958
    },
959
}
960
961
#[derive(Subcommand)]
962
enum RootCmd {
963
    /// Make an exported identity a root key
964
    Add {
d42369ab Andy McCall 965
        /// The identity to make a root, exported with `oxy identity export`
28fc23d7 Andy McCall ↶ 966
        identity_file: PathBuf,
d42369ab Andy McCall 967
        /// Where to write the proposal when more root signatures are needed
28fc23d7 Andy McCall ↶ 968
        #[arg(long)]
969
        out: Option<PathBuf>,
970
    },
971
    /// Remove a root key by KeyId prefix
972
    Remove {
d42369ab Andy McCall 973
        /// KeyId prefix of the root key
28fc23d7 Andy McCall ↶ 974
        key: String,
d42369ab Andy McCall 975
        /// Where to write the proposal when more root signatures are needed
28fc23d7 Andy McCall ↶ 976
        #[arg(long)]
977
        out: Option<PathBuf>,
978
    },
979
    /// Require this many root signatures on policy updates
980
    Threshold {
d42369ab Andy McCall 981
        /// Number of root signatures
28fc23d7 Andy McCall ↶ 982
        n: u32,
d42369ab Andy McCall 983
        /// Where to write the proposal when more root signatures are needed
28fc23d7 Andy McCall ↶ 984
        #[arg(long)]
985
        out: Option<PathBuf>,
986
    },
83e0677b Andy McCall ↶ 987
}
988
fce44ae9 Andy McCall ↶ 989
/// Open the repository containing the current directory.
990
fn open() -> Result<Repo> {
98a1620a Andy McCall ↶ 991
    let repo = Repo::open(&std::env::current_dir()?).context("opening repository")?;
992
    match AT_OP.get().and_then(|o| o.as_deref()) {
993
        Some(op) => Ok(repo.at_op(op)?),
994
        None => Ok(repo),
995
    }
fce44ae9 Andy McCall ↶ 996
}
997
d42369ab Andy McCall 998
/// `oxy man`: every page into `dir`, or the top-level page on stdout.
999
fn man(dir: Option<PathBuf>) -> Result<i32> {
1000
    use clap::CommandFactory;
1001
    let cmd = Cli::command();
1002
    match dir {
1003
        Some(dir) => {
1004
            std::fs::create_dir_all(&dir)?;
1005
            clap_mangen::generate_to(cmd, &dir)?;
1006
            let pages = std::fs::read_dir(&dir)?
1007
                .filter(|e| {
1008
                    e.as_ref()
1009
                        .is_ok_and(|e| e.path().extension().is_some_and(|x| x == "1"))
1010
                })
1011
                .count();
1012
            println!(
1013
                "{}",
1014
                ui::done(format!("Wrote {pages} man pages to {}", dir.display()))
1015
            );
1016
        }
1017
        None => clap_mangen::Man::new(cmd).render(&mut std::io::stdout())?,
1018
    }
1019
    Ok(0)
1020
}
1021
fce44ae9 Andy McCall ↶ 1022
/// Parse arguments and run; returns the process exit code.
1023
pub fn run() -> Result<i32> {
1024
    let cli = Cli::parse();
135212de Andy McCall ↶ 1025
    ui::init(cli.plain);
98a1620a Andy McCall ↶ 1026
    AT_OP.set(cli.at_op.clone()).ok();
fce44ae9 Andy McCall ↶ 1027
    match cli.cmd {
d42369ab Andy McCall 1028
        Cmd::Completions { shell } => {
1029
            use clap::CommandFactory;
1030
            clap_complete::generate(shell, &mut Cli::command(), "oxy", &mut std::io::stdout());
1031
            Ok(0)
1032
        }
1033
        Cmd::Man { dir } => man(dir),
e02bf0cd Andy McCall ↶ 1034
        Cmd::Init { path, bare } => workspace::init(path, bare),
50a046e4 Andy McCall ↶ 1035
        Cmd::Status { json } => workspace::status(json),
75167672 Andy McCall 1036
        Cmd::Prompt {
1037
            format,
1038
            glyphs,
1039
            color,
1040
        } => workspace::prompt(&format, glyphs, color.as_deref()),
1041
        Cmd::Commit {
1042
            message,
6a81dbab Andy McCall ↶ 1043
            file,
75167672 Andy McCall 1044
            depends_on,
1045
            paths,
1046
            interactive,
1047
            hunks,
6a81dbab Andy McCall ↶ 1048
        } => {
1049
            let message = match (message, file) {
1050
                (Some(m), _) => m,
1051
                (None, Some(f)) if f.as_os_str() == "-" => {
1052
                    let mut s = String::new();
1053
                    std::io::Read::read_to_string(&mut std::io::stdin(), &mut s)?;
1054
                    s
1055
                }
1056
                (None, Some(f)) => std::fs::read_to_string(&f).map_err(|e| {
1057
                    anyhow::anyhow!("reading the message from {}: {e}", f.display())
1058
                })?,
1059
                (None, None) => anyhow::bail!("a commit message is required (-m or -F)"),
1060
            };
1061
            workspace::commit(&message, &depends_on, &paths, interactive, &hunks)
1062
        }
c6aa5bd9 Andy McCall ↶ 1063
        Cmd::Cat { path, change } => workspace::cat(&path, change.as_deref()),
1064
        Cmd::Root { json } => workspace::root(json),
1065
        Cmd::Version { json } => workspace::version(json),
1066
        Cmd::Discard { paths, hunks } => workspace::discard(&paths, &hunks),
1067
        Cmd::Hunks { json } => workspace::hunks(json),
728da0f9 Andy McCall ↶ 1068
        Cmd::Squash { change, into } => workspace::squash(&change, &into),
e266b7d4 Andy McCall ↶ 1069
        Cmd::Rebase {
1070
            change,
1071
            onto,
1072
            into_working_copy,
1073
        } => workspace::rebase(&change, &onto, into_working_copy),
957fee30 Andy McCall ↶ 1074
        Cmd::Blame { path, json } => workspace::blame(&path, json),
1075
        Cmd::Bisect { cmd } => match cmd {
1076
            BisectCmd::Start => workspace::bisect_start(),
1077
            BisectCmd::Good { changes } => workspace::bisect_mark(Some(true), &changes),
1078
            BisectCmd::Bad { changes } => workspace::bisect_mark(Some(false), &changes),
1079
            BisectCmd::Skip => workspace::bisect_mark(None, &[]),
1080
            BisectCmd::Run { command } => workspace::bisect_run(&command),
c6aa5bd9 Andy McCall ↶ 1081
            BisectCmd::Status { json } => workspace::bisect_status(json),
957fee30 Andy McCall ↶ 1082
            BisectCmd::Reset => workspace::bisect_reset(),
1083
        },
75167672 Andy McCall 1084
        Cmd::Log {
47ce8b8e Andy McCall ↶ 1085
            revset,
75167672 Andy McCall 1086
            limit,
1087
            verbose,
1088
            path,
83d61e80 Andy McCall ↶ 1089
            lines,
75167672 Andy McCall 1090
            json,
47ce8b8e Andy McCall ↶ 1091
        } => workspace::log(
1092
            revset.as_deref(),
1093
            limit,
1094
            verbose,
1095
            path.as_deref(),
1096
            lines.as_deref(),
1097
            json,
1098
        ),
c6aa5bd9 Andy McCall ↶ 1099
        Cmd::Diff { change, json } => workspace::diff(change.as_deref(), json),
6a81dbab Andy McCall ↶ 1100
        Cmd::Describe {
1101
            message,
1102
            change,
1103
            json,
1104
        } => match message {
1105
            Some(m) => workspace::describe(&m, change.as_deref()),
1106
            None if change.is_some() => {
1107
                anyhow::bail!(
1108
                    "naming works on the working copy; to change a head's message pass -m"
1109
                )
1110
            }
1111
            None => workspace::describe_name(json),
1112
        },
69953b50 Andy McCall ↶ 1113
        Cmd::Amend {
1114
            message,
1115
            into,
1116
            paths,
1117
        } => workspace::amend(message.as_deref(), into.as_deref(), &paths),
23b217d7 Andy McCall ↶ 1118
        Cmd::Split { change, paths } => workspace::split(&change, &paths),
2c9ddac3 Andy McCall ↶ 1119
        Cmd::Abandon {
1120
            change,
1121
            revset,
1122
            yes,
1123
        } => workspace::abandon(change.as_deref(), revset.as_deref(), yes),
1124
        Cmd::Show {
1125
            change,
1126
            revset,
0299076f Andy McCall ↶ 1127
            stat,
2c9ddac3 Andy McCall ↶ 1128
            json,
0299076f Andy McCall ↶ 1129
        } => workspace::show(change.as_deref(), revset.as_deref(), stat, 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,
1215
            } => receipt::export(&r, &file, rev.as_deref()),
1216
            ReceiptCmd::Verify { file, json } => receipt::verify(&file, json),
1217
            ReceiptCmd::Import { file } => receipt::import(&file),
4dee277c Andy McCall ↶ 1218
        },
132b884b Andy McCall ↶ 1219
        Cmd::Tag { cmd } => match cmd {
75167672 Andy McCall 1220
            TagCmd::Create {
1221
                name,
1222
                changes,
1223
                message,
1224
            } => workspace::tag_create(&name, &changes, &message),
1196b29b Andy McCall ↶ 1225
            TagCmd::List { json } => workspace::tag_list(json),
132b884b Andy McCall ↶ 1226
        },
fce44ae9 Andy McCall ↶ 1227
        Cmd::Remote { cmd } => match cmd {
1228
            RemoteCmd::Add { name, url } => sync::remote_add(&name, &url),
1229
            RemoteCmd::Remove { name } => sync::remote_remove(&name),
c6aa5bd9 Andy McCall ↶ 1230
            RemoteCmd::List { json } => sync::remote_list(json),
fce44ae9 Andy McCall ↶ 1231
        },
c6aa5bd9 Andy McCall ↶ 1232
        Cmd::Fetch { remote, json } => sync::fetch(remote.as_deref(), json),
1233
        Cmd::Pull { remote, json } => sync::pull(remote.as_deref(), json),
75167672 Andy McCall 1234
        Cmd::Push {
1235
            remote,
1236
            force,
1237
            bookmark,
f8c69576 Andy McCall ↶ 1238
            delete,
75167672 Andy McCall 1239
            json,
f8c69576 Andy McCall ↶ 1240
        } => match delete {
1241
            Some(name) => sync::push_delete(remote.as_deref(), &name, json),
1242
            None => sync::push(remote.as_deref(), force, bookmark.as_deref(), json),
1243
        },
75167672 Andy McCall 1244
        Cmd::Serve {
1245
            root,
1246
            bind,
1247
            tokens,
1248
            tls_cert,
1249
            tls_key,
1250
        } => sync::serve(root, &bind, tokens, tls_cert.zip(tls_key)),
fce44ae9 Andy McCall ↶ 1251
        Cmd::Identity { cmd } => match cmd {
75167672 Andy McCall 1252
            IdentityCmd::Create {
1253
                name,
1254
                email,
1255
                local,
1256
                expires,
1257
            } => identity::create(name, email, local, expires),
fce44ae9 Andy McCall ↶ 1258
            IdentityCmd::Show => identity::show(),
83e0677b Andy McCall ↶ 1259
            IdentityCmd::Export { path } => identity::export(path),
119bbf50 Andy McCall ↶ 1260
            IdentityCmd::SignChallenge { challenge, json } => {
1261
                identity::sign_challenge(&challenge, json)
1262
            }
28fc23d7 Andy McCall ↶ 1263
            IdentityCmd::Rotate => identity::rotate(),
1264
            IdentityCmd::Renew { expires } => identity::renew(expires),
1265
            IdentityCmd::Revoke { key, reason } => identity::revoke(key.as_deref(), &reason),
1266
            IdentityCmd::Delegate { cmd } => match cmd {
1267
                DelegateCmd::Add { identity_file } => identity::delegate_add(&identity_file),
1268
                DelegateCmd::Remove { key } => identity::delegate_remove(&key),
1269
                DelegateCmd::List => identity::delegate_list(),
1270
            },
83e0677b Andy McCall ↶ 1271
        },
75167672 Andy McCall 1272
        Cmd::Git {
1273
            cmd: GitCmd::Export { git_dir, branch },
1274
        } => sync::git_export(&git_dir, branch.as_deref()),
1275
        Cmd::Git {
1276
            cmd: GitCmd::Fetch { url, branch },
1277
        } => sync::git_fetch(&url, &branch),
1278
        Cmd::Git {
1279
            cmd: GitCmd::Push { url, branch },
1280
        } => sync::git_push(&url, &branch),
1281
        Cmd::Git {
1282
            cmd:
1283
                GitCmd::Import {
1284
                    git_dir,
1285
                    dest,
1286
                    branch,
1287
                },
1288
        } => sync::git_import(&git_dir, &dest, &branch),
62794ecc Andy McCall ↶ 1289
        Cmd::Git {
1290
            cmd: GitCmd::Verify { git_dir, branch },
1291
        } => sync::git_verify(&git_dir, &branch),
83e0677b Andy McCall ↶ 1292
        Cmd::Policy { cmd } => match cmd {
1293
            PolicyCmd::Init => identity::policy_init(),
c6aa5bd9 Andy McCall ↶ 1294
            PolicyCmd::Show { json } => identity::policy_show(json),
75167672 Andy McCall 1295
            PolicyCmd::Grant {
1296
                identity_file,
1297
                pattern,
1298
                out,
1299
            } => identity::policy_grant(&identity_file, pattern.as_deref(), out),
28fc23d7 Andy McCall ↶ 1300
            PolicyCmd::Revoke { key, out } => identity::policy_revoke(&key, out),
1301
            PolicyCmd::Root { cmd } => match cmd {
75167672 Andy McCall 1302
                RootCmd::Add { identity_file, out } => {
1303
                    identity::policy_root_add(&identity_file, out)
1304
                }
28fc23d7 Andy McCall ↶ 1305
                RootCmd::Remove { key, out } => identity::policy_root_remove(&key, out),
1306
                RootCmd::Threshold { n, out } => identity::policy_threshold(n, out),
1307
            },
1308
            PolicyCmd::Sign { proposal, out } => identity::policy_sign(&proposal, out),
fce44ae9 Andy McCall ↶ 1309
        },
4213c41d Andy McCall ↶ 1310
        Cmd::Seal {
1311
            changes,
1312
            proposal: Some(url),
1313
            json,
1314
        } if changes.is_empty() => proposal::seal(&url, json),
d82e4409 Andy McCall ↶ 1315
        Cmd::Seal { changes, json, .. } => identity::seal(&changes, json),
1316
        Cmd::Proposal { cmd } => match cmd {
1317
            ProposalCmd::Show { url, json } => proposal::show(&url, json),
1318
            ProposalCmd::Land { url, force } => proposal::land(&url, force),
1319
        },
2c9ddac3 Andy McCall ↶ 1320
        Cmd::Verify {
1321
            change,
1322
            revset,
1323
            json,
1324
        } => identity::verify(change.as_deref(), revset.as_deref(), json),
fce44ae9 Andy McCall ↶ 1325
        Cmd::Config { key, value, user } => identity::config(&key, &value, user),
1326
    }
1327
}
d42369ab Andy McCall 1328
1329
#[cfg(test)]
1330
mod help_tests {
1331
    use super::Cli;
1332
    use clap::CommandFactory;
1333
1334
    /// Every command and every argument explains itself, so `--help`,
1335
    /// completions and the man pages are complete.
1336
    #[test]
1337
    fn every_command_and_argument_has_help() {
1338
        fn walk(cmd: &clap::Command, path: &str, missing: &mut Vec<String>) {
1339
            let here = format!("{path} {}", cmd.get_name()).trim().to_string();
1340
            if cmd.get_about().is_none() && path != "" {
1341
                missing.push(format!("{here} (command)"));
1342
            }
1343
            for a in cmd.get_arguments() {
1344
                let id = a.get_id().as_str();
1345
                if id == "help" || id == "version" || a.is_global_set() && path != "" {
1346
                    continue;
1347
                }
1348
                if a.get_help().is_none() && a.get_long_help().is_none() {
1349
                    missing.push(format!("{here} {id}"));
1350
                }
1351
            }
1352
            for sub in cmd.get_subcommands() {
1353
                walk(sub, &here, missing);
1354
            }
1355
        }
1356
        let mut missing = Vec::new();
1357
        walk(&Cli::command(), "", &mut missing);
1358
        assert!(
1359
            missing.is_empty(),
1360
            "{} without help:\n{}",
1361
            missing.len(),
1362
            missing.join("\n")
1363
        );
1364
    }
1365
}