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