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