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