OXYGENHUB
# d0bf2da15094 oxygen / src / cli / mod.rs
48.7 KiB · Rust · last changed A repository kept on a store: oxy init --store 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,
d069701a Andy McCall ↶ 47
        /// Keep the objects and the operation log on this store
48
        /// (dir://PATH, s3://BUCKET/PREFIX, gs://…, az://…) instead of
49
        /// in .oxy, with a local cache in front (storage.cache, 2 GiB)
50
        #[arg(long, value_name = "URL")]
51
        store: Option<String>,
e02bf0cd Andy McCall ↶ 52
    },
fce44ae9 Andy McCall ↶ 53
    /// Clone a repository from a local path or an http(s) URL
b3c5a59a Andy McCall ↶ 54
    Clone {
d42369ab Andy McCall 55
        /// Local path or http(s) URL of the repository
b3c5a59a Andy McCall ↶ 56
        url: String,
d42369ab Andy McCall 57
        /// Directory to clone into (default: the last part of the URL)
b3c5a59a Andy McCall ↶ 58
        dest: Option<PathBuf>,
59
        /// Leave blobs larger than this (e.g. 1M) to be fetched on first read
60
        #[arg(long)]
61
        max_blob: Option<String>,
7421309f Andy McCall ↶ 62
        /// Materialize only these paths (repeatable); implies lazy blobs
63
        #[arg(long = "sparse")]
64
        sparse: Vec<String>,
2863456a Andy McCall ↶ 65
        /// Shallow clone: fetch only this many levels of history below the heads
66
        #[arg(long)]
67
        depth: Option<u32>,
14edbaaf Andy McCall ↶ 68
        /// Clone the subrepos too (as oxy submodule update --init)
69
        #[arg(long)]
70
        recursive: bool,
b3c5a59a Andy McCall ↶ 71
    },
2863456a Andy McCall ↶ 72
    /// Fetch more history below a shallow clone's boundary
73
    Deepen {
d42369ab Andy McCall 74
        /// Levels of history to add below the boundary
2863456a Andy McCall ↶ 75
        #[arg(default_value_t = 10)]
76
        depth: u32,
d42369ab Andy McCall 77
        /// Remote to fetch the history from
2863456a Andy McCall ↶ 78
        #[arg(long, default_value = "origin")]
79
        remote: String,
80
    },
7421309f Andy McCall ↶ 81
    /// Show or set the sparse filter (paths to materialize); re-checks out the bookmark
d42369ab Andy McCall 82
    Sparse {
83
        /// Paths to materialize; none prints the current filter
84
        paths: Vec<String>,
85
    },
fce44ae9 Andy McCall ↶ 86
    /// Show the working copy: changed paths and conflicts
50a046e4 Andy McCall ↶ 87
    Status {
88
        /// Machine-readable output: paths, and every conflict with its kind and contributing changes
89
        #[arg(long)]
90
        json: bool,
91
    },
135212de Andy McCall ↶ 92
    /// One-line summary for shell prompts; fast and records nothing
93
    Prompt {
694805cc Andy McCall ↶ 94
        /// 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 ↶ 95
        #[arg(long, default_value = oxy_core::repo::DEFAULT_PROMPT_FORMAT)]
96
        format: String,
694805cc Andy McCall ↶ 97
        /// Glyph format (%i %b %c %s%U%O) instead of the plain default
98
        #[arg(long)]
99
        glyphs: bool,
100
        /// Colour by state (cyan clean, yellow dirty, red conflicted): raw escapes, or guarded for a bash or zsh PS1
101
        #[arg(long, value_parser = ["raw", "bash", "zsh"])]
102
        color: Option<String>,
135212de Andy McCall ↶ 103
    },
fce44ae9 Andy McCall ↶ 104
    /// Record the working copy as a change on the current bookmark
105
    Commit {
d42369ab Andy McCall 106
        /// The change's message: a subject line, then optionally a blank line and a body
6a81dbab Andy McCall ↶ 107
        #[arg(short, long, required_unless_present = "file", conflicts_with = "file")]
108
        message: Option<String>,
109
        /// Read the message from FILE (`-` for standard input)
110
        #[arg(short = 'F', long, value_name = "FILE")]
111
        file: Option<PathBuf>,
fce44ae9 Andy McCall ↶ 112
        /// Extra explicit dependencies (ChangeId prefix, #hash prefix)
113
        #[arg(long = "depends-on")]
114
        depends_on: Vec<String>,
957fee30 Andy McCall ↶ 115
        /// Commit only these paths; the rest stays as uncommitted work
116
        paths: Vec<String>,
117
        /// Choose hunks one by one
118
        #[arg(short, long)]
119
        interactive: bool,
c6aa5bd9 Andy McCall ↶ 120
        /// Commit these hunks (as `oxy hunks` numbers them), comma separated
121
        #[arg(long, value_delimiter = ',')]
122
        hunks: Vec<usize>,
fce44ae9 Andy McCall ↶ 123
    },
728da0f9 Andy McCall ↶ 124
    /// Fold CHANGE into one of its dependencies (keeps that change's id)
125
    Squash {
d42369ab Andy McCall 126
        /// The change to fold (ChangeId prefix, #hash prefix)
728da0f9 Andy McCall ↶ 127
        change: String,
d42369ab Andy McCall 128
        /// The dependency that absorbs it
728da0f9 Andy McCall ↶ 129
        #[arg(long)]
130
        into: String,
131
    },
132
    /// Re-express CHANGE against another base state
133
    Rebase {
d42369ab Andy McCall 134
        /// The change to re-express (ChangeId prefix, #hash prefix)
728da0f9 Andy McCall ↶ 135
        change: String,
136
        /// The changes, bookmark or tag whose state becomes the new base
137
        #[arg(long, required = true, num_args = 1..)]
138
        onto: Vec<String>,
e266b7d4 Andy McCall ↶ 139
        /// Where the rebase would be conflicted, merge the target into the
140
        /// current bookmark instead, leaving the conflict in the working
141
        /// copy to fix and commit
142
        #[arg(long)]
143
        into_working_copy: bool,
728da0f9 Andy McCall ↶ 144
    },
957fee30 Andy McCall ↶ 145
    /// Show which change introduced each line of a file
146
    Blame {
d42369ab Andy McCall 147
        /// File to annotate, relative to the repository root
957fee30 Andy McCall ↶ 148
        path: String,
d42369ab Andy McCall 149
        /// Machine-readable output: one JSON document on stdout
957fee30 Andy McCall ↶ 150
        #[arg(long)]
151
        json: bool,
152
    },
153
    /// Find the change that introduced a regression
154
    Bisect {
155
        #[command(subcommand)]
156
        cmd: BisectCmd,
157
    },
fce44ae9 Andy McCall ↶ 158
    /// List changes reachable from the bookmark and the working copy
94084087 Andy McCall ↶ 159
    Log {
47ce8b8e Andy McCall ↶ 160
        /// Show the changes a revset selects: `main..feature & author(andy)`,
161
        /// `touches("src/**") & date(-7d..)` (see docs/revset_query_language.md)
162
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with_all = ["path", "lines"])]
163
        revset: Option<String>,
94084087 Andy McCall ↶ 164
        /// Show at most this many changes
165
        #[arg(short = 'n', long)]
166
        limit: Option<usize>,
167
        /// Show full messages, dependencies, and signatures
168
        #[arg(short, long)]
169
        verbose: bool,
c6aa5bd9 Andy McCall ↶ 170
        /// Only changes touching this path (renames followed)
171
        #[arg(long)]
172
        path: Option<String>,
83d61e80 Andy McCall ↶ 173
        /// Only changes that wrote or deleted lines START to END of PATH
174
        /// (numbered as in the working copy's base), or deleted lines from
175
        /// between them: the history of a function
176
        #[arg(short = 'L', value_name = "START,END:PATH", conflicts_with = "path")]
177
        lines: Option<String>,
d42369ab Andy McCall 178
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 179
        #[arg(long)]
180
        json: bool,
94084087 Andy McCall ↶ 181
    },
fce44ae9 Andy McCall ↶ 182
    /// Show what the working copy changes against its base
c6aa5bd9 Andy McCall ↶ 183
    Diff {
184
        /// A change instead of the working copy
185
        change: Option<String>,
d42369ab Andy McCall 186
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 187
        #[arg(long)]
188
        json: bool,
189
    },
190
    /// Print a file as it is in a state (default: the working copy's base)
191
    Cat {
d42369ab Andy McCall 192
        /// File to print, relative to the repository root
c6aa5bd9 Andy McCall ↶ 193
        path: String,
194
        /// A change, bookmark, or tag
195
        #[arg(short = 'r', long)]
196
        change: Option<String>,
197
    },
198
    /// Print the repository root, workspace, and bookmark
199
    Root {
d42369ab Andy McCall 200
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 201
        #[arg(long)]
202
        json: bool,
203
    },
204
    /// Print the version of oxy, its repository format, and protocol
205
    Version {
d42369ab Andy McCall 206
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 207
        #[arg(long)]
208
        json: bool,
209
    },
210
    /// Restore paths to the working copy's base, or undo chosen hunks
211
    Discard {
d42369ab Andy McCall 212
        /// Paths to restore; none with --hunks, or everything with neither
c6aa5bd9 Andy McCall ↶ 213
        paths: Vec<String>,
214
        /// Hunk indices as `oxy hunks` numbers them, comma separated
215
        #[arg(long, value_delimiter = ',')]
216
        hunks: Vec<usize>,
217
    },
218
    /// List the working copy's hunks, numbered as commit --hunks expects
219
    Hunks {
d42369ab Andy McCall 220
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 221
        #[arg(long)]
222
        json: bool,
223
    },
6a81dbab Andy McCall ↶ 224
    /// With -m, change the message of a head; without, name the working
225
    /// copy for a build: its tag, or the nearest tag plus distance and
226
    /// change, or the bookmark and change, and -dirty
614541c3 Andy McCall ↶ 227
    Describe {
d42369ab Andy McCall 228
        /// The new message
614541c3 Andy McCall ↶ 229
        #[arg(short, long)]
6a81dbab Andy McCall ↶ 230
        message: Option<String>,
d42369ab Andy McCall 231
        /// The head to describe (default: the one the working copy sits on)
614541c3 Andy McCall ↶ 232
        change: Option<String>,
6a81dbab Andy McCall ↶ 233
        /// Machine-readable output (naming only)
234
        #[arg(long, conflicts_with = "message")]
235
        json: bool,
614541c3 Andy McCall ↶ 236
    },
23b217d7 Andy McCall ↶ 237
    /// Fold the working copy into the head it sits on, or into CHANGE with --into
614541c3 Andy McCall ↶ 238
    Amend {
d42369ab Andy McCall 239
        /// Replace the message too
614541c3 Andy McCall ↶ 240
        #[arg(short, long)]
241
        message: Option<String>,
23b217d7 Andy McCall ↶ 242
        /// Amend an older change; the edits must touch only lines it already knows
243
        #[arg(long)]
244
        into: Option<String>,
614541c3 Andy McCall ↶ 245
    },
23b217d7 Andy McCall ↶ 246
    /// Split a head: the named paths become a separate first change
d42369ab Andy McCall 247
    Split {
248
        /// The head to split
249
        change: String,
250
        /// Paths whose edits become the first change
251
        paths: Vec<String>,
252
    },
2c9ddac3 Andy McCall ↶ 253
    /// Drop a change from the bookmark; its content stays on disk as uncommitted work
d42369ab Andy McCall 254
    Abandon {
2c9ddac3 Andy McCall ↶ 255
        /// The change to drop (ChangeId prefix, #hash prefix)
256
        #[arg(required_unless_present = "revset")]
257
        change: Option<String>,
258
        /// Drop every change a revset selects, newest first
259
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
260
        revset: Option<String>,
261
        /// Drop more than five changes without asking
262
        #[arg(long, short = 'y')]
263
        yes: bool,
d42369ab Andy McCall 264
    },
2c9ddac3 Andy McCall ↶ 265
    /// Show one change (ChangeId prefix, #hash prefix, or @), or those a revset selects
c6aa5bd9 Andy McCall ↶ 266
    Show {
d42369ab Andy McCall 267
        /// ChangeId prefix, #hash prefix, or @ for the working copy
2c9ddac3 Andy McCall ↶ 268
        #[arg(required_unless_present = "revset")]
269
        change: Option<String>,
270
        /// Show every change a revset selects
271
        #[arg(short = 'r', long, value_name = "REVSET", conflicts_with = "change")]
272
        revset: Option<String>,
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,
614f55e1 Andy McCall ↶ 485
        /// The value to set (none with --unset)
486
        #[arg(required_unless_present = "unset")]
487
        value: Option<String>,
fce44ae9 Andy McCall ↶ 488
        /// Write to the user file (~/.config/oxy/config.toml) instead of this repository
489
        #[arg(long)]
490
        user: bool,
614f55e1 Andy McCall ↶ 491
        /// Remove the key from this repository's file (or the user file with --user)
492
        #[arg(long)]
493
        unset: bool,
fce44ae9 Andy McCall ↶ 494
    },
495
}
496
497
#[derive(Subcommand)]
498
enum OpCmd {
98a1620a Andy McCall ↶ 499
    /// List operations, newest first, with what each changed
c6aa5bd9 Andy McCall ↶ 500
    Log {
98a1620a Andy McCall ↶ 501
        /// Show only the latest N (snapshots folded together count as one)
502
        #[arg(short = 'n', long)]
503
        limit: Option<usize>,
d42369ab Andy McCall 504
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 505
        #[arg(long)]
506
        json: bool,
98a1620a Andy McCall ↶ 507
    },
508
    /// Go back to the bookmarks and working copy as they were after OP (recorded as a new operation, so it can be undone)
509
    Restore {
510
        /// The operation: an ID prefix from oxy op log, @ or @-
511
        op: String,
512
        /// Throw away uncommitted working-copy changes
513
        #[arg(long)]
514
        discard: bool,
515
    },
516
    /// Undo OP alone, keeping every operation after it: the bookmarks it moved go back
517
    Revert {
518
        /// The operation: an ID prefix from oxy op log
519
        op: String,
c6aa5bd9 Andy McCall ↶ 520
    },
fce44ae9 Andy McCall ↶ 521
}
522
523
#[derive(Subcommand)]
4e88e774 Andy McCall ↶ 524
enum WorkspaceCmd {
525
    /// Create a workspace at PATH checked out on CHANGE... (default: the bookmark heads)
d42369ab Andy McCall 526
    Add {
527
        /// Directory for the new workspace (must be empty or absent)
528
        path: PathBuf,
529
        /// Changes whose state to check out there
530
        changes: Vec<String>,
531
    },
532
    /// List workspaces and their working-copy changes
1196b29b Andy McCall ↶ 533
    List {
d42369ab Andy McCall 534
        /// Machine-readable output: one JSON document on stdout
1196b29b Andy McCall ↶ 535
        #[arg(long)]
536
        json: bool,
537
    },
4e88e774 Andy McCall ↶ 538
    /// Stop tracking a workspace (by id prefix or path); its files stay
d42369ab Andy McCall 539
    Forget {
540
        /// Workspace id prefix or path
541
        workspace: String,
542
    },
4e88e774 Andy McCall ↶ 543
}
544
545
#[derive(Subcommand)]
957fee30 Andy McCall ↶ 546
enum BisectCmd {
547
    /// Begin; remembers where the working copy was
548
    Start,
549
    /// Mark CHANGE... (or the state under test) as good
d42369ab Andy McCall 550
    Good {
551
        /// Changes known to be good (default: the state under test)
552
        changes: Vec<String>,
553
    },
957fee30 Andy McCall ↶ 554
    /// Mark CHANGE... (or the state under test) as bad
d42369ab Andy McCall 555
    Bad {
556
        /// Changes known to be bad (default: the state under test)
557
        changes: Vec<String>,
558
    },
957fee30 Andy McCall ↶ 559
    /// The state under test cannot be tested; try another
560
    Skip,
561
    /// Run a command for each step: exit 0 good, 125 skip, else bad
562
    Run {
d42369ab Andy McCall 563
        /// Command and arguments to run at each step
957fee30 Andy McCall ↶ 564
        #[arg(required = true, trailing_var_arg = true)]
565
        command: Vec<String>,
566
    },
567
    /// Where the search stands
c6aa5bd9 Andy McCall ↶ 568
    Status {
d42369ab Andy McCall 569
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 570
        #[arg(long)]
571
        json: bool,
572
    },
957fee30 Andy McCall ↶ 573
    /// Restore the working copy and forget the search
574
    Reset,
575
}
576
577
#[derive(Subcommand)]
7b9809e6 Andy McCall ↶ 578
enum BookmarkCmd {
579
    /// Create a bookmark at CHANGE... (default: the working copy's base)
d42369ab Andy McCall 580
    Create {
581
        /// Name of the new bookmark
582
        name: String,
4fe7d604 Andy McCall ↶ 583
        /// Its heads (default: the working copy's base). A state is its
584
        /// heads and what they depend on: a change alone may leave out
585
        /// earlier changes of the current state, which is refused unless
586
        /// --upto or --only says which is meant
d42369ab Andy McCall 587
        changes: Vec<String>,
4fe7d604 Andy McCall ↶ 588
        /// Everything of the current state up to CHANGE..., as a Git
589
        /// branch at a commit would hold
590
        #[arg(long, conflicts_with = "only")]
591
        upto: bool,
592
        /// Just CHANGE... and what they depend on
593
        #[arg(long)]
594
        only: bool,
d42369ab Andy McCall 595
    },
7b9809e6 Andy McCall ↶ 596
    /// Point an existing bookmark at CHANGE...
d42369ab Andy McCall 597
    Set {
598
        /// The bookmark to move
599
        name: String,
06d16dc2 Andy McCall ↶ 600
        /// Its new heads. A change alone may leave out changes the
601
        /// bookmark now holds that were recorded before it, which is
602
        /// refused unless --upto or --only says which is meant
d42369ab Andy McCall 603
        changes: Vec<String>,
06d16dc2 Andy McCall ↶ 604
        /// Everything the bookmark holds up to CHANGE..., as a Git branch
605
        /// moved to a commit would hold
606
        #[arg(long, conflicts_with = "only")]
607
        upto: bool,
608
        /// Just CHANGE... and what they depend on
609
        #[arg(long)]
610
        only: bool,
d42369ab Andy McCall 611
    },
7b9809e6 Andy McCall ↶ 612
    /// Remove a bookmark; its changes stay
d42369ab Andy McCall 613
    Delete {
614
        /// The bookmark to remove
615
        name: String,
616
    },
7b9809e6 Andy McCall ↶ 617
    /// List bookmarks with their heads and difference from origin
c6aa5bd9 Andy McCall ↶ 618
    List {
14edbaaf Andy McCall ↶ 619
        /// Also list remotes' bookmarks that have no local bookmark
620
        #[arg(long, short)]
621
        all: bool,
d42369ab Andy McCall 622
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 623
        #[arg(long)]
624
        json: bool,
625
    },
61e3bce7 Andy McCall ↶ 626
    /// 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 ↶ 627
    Switch {
14edbaaf Andy McCall ↶ 628
        /// The bookmark to work on; one only a remote has (NAME or REMOTE/NAME) is created from it
7b9809e6 Andy McCall ↶ 629
        name: String,
630
        /// Throw away uncommitted working-copy changes
631
        #[arg(long)]
632
        discard: bool,
61e3bce7 Andy McCall ↶ 633
        /// Take uncommitted changes along; refused when NAME has other
634
        /// versions of the files they touch
635
        #[arg(long, conflicts_with = "discard")]
636
        carry: bool,
ff1f62fe Andy McCall ↶ 637
    },
638
}
639
640
#[derive(Subcommand)]
641
enum AuthCmd {
642
    /// Sign in to HUB in the browser (device sign-in) and keep the token for
643
    /// every repository there
644
    Login {
645
        /// The hub, as https://oxygenhub.io or oxygenhub.io (default: this checkout's origin)
646
        hub: Option<String>,
647
        /// Read a token from standard input instead (for CI and scripts)
648
        #[arg(long)]
649
        with_token: bool,
650
        /// PEM file of extra roots to trust (a hub with a self-signed certificate)
651
        #[arg(long)]
652
        ca: Option<PathBuf>,
7b9809e6 Andy McCall ↶ 653
    },
ff1f62fe Andy McCall ↶ 654
    /// List the hubs you are signed in to, checking each token with its hub
655
    Status,
656
    /// Forget HUB's token and revoke it on the hub
657
    Logout {
658
        /// The hub (default: this checkout's origin, or the only one)
659
        hub: Option<String>,
660
    },
7b9809e6 Andy McCall ↶ 661
}
662
663
#[derive(Subcommand)]
4dee277c Andy McCall ↶ 664
enum SubmoduleCmd {
665
    /// Clone URL (Oxygen or Git) into PATH and register it in .oxymodules
666
    Add {
d42369ab Andy McCall 667
        /// URL or path of the Oxygen or Git repository
4dee277c Andy McCall ↶ 668
        url: String,
d42369ab Andy McCall 669
        /// Where to put it, relative to the repository root
4dee277c Andy McCall ↶ 670
        path: String,
671
        /// Bookmark (Oxygen) or branch (Git) to check out and track
672
        #[arg(long)]
673
        bookmark: Option<String>,
674
    },
675
    /// Bring nested repositories to their pins
676
    Update {
677
        /// Clone nested repositories that are absent
678
        #[arg(long)]
679
        init: bool,
d42369ab Andy McCall 680
        /// Subrepos to update (default: all)
4dee277c Andy McCall ↶ 681
        paths: Vec<String>,
682
    },
683
    /// List subrepos with their pins and on-disk state
c6aa5bd9 Andy McCall ↶ 684
    Status {
d42369ab Andy McCall 685
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 686
        #[arg(long)]
687
        json: bool,
688
    },
4dee277c Andy McCall ↶ 689
    /// Unregister PATH; the directory stays, the node goes with the next commit
d42369ab Andy McCall 690
    Remove {
691
        /// The subrepo to unregister
692
        path: String,
693
    },
4dee277c Andy McCall ↶ 694
}
695
696
#[derive(Subcommand)]
fc1a466a Andy McCall ↶ 697
enum ReceiptCmd {
698
    /// The receipts kept for a state (default: the bookmark heads)
699
    List {
700
        /// Change, bookmark or tag whose state to look at
701
        rev: Option<String>,
702
        /// Machine-readable output: one JSON document on stdout
703
        #[arg(long)]
704
        json: bool,
705
    },
706
    /// One receipt in full, and whether its signature verifies
707
    Show {
708
        /// The receipt (a prefix of its hash, as `list` shows it)
709
        receipt: String,
710
        /// Change, bookmark or tag whose state holds it
711
        #[arg(long)]
712
        rev: Option<String>,
713
        /// Machine-readable output: one JSON document on stdout
714
        #[arg(long)]
715
        json: bool,
716
    },
717
    /// Write a signed receipt to FILE
718
    Export {
719
        /// The receipt (a prefix of its hash, as `list` shows it)
720
        receipt: String,
721
        /// Where to write it
722
        file: String,
723
        /// Change, bookmark or tag whose state holds it
724
        #[arg(long)]
725
        rev: Option<String>,
726
    },
727
    /// Check a signed receipt in FILE without keeping it
728
    Verify {
729
        /// A signed receipt, as a runner or `export` writes it
730
        file: String,
731
        /// Machine-readable output: one JSON document on stdout
732
        #[arg(long)]
733
        json: bool,
734
    },
735
    /// Verify a signed receipt in FILE and keep it with its state
736
    Import {
737
        /// A signed receipt, as a runner or `export` writes it
738
        file: String,
739
    },
740
}
741
742
#[derive(Subcommand)]
132b884b Andy McCall ↶ 743
enum TagCmd {
744
    /// Tag the state of CHANGE... (default: the bookmark heads)
745
    Create {
d42369ab Andy McCall 746
        /// Name of the tag; tags never move
132b884b Andy McCall ↶ 747
        name: String,
d42369ab Andy McCall 748
        /// Changes whose state to tag (default: the bookmark heads)
132b884b Andy McCall ↶ 749
        changes: Vec<String>,
d42369ab Andy McCall 750
        /// A message recorded with the tag
132b884b Andy McCall ↶ 751
        #[arg(short, long, default_value = "")]
752
        message: String,
753
    },
d42369ab Andy McCall 754
    /// List tags and the states they name
1196b29b Andy McCall ↶ 755
    List {
d42369ab Andy McCall 756
        /// Machine-readable output: one JSON document on stdout
1196b29b Andy McCall ↶ 757
        #[arg(long)]
758
        json: bool,
759
    },
132b884b Andy McCall ↶ 760
}
761
762
#[derive(Subcommand)]
fce44ae9 Andy McCall ↶ 763
enum RemoteCmd {
d42369ab Andy McCall 764
    /// Add a remote
75167672 Andy McCall 765
    Add {
d42369ab Andy McCall 766
        /// Name to refer to the remote by, such as origin
75167672 Andy McCall 767
        name: String,
d42369ab Andy McCall 768
        /// Local path or http(s) URL of the repository
75167672 Andy McCall 769
        url: String,
770
    },
d42369ab Andy McCall 771
    /// Remove a remote
75167672 Andy McCall 772
    Remove {
d42369ab Andy McCall 773
        /// The remote to remove
75167672 Andy McCall 774
        name: String,
775
    },
d42369ab Andy McCall 776
    /// List remotes and their URLs
c6aa5bd9 Andy McCall ↶ 777
    List {
d42369ab Andy McCall 778
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 779
        #[arg(long)]
780
        json: bool,
781
    },
fce44ae9 Andy McCall ↶ 782
}
783
784
#[derive(Subcommand)]
d82e4409 Andy McCall ↶ 785
enum ProposalCmd {
786
    /// Show a proposal by its hub URL
787
    Show {
d42369ab Andy McCall 788
        /// The proposal's URL on the hub
d82e4409 Andy McCall ↶ 789
        url: String,
d42369ab Andy McCall 790
        /// Machine-readable output: one JSON document on stdout
d82e4409 Andy McCall ↶ 791
        #[arg(long)]
792
        json: bool,
793
    },
794
    /// Fetch the proposal's changes, set the target bookmark to the projected state, and push with your key
795
    Land {
d42369ab Andy McCall 796
        /// The proposal's URL on the hub
d82e4409 Andy McCall ↶ 797
        url: String,
798
        /// Land even when the hub reports blockers
799
        #[arg(long)]
800
        force: bool,
801
    },
802
}
803
804
#[derive(Subcommand)]
fce44ae9 Andy McCall ↶ 805
enum IdentityCmd {
806
    /// Generate a composite Ed25519 + ML-DSA-65 key pair and make it your author identity
807
    Create {
d42369ab Andy McCall 808
        /// Your name (default: author.name)
fce44ae9 Andy McCall ↶ 809
        #[arg(long)]
810
        name: Option<String>,
d42369ab Andy McCall 811
        /// Your email (default: author.email)
fce44ae9 Andy McCall ↶ 812
        #[arg(long)]
813
        email: Option<String>,
814
        /// Record the author in this repository only, not in the user config
815
        #[arg(long)]
816
        local: bool,
28fc23d7 Andy McCall ↶ 817
        /// Expire the identity this many days from now
818
        #[arg(long)]
819
        expires: Option<u64>,
fce44ae9 Andy McCall ↶ 820
    },
821
    /// Show the configured identity
822
    Show,
83e0677b Andy McCall ↶ 823
    /// Write your identity object to a file, to hand to a policy holder
d42369ab Andy McCall 824
    Export {
e3d071ce Andy McCall ↶ 825
        /// File to write (default: <key>.identity in the current directory)
d42369ab Andy McCall 826
        path: Option<PathBuf>,
827
    },
7aa2dc93 Andy McCall ↶ 828
    /// Sign a host's challenge (hex, at least 16 bytes) to prove you hold your key; prints the signature as hex
829
    SignChallenge {
d42369ab Andy McCall 830
        /// The host's challenge, as hex
7aa2dc93 Andy McCall ↶ 831
        challenge: String,
d42369ab Andy McCall 832
        /// Machine-readable output: one JSON document on stdout
7aa2dc93 Andy McCall ↶ 833
        #[arg(long)]
834
        json: bool,
835
    },
28fc23d7 Andy McCall ↶ 836
    /// Move to a fresh key pair; the policy follows if it names your key
837
    Rotate,
838
    /// Re-issue your identity with a new expiry (in days from now; 0 = never)
839
    Renew {
d42369ab Andy McCall 840
        /// Days from now until it expires; 0 for never
28fc23d7 Andy McCall ↶ 841
        #[arg(long)]
842
        expires: u64,
843
    },
844
    /// Revoke a key: yours by default, or any key if you hold a policy root
845
    Revoke {
846
        /// KeyId prefix (default: your own key)
847
        key: Option<String>,
d42369ab Andy McCall 848
        /// Why, recorded in the revocation
28fc23d7 Andy McCall ↶ 849
        #[arg(long, default_value = "")]
850
        reason: String,
851
    },
852
    /// Keys allowed to sign or seal on your behalf
853
    Delegate {
854
        #[command(subcommand)]
855
        cmd: DelegateCmd,
856
    },
857
}
858
859
#[derive(Subcommand)]
860
enum DelegateCmd {
861
    /// Add a delegate from an exported identity file
d42369ab Andy McCall 862
    Add {
614f55e1 Andy McCall ↶ 863
        /// The delegates' exported identity files: one rotation for all of them
864
        #[arg(required = true)]
865
        identity_file: Vec<PathBuf>,
7ba155f2 Andy McCall ↶ 866
        /// What it may do for you: changes, refs, seal (comma-separated) or all.
867
        /// An agent gets `changes`; a host that lands for you needs `changes,refs`
868
        #[arg(long, default_value = "changes")]
869
        scope: String,
870
        /// How long for: 30m, 8h, 7d, or a number of days (default: until removed)
871
        #[arg(long)]
872
        expires: Option<String>,
d42369ab Andy McCall 873
    },
28fc23d7 Andy McCall ↶ 874
    /// Remove a delegate by KeyId prefix
d42369ab Andy McCall 875
    Remove {
876
        /// KeyId prefix of the delegate
877
        key: String,
878
    },
28fc23d7 Andy McCall ↶ 879
    /// List delegates
880
    List,
fce44ae9 Andy McCall ↶ 881
}
882
83e0677b Andy McCall ↶ 883
#[derive(Subcommand)]
79ab8528 Andy McCall ↶ 884
enum GitCmd {
885
    /// Export the current bookmark to a Git repository (created bare if absent)
30ea9c1e Andy McCall ↶ 886
    Export {
d42369ab Andy McCall 887
        /// Git repository to write to (created bare if absent)
30ea9c1e Andy McCall ↶ 888
        git_dir: PathBuf,
889
        /// Git branch to write (default: the bookmark name)
890
        #[arg(long)]
891
        branch: Option<String>,
892
    },
893
    /// Fetch a branch from a Git remote (path or URL) into the current bookmark
894
    Fetch {
d42369ab Andy McCall 895
        /// Git remote: a path or URL
30ea9c1e Andy McCall ↶ 896
        url: String,
d42369ab Andy McCall 897
        /// Branch to fetch
30ea9c1e Andy McCall ↶ 898
        #[arg(long, default_value = "main")]
899
        branch: String,
900
    },
901
    /// Push the current bookmark to a branch of a Git remote (fetch first)
902
    Push {
d42369ab Andy McCall 903
        /// Git remote: a path or URL
30ea9c1e Andy McCall ↶ 904
        url: String,
d42369ab Andy McCall 905
        /// Branch to push to
30ea9c1e Andy McCall ↶ 906
        #[arg(long, default_value = "main")]
907
        branch: String,
908
    },
62794ecc Andy McCall ↶ 909
    /// Check this repository's import of a Git branch: every commit's tree must be reproduced exactly
910
    Verify {
911
        /// The Git repository the import came from
912
        git_dir: PathBuf,
913
        /// Branch that was imported
914
        #[arg(long, default_value = "main")]
915
        branch: String,
916
    },
c3069537 Andy McCall ↶ 917
    /// Import a Git branch into a new Oxygen repository at DEST
918
    Import {
d42369ab Andy McCall 919
        /// Git repository to read
c3069537 Andy McCall ↶ 920
        git_dir: PathBuf,
d42369ab Andy McCall 921
        /// Directory for the new Oxygen repository
c3069537 Andy McCall ↶ 922
        dest: PathBuf,
d42369ab Andy McCall 923
        /// Branch to import
c3069537 Andy McCall ↶ 924
        #[arg(long, default_value = "main")]
925
        branch: String,
926
    },
79ab8528 Andy McCall ↶ 927
}
928
929
#[derive(Subcommand)]
83e0677b Andy McCall ↶ 930
enum PolicyCmd {
931
    /// Create the initial policy with your identity as the only root
932
    Init,
933
    /// Show the current policy
c6aa5bd9 Andy McCall ↶ 934
    Show {
d42369ab Andy McCall 935
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 936
        #[arg(long)]
937
        json: bool,
938
    },
83e0677b Andy McCall ↶ 939
    /// Allow an identity (from `oxy identity export`) to update bookmarks
940
    Grant {
d42369ab Andy McCall 941
        /// The identity to grant, exported with `oxy identity export`
83e0677b Andy McCall ↶ 942
        identity_file: PathBuf,
943
        /// Reference pattern the grant applies to (default: every bookmark)
944
        #[arg(long)]
945
        pattern: Option<String>,
28fc23d7 Andy McCall ↶ 946
        /// Where to write the proposal when more root signatures are needed
947
        #[arg(long)]
948
        out: Option<PathBuf>,
83e0677b Andy McCall ↶ 949
    },
950
    /// Revoke a key (KeyId prefix of an identity in the policy)
28fc23d7 Andy McCall ↶ 951
    Revoke {
d42369ab Andy McCall 952
        /// KeyId prefix of the identity
28fc23d7 Andy McCall ↶ 953
        key: String,
954
        /// Where to write the proposal when more root signatures are needed
955
        #[arg(long)]
956
        out: Option<PathBuf>,
957
    },
958
    /// Manage root keys and the signature threshold for policy updates
959
    Root {
960
        #[command(subcommand)]
961
        cmd: RootCmd,
962
    },
963
    /// Add your root signature to a proposal file; applies it once the threshold is met
964
    Sign {
d42369ab Andy McCall 965
        /// The proposal file to sign
28fc23d7 Andy McCall ↶ 966
        proposal: PathBuf,
967
        /// Where to write the proposal if it still needs signatures (default: in place)
968
        #[arg(long)]
969
        out: Option<PathBuf>,
970
    },
971
}
972
973
#[derive(Subcommand)]
974
enum RootCmd {
975
    /// Make an exported identity a root key
976
    Add {
d42369ab Andy McCall 977
        /// The identity to make a root, exported with `oxy identity export`
28fc23d7 Andy McCall ↶ 978
        identity_file: PathBuf,
d42369ab Andy McCall 979
        /// Where to write the proposal when more root signatures are needed
28fc23d7 Andy McCall ↶ 980
        #[arg(long)]
981
        out: Option<PathBuf>,
982
    },
983
    /// Remove a root key by KeyId prefix
984
    Remove {
d42369ab Andy McCall 985
        /// KeyId prefix of the root key
28fc23d7 Andy McCall ↶ 986
        key: String,
d42369ab Andy McCall 987
        /// Where to write the proposal when more root signatures are needed
28fc23d7 Andy McCall ↶ 988
        #[arg(long)]
989
        out: Option<PathBuf>,
990
    },
991
    /// Require this many root signatures on policy updates
992
    Threshold {
d42369ab Andy McCall 993
        /// Number of root signatures
28fc23d7 Andy McCall ↶ 994
        n: u32,
d42369ab Andy McCall 995
        /// Where to write the proposal when more root signatures are needed
28fc23d7 Andy McCall ↶ 996
        #[arg(long)]
997
        out: Option<PathBuf>,
998
    },
83e0677b Andy McCall ↶ 999
}
1000
fce44ae9 Andy McCall ↶ 1001
/// Open the repository containing the current directory.
1002
fn open() -> Result<Repo> {
98a1620a Andy McCall ↶ 1003
    let repo = Repo::open(&std::env::current_dir()?).context("opening repository")?;
1004
    match AT_OP.get().and_then(|o| o.as_deref()) {
1005
        Some(op) => Ok(repo.at_op(op)?),
1006
        None => Ok(repo),
1007
    }
fce44ae9 Andy McCall ↶ 1008
}
1009
d42369ab Andy McCall 1010
/// `oxy man`: every page into `dir`, or the top-level page on stdout.
1011
fn man(dir: Option<PathBuf>) -> Result<i32> {
1012
    use clap::CommandFactory;
1013
    let cmd = Cli::command();
1014
    match dir {
1015
        Some(dir) => {
1016
            std::fs::create_dir_all(&dir)?;
1017
            clap_mangen::generate_to(cmd, &dir)?;
1018
            let pages = std::fs::read_dir(&dir)?
1019
                .filter(|e| {
1020
                    e.as_ref()
1021
                        .is_ok_and(|e| e.path().extension().is_some_and(|x| x == "1"))
1022
                })
1023
                .count();
1024
            println!(
1025
                "{}",
1026
                ui::done(format!("Wrote {pages} man pages to {}", dir.display()))
1027
            );
1028
        }
1029
        None => clap_mangen::Man::new(cmd).render(&mut std::io::stdout())?,
1030
    }
1031
    Ok(0)
1032
}
1033
fce44ae9 Andy McCall ↶ 1034
/// Parse arguments and run; returns the process exit code.
1035
pub fn run() -> Result<i32> {
8d803563 Andy McCall ↶ 1036
    // The cloud stores (s3://, gs://, az://) for remotes kept on them.
1037
    oxy_strata::register();
fce44ae9 Andy McCall ↶ 1038
    let cli = Cli::parse();
135212de Andy McCall ↶ 1039
    ui::init(cli.plain);
98a1620a Andy McCall ↶ 1040
    AT_OP.set(cli.at_op.clone()).ok();
fce44ae9 Andy McCall ↶ 1041
    match cli.cmd {
d42369ab Andy McCall 1042
        Cmd::Completions { shell } => {
1043
            use clap::CommandFactory;
1044
            clap_complete::generate(shell, &mut Cli::command(), "oxy", &mut std::io::stdout());
1045
            Ok(0)
1046
        }
1047
        Cmd::Man { dir } => man(dir),
d069701a Andy McCall ↶ 1048
        Cmd::Init { path, bare, store } => workspace::init(path, bare, store.as_deref()),
50a046e4 Andy McCall ↶ 1049
        Cmd::Status { json } => workspace::status(json),
75167672 Andy McCall 1050
        Cmd::Prompt {
1051
            format,
1052
            glyphs,
1053
            color,
1054
        } => workspace::prompt(&format, glyphs, color.as_deref()),
1055
        Cmd::Commit {
1056
            message,
6a81dbab Andy McCall ↶ 1057
            file,
75167672 Andy McCall 1058
            depends_on,
1059
            paths,
1060
            interactive,
1061
            hunks,
6a81dbab Andy McCall ↶ 1062
        } => {
1063
            let message = match (message, file) {
1064
                (Some(m), _) => m,
1065
                (None, Some(f)) if f.as_os_str() == "-" => {
1066
                    let mut s = String::new();
1067
                    std::io::Read::read_to_string(&mut std::io::stdin(), &mut s)?;
1068
                    s
1069
                }
1070
                (None, Some(f)) => std::fs::read_to_string(&f).map_err(|e| {
1071
                    anyhow::anyhow!("reading the message from {}: {e}", f.display())
1072
                })?,
1073
                (None, None) => anyhow::bail!("a commit message is required (-m or -F)"),
1074
            };
1075
            workspace::commit(&message, &depends_on, &paths, interactive, &hunks)
1076
        }
c6aa5bd9 Andy McCall ↶ 1077
        Cmd::Cat { path, change } => workspace::cat(&path, change.as_deref()),
1078
        Cmd::Root { json } => workspace::root(json),
1079
        Cmd::Version { json } => workspace::version(json),
1080
        Cmd::Discard { paths, hunks } => workspace::discard(&paths, &hunks),
1081
        Cmd::Hunks { json } => workspace::hunks(json),
728da0f9 Andy McCall ↶ 1082
        Cmd::Squash { change, into } => workspace::squash(&change, &into),
e266b7d4 Andy McCall ↶ 1083
        Cmd::Rebase {
1084
            change,
1085
            onto,
1086
            into_working_copy,
1087
        } => workspace::rebase(&change, &onto, into_working_copy),
957fee30 Andy McCall ↶ 1088
        Cmd::Blame { path, json } => workspace::blame(&path, json),
1089
        Cmd::Bisect { cmd } => match cmd {
1090
            BisectCmd::Start => workspace::bisect_start(),
1091
            BisectCmd::Good { changes } => workspace::bisect_mark(Some(true), &changes),
1092
            BisectCmd::Bad { changes } => workspace::bisect_mark(Some(false), &changes),
1093
            BisectCmd::Skip => workspace::bisect_mark(None, &[]),
1094
            BisectCmd::Run { command } => workspace::bisect_run(&command),
c6aa5bd9 Andy McCall ↶ 1095
            BisectCmd::Status { json } => workspace::bisect_status(json),
957fee30 Andy McCall ↶ 1096
            BisectCmd::Reset => workspace::bisect_reset(),
1097
        },
75167672 Andy McCall 1098
        Cmd::Log {
47ce8b8e Andy McCall ↶ 1099
            revset,
75167672 Andy McCall 1100
            limit,
1101
            verbose,
1102
            path,
83d61e80 Andy McCall ↶ 1103
            lines,
75167672 Andy McCall 1104
            json,
47ce8b8e Andy McCall ↶ 1105
        } => workspace::log(
1106
            revset.as_deref(),
1107
            limit,
1108
            verbose,
1109
            path.as_deref(),
1110
            lines.as_deref(),
1111
            json,
1112
        ),
c6aa5bd9 Andy McCall ↶ 1113
        Cmd::Diff { change, json } => workspace::diff(change.as_deref(), json),
6a81dbab Andy McCall ↶ 1114
        Cmd::Describe {
1115
            message,
1116
            change,
1117
            json,
1118
        } => match message {
1119
            Some(m) => workspace::describe(&m, change.as_deref()),
1120
            None if change.is_some() => {
1121
                anyhow::bail!(
1122
                    "naming works on the working copy; to change a head's message pass -m"
1123
                )
1124
            }
1125
            None => workspace::describe_name(json),
1126
        },
23b217d7 Andy McCall ↶ 1127
        Cmd::Amend { message, into } => workspace::amend(message.as_deref(), into.as_deref()),
1128
        Cmd::Split { change, paths } => workspace::split(&change, &paths),
2c9ddac3 Andy McCall ↶ 1129
        Cmd::Abandon {
1130
            change,
1131
            revset,
1132
            yes,
1133
        } => workspace::abandon(change.as_deref(), revset.as_deref(), yes),
1134
        Cmd::Show {
1135
            change,
1136
            revset,
1137
            json,
1138
        } => workspace::show(change.as_deref(), revset.as_deref(), json),
1c2bd9ab Andy McCall ↶ 1139
        Cmd::Checkout {
1140
            changes,
1141
            discard,
1142
            carry,
1143
        } => workspace::checkout(&changes, discard, carry),
c6aa5bd9 Andy McCall ↶ 1144
        Cmd::Resolve { json } => workspace::resolve(json),
fce44ae9 Andy McCall ↶ 1145
        Cmd::Undo => workspace::undo(),
ba160f60 Andy McCall ↶ 1146
        Cmd::Gc { now } => workspace::gc(now),
387335ff Andy McCall ↶ 1147
        Cmd::Fsck { json } => workspace::fsck(json),
3e5772cc Andy McCall ↶ 1148
        Cmd::Doctor { offline, json } => workspace::doctor(offline, json),
252e8cb2 Andy McCall ↶ 1149
        Cmd::Checkpoint => workspace::checkpoint(),
98a1620a Andy McCall ↶ 1150
        Cmd::Op { cmd } => match cmd {
1151
            OpCmd::Log { limit, json } => workspace::op_log(limit, json),
1152
            OpCmd::Restore { op, discard } => workspace::op_restore(&op, discard),
1153
            OpCmd::Revert { op } => workspace::op_revert(&op),
1154
        },
75167672 Andy McCall 1155
        Cmd::Clone {
1156
            url,
1157
            dest,
1158
            max_blob,
1159
            sparse,
1160
            depth,
14edbaaf Andy McCall ↶ 1161
            recursive,
1162
        } => sync::clone(&url, dest, max_blob.as_deref(), &sparse, depth, recursive),
2863456a Andy McCall ↶ 1163
        Cmd::Deepen { depth, remote } => sync::deepen(&remote, depth),
7421309f Andy McCall ↶ 1164
        Cmd::Sparse { paths } => workspace::sparse(&paths),
cdb5beba Andy McCall ↶ 1165
        Cmd::Lock { path } => workspace::lock(&path),
1166
        Cmd::Unlock { path } => workspace::unlock(&path),
4e88e774 Andy McCall ↶ 1167
        Cmd::Workspace { cmd } => match cmd {
1168
            WorkspaceCmd::Add { path, changes } => workspace::workspace_add(&path, &changes),
1196b29b Andy McCall ↶ 1169
            WorkspaceCmd::List { json } => workspace::workspace_list(json),
4e88e774 Andy McCall ↶ 1170
            WorkspaceCmd::Forget { workspace } => workspace::workspace_forget(&workspace),
1171
        },
7b9809e6 Andy McCall ↶ 1172
        Cmd::Bookmark { cmd } => match cmd {
4fe7d604 Andy McCall ↶ 1173
            BookmarkCmd::Create {
1174
                name,
1175
                changes,
1176
                upto,
1177
                only,
1178
            } => workspace::bookmark_create(&name, &changes, upto, only),
06d16dc2 Andy McCall ↶ 1179
            BookmarkCmd::Set {
1180
                name,
1181
                changes,
1182
                upto,
1183
                only,
1184
            } => workspace::bookmark_set(&name, &changes, upto, only),
7b9809e6 Andy McCall ↶ 1185
            BookmarkCmd::Delete { name } => workspace::bookmark_delete(&name),
14edbaaf Andy McCall ↶ 1186
            BookmarkCmd::List { all, json } => workspace::bookmark_list(all, json),
61e3bce7 Andy McCall ↶ 1187
            BookmarkCmd::Switch {
1188
                name,
1189
                discard,
1190
                carry,
1191
            } => workspace::bookmark_switch(&name, discard, carry),
7b9809e6 Andy McCall ↶ 1192
        },
1193
        Cmd::Merge { bookmark } => workspace::merge(&bookmark),
ff1f62fe Andy McCall ↶ 1194
        Cmd::Auth { cmd } => match cmd {
1195
            AuthCmd::Login {
1196
                hub,
1197
                with_token,
1198
                ca,
1199
            } => auth::login(hub.as_deref(), with_token, ca),
1200
            AuthCmd::Status => auth::status(),
1201
            AuthCmd::Logout { hub } => auth::logout(hub.as_deref()),
1202
        },
4dee277c Andy McCall ↶ 1203
        Cmd::Submodule { cmd } => match cmd {
75167672 Andy McCall 1204
            SubmoduleCmd::Add {
1205
                url,
1206
                path,
1207
                bookmark,
1208
            } => sync::submodule_add(&url, &path, bookmark.as_deref()),
4dee277c Andy McCall ↶ 1209
            SubmoduleCmd::Update { init, paths } => sync::submodule_update(init, &paths),
c6aa5bd9 Andy McCall ↶ 1210
            SubmoduleCmd::Status { json } => sync::submodule_status(json),
4dee277c Andy McCall ↶ 1211
            SubmoduleCmd::Remove { path } => sync::submodule_remove(&path),
fc1a466a Andy McCall ↶ 1212
        },
1213
        Cmd::Receipt { cmd } => match cmd {
1214
            ReceiptCmd::List { rev, json } => receipt::list(rev.as_deref(), json),
1215
            ReceiptCmd::Show {
1216
                receipt: r,
1217
                rev,
1218
                json,
1219
            } => receipt::show(&r, rev.as_deref(), json),
1220
            ReceiptCmd::Export {
1221
                receipt: r,
1222
                file,
1223
                rev,
1224
            } => receipt::export(&r, &file, rev.as_deref()),
1225
            ReceiptCmd::Verify { file, json } => receipt::verify(&file, json),
1226
            ReceiptCmd::Import { file } => receipt::import(&file),
4dee277c Andy McCall ↶ 1227
        },
132b884b Andy McCall ↶ 1228
        Cmd::Tag { cmd } => match cmd {
75167672 Andy McCall 1229
            TagCmd::Create {
1230
                name,
1231
                changes,
1232
                message,
1233
            } => workspace::tag_create(&name, &changes, &message),
1196b29b Andy McCall ↶ 1234
            TagCmd::List { json } => workspace::tag_list(json),
132b884b Andy McCall ↶ 1235
        },
fce44ae9 Andy McCall ↶ 1236
        Cmd::Remote { cmd } => match cmd {
1237
            RemoteCmd::Add { name, url } => sync::remote_add(&name, &url),
1238
            RemoteCmd::Remove { name } => sync::remote_remove(&name),
c6aa5bd9 Andy McCall ↶ 1239
            RemoteCmd::List { json } => sync::remote_list(json),
fce44ae9 Andy McCall ↶ 1240
        },
c6aa5bd9 Andy McCall ↶ 1241
        Cmd::Fetch { remote, json } => sync::fetch(remote.as_deref(), json),
1242
        Cmd::Pull { remote, json } => sync::pull(remote.as_deref(), json),
75167672 Andy McCall 1243
        Cmd::Push {
1244
            remote,
1245
            force,
1246
            bookmark,
f8c69576 Andy McCall ↶ 1247
            delete,
75167672 Andy McCall 1248
            json,
f8c69576 Andy McCall ↶ 1249
        } => match delete {
1250
            Some(name) => sync::push_delete(remote.as_deref(), &name, json),
1251
            None => sync::push(remote.as_deref(), force, bookmark.as_deref(), json),
1252
        },
75167672 Andy McCall 1253
        Cmd::Serve {
1254
            root,
1255
            bind,
1256
            tokens,
1257
            tls_cert,
1258
            tls_key,
1259
        } => sync::serve(root, &bind, tokens, tls_cert.zip(tls_key)),
fce44ae9 Andy McCall ↶ 1260
        Cmd::Identity { cmd } => match cmd {
75167672 Andy McCall 1261
            IdentityCmd::Create {
1262
                name,
1263
                email,
1264
                local,
1265
                expires,
1266
            } => identity::create(name, email, local, expires),
fce44ae9 Andy McCall ↶ 1267
            IdentityCmd::Show => identity::show(),
83e0677b Andy McCall ↶ 1268
            IdentityCmd::Export { path } => identity::export(path),
119bbf50 Andy McCall ↶ 1269
            IdentityCmd::SignChallenge { challenge, json } => {
1270
                identity::sign_challenge(&challenge, json)
1271
            }
28fc23d7 Andy McCall ↶ 1272
            IdentityCmd::Rotate => identity::rotate(),
1273
            IdentityCmd::Renew { expires } => identity::renew(expires),
1274
            IdentityCmd::Revoke { key, reason } => identity::revoke(key.as_deref(), &reason),
1275
            IdentityCmd::Delegate { cmd } => match cmd {
7ba155f2 Andy McCall ↶ 1276
                DelegateCmd::Add {
1277
                    identity_file,
1278
                    scope,
1279
                    expires,
1280
                } => identity::delegate_add(&identity_file, &scope, expires.as_deref()),
28fc23d7 Andy McCall ↶ 1281
                DelegateCmd::Remove { key } => identity::delegate_remove(&key),
1282
                DelegateCmd::List => identity::delegate_list(),
1283
            },
83e0677b Andy McCall ↶ 1284
        },
75167672 Andy McCall 1285
        Cmd::Git {
1286
            cmd: GitCmd::Export { git_dir, branch },
1287
        } => sync::git_export(&git_dir, branch.as_deref()),
1288
        Cmd::Git {
1289
            cmd: GitCmd::Fetch { url, branch },
1290
        } => sync::git_fetch(&url, &branch),
1291
        Cmd::Git {
1292
            cmd: GitCmd::Push { url, branch },
1293
        } => sync::git_push(&url, &branch),
1294
        Cmd::Git {
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
}