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