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