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