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