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