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