OXYGENHUB
# 2dd42fa169c8 oxygen / src / cli / mod.rs
37.1 KiB · Rust · last changed Delete bookmarks on a remote: oxy push REMOTE --delete NAME 1 month ago source blame history raw
fce44ae9 Andy McCall ↶ 1
//! Command-line definitions and dispatch.
2
3
mod format;
75167672 Andy McCall 4
mod identity;
c6aa5bd9 Andy McCall ↶ 5
mod json;
d82e4409 Andy McCall ↶ 6
mod proposal;
fce44ae9 Andy McCall ↶ 7
mod sync;
135212de Andy McCall ↶ 8
pub mod ui;
fce44ae9 Andy McCall ↶ 9
mod workspace;
10
11
use anyhow::{Context, Result};
12
use clap::{Parser, Subcommand};
13
use oxy_core::repo::Repo;
14
use std::path::PathBuf;
15
16
#[derive(Parser)]
75167672 Andy McCall 17
#[command(
18
    name = "oxy",
19
    version,
20
    about = "Oxygen: breathing fresh air into version control"
21
)]
fce44ae9 Andy McCall ↶ 22
struct Cli {
135212de Andy McCall ↶ 23
    /// Plain output: no colour, no spinner (also implied by NO_COLOR or a non-terminal)
24
    #[arg(long, global = true)]
25
    plain: bool,
fce44ae9 Andy McCall ↶ 26
    #[command(subcommand)]
27
    cmd: Cmd,
28
}
29
30
#[derive(Subcommand)]
31
enum Cmd {
32
    /// Create a repository in PATH (default: current directory)
e02bf0cd Andy McCall ↶ 33
    Init {
d42369ab Andy McCall 34
        /// Directory to create the repository in (default: the current directory)
e02bf0cd Andy McCall ↶ 35
        path: Option<PathBuf>,
36
        /// No working copy: an object store and references only, for hosting
37
        #[arg(long)]
38
        bare: bool,
39
    },
fce44ae9 Andy McCall ↶ 40
    /// Clone a repository from a local path or an http(s) URL
b3c5a59a Andy McCall ↶ 41
    Clone {
d42369ab Andy McCall 42
        /// Local path or http(s) URL of the repository
b3c5a59a Andy McCall ↶ 43
        url: String,
d42369ab Andy McCall 44
        /// Directory to clone into (default: the last part of the URL)
b3c5a59a Andy McCall ↶ 45
        dest: Option<PathBuf>,
46
        /// Leave blobs larger than this (e.g. 1M) to be fetched on first read
47
        #[arg(long)]
48
        max_blob: Option<String>,
7421309f Andy McCall ↶ 49
        /// Materialize only these paths (repeatable); implies lazy blobs
50
        #[arg(long = "sparse")]
51
        sparse: Vec<String>,
2863456a Andy McCall ↶ 52
        /// Shallow clone: fetch only this many levels of history below the heads
53
        #[arg(long)]
54
        depth: Option<u32>,
b3c5a59a Andy McCall ↶ 55
    },
2863456a Andy McCall ↶ 56
    /// Fetch more history below a shallow clone's boundary
57
    Deepen {
d42369ab Andy McCall 58
        /// Levels of history to add below the boundary
2863456a Andy McCall ↶ 59
        #[arg(default_value_t = 10)]
60
        depth: u32,
d42369ab Andy McCall 61
        /// Remote to fetch the history from
2863456a Andy McCall ↶ 62
        #[arg(long, default_value = "origin")]
63
        remote: String,
64
    },
7421309f Andy McCall ↶ 65
    /// Show or set the sparse filter (paths to materialize); re-checks out the bookmark
d42369ab Andy McCall 66
    Sparse {
67
        /// Paths to materialize; none prints the current filter
68
        paths: Vec<String>,
69
    },
fce44ae9 Andy McCall ↶ 70
    /// Show the working copy: changed paths and conflicts
50a046e4 Andy McCall ↶ 71
    Status {
72
        /// Machine-readable output: paths, and every conflict with its kind and contributing changes
73
        #[arg(long)]
74
        json: bool,
75
    },
135212de Andy McCall ↶ 76
    /// One-line summary for shell prompts; fast and records nothing
77
    Prompt {
694805cc Andy McCall ↶ 78
        /// 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 ↶ 79
        #[arg(long, default_value = oxy_core::repo::DEFAULT_PROMPT_FORMAT)]
80
        format: String,
694805cc Andy McCall ↶ 81
        /// Glyph format (%i %b %c %s%U%O) instead of the plain default
82
        #[arg(long)]
83
        glyphs: bool,
84
        /// Colour by state (cyan clean, yellow dirty, red conflicted): raw escapes, or guarded for a bash or zsh PS1
85
        #[arg(long, value_parser = ["raw", "bash", "zsh"])]
86
        color: Option<String>,
135212de Andy McCall ↶ 87
    },
fce44ae9 Andy McCall ↶ 88
    /// Record the working copy as a change on the current bookmark
89
    Commit {
d42369ab Andy McCall 90
        /// The change's message: a subject line, then optionally a blank line and a body
fce44ae9 Andy McCall ↶ 91
        #[arg(short, long)]
92
        message: String,
93
        /// Extra explicit dependencies (ChangeId prefix, #hash prefix)
94
        #[arg(long = "depends-on")]
95
        depends_on: Vec<String>,
957fee30 Andy McCall ↶ 96
        /// Commit only these paths; the rest stays as uncommitted work
97
        paths: Vec<String>,
98
        /// Choose hunks one by one
99
        #[arg(short, long)]
100
        interactive: bool,
c6aa5bd9 Andy McCall ↶ 101
        /// Commit these hunks (as `oxy hunks` numbers them), comma separated
102
        #[arg(long, value_delimiter = ',')]
103
        hunks: Vec<usize>,
fce44ae9 Andy McCall ↶ 104
    },
728da0f9 Andy McCall ↶ 105
    /// Fold CHANGE into one of its dependencies (keeps that change's id)
106
    Squash {
d42369ab Andy McCall 107
        /// The change to fold (ChangeId prefix, #hash prefix)
728da0f9 Andy McCall ↶ 108
        change: String,
d42369ab Andy McCall 109
        /// The dependency that absorbs it
728da0f9 Andy McCall ↶ 110
        #[arg(long)]
111
        into: String,
112
    },
113
    /// Re-express CHANGE against another base state
114
    Rebase {
d42369ab Andy McCall 115
        /// The change to re-express (ChangeId prefix, #hash prefix)
728da0f9 Andy McCall ↶ 116
        change: String,
117
        /// The changes, bookmark or tag whose state becomes the new base
118
        #[arg(long, required = true, num_args = 1..)]
119
        onto: Vec<String>,
120
    },
957fee30 Andy McCall ↶ 121
    /// Show which change introduced each line of a file
122
    Blame {
d42369ab Andy McCall 123
        /// File to annotate, relative to the repository root
957fee30 Andy McCall ↶ 124
        path: String,
d42369ab Andy McCall 125
        /// Machine-readable output: one JSON document on stdout
957fee30 Andy McCall ↶ 126
        #[arg(long)]
127
        json: bool,
128
    },
129
    /// Find the change that introduced a regression
130
    Bisect {
131
        #[command(subcommand)]
132
        cmd: BisectCmd,
133
    },
fce44ae9 Andy McCall ↶ 134
    /// List changes reachable from the bookmark and the working copy
94084087 Andy McCall ↶ 135
    Log {
136
        /// Show at most this many changes
137
        #[arg(short = 'n', long)]
138
        limit: Option<usize>,
139
        /// Show full messages, dependencies, and signatures
140
        #[arg(short, long)]
141
        verbose: bool,
c6aa5bd9 Andy McCall ↶ 142
        /// Only changes touching this path (renames followed)
143
        #[arg(long)]
144
        path: Option<String>,
d42369ab Andy McCall 145
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 146
        #[arg(long)]
147
        json: bool,
94084087 Andy McCall ↶ 148
    },
fce44ae9 Andy McCall ↶ 149
    /// Show what the working copy changes against its base
c6aa5bd9 Andy McCall ↶ 150
    Diff {
151
        /// A change instead of the working copy
152
        change: Option<String>,
d42369ab Andy McCall 153
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 154
        #[arg(long)]
155
        json: bool,
156
    },
157
    /// Print a file as it is in a state (default: the working copy's base)
158
    Cat {
d42369ab Andy McCall 159
        /// File to print, relative to the repository root
c6aa5bd9 Andy McCall ↶ 160
        path: String,
161
        /// A change, bookmark, or tag
162
        #[arg(short = 'r', long)]
163
        change: Option<String>,
164
    },
165
    /// Print the repository root, workspace, and bookmark
166
    Root {
d42369ab Andy McCall 167
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 168
        #[arg(long)]
169
        json: bool,
170
    },
171
    /// Print the version of oxy, its repository format, and protocol
172
    Version {
d42369ab Andy McCall 173
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 174
        #[arg(long)]
175
        json: bool,
176
    },
177
    /// Restore paths to the working copy's base, or undo chosen hunks
178
    Discard {
d42369ab Andy McCall 179
        /// Paths to restore; none with --hunks, or everything with neither
c6aa5bd9 Andy McCall ↶ 180
        paths: Vec<String>,
181
        /// Hunk indices as `oxy hunks` numbers them, comma separated
182
        #[arg(long, value_delimiter = ',')]
183
        hunks: Vec<usize>,
184
    },
185
    /// List the working copy's hunks, numbered as commit --hunks expects
186
    Hunks {
d42369ab Andy McCall 187
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 188
        #[arg(long)]
189
        json: bool,
190
    },
614541c3 Andy McCall ↶ 191
    /// Change the message of a head (default: the head the working copy sits on)
192
    Describe {
d42369ab Andy McCall 193
        /// The new message
614541c3 Andy McCall ↶ 194
        #[arg(short, long)]
195
        message: String,
d42369ab Andy McCall 196
        /// The head to describe (default: the one the working copy sits on)
614541c3 Andy McCall ↶ 197
        change: Option<String>,
198
    },
23b217d7 Andy McCall ↶ 199
    /// Fold the working copy into the head it sits on, or into CHANGE with --into
614541c3 Andy McCall ↶ 200
    Amend {
d42369ab Andy McCall 201
        /// Replace the message too
614541c3 Andy McCall ↶ 202
        #[arg(short, long)]
203
        message: Option<String>,
23b217d7 Andy McCall ↶ 204
        /// Amend an older change; the edits must touch only lines it already knows
205
        #[arg(long)]
206
        into: Option<String>,
614541c3 Andy McCall ↶ 207
    },
23b217d7 Andy McCall ↶ 208
    /// Split a head: the named paths become a separate first change
d42369ab Andy McCall 209
    Split {
210
        /// The head to split
211
        change: String,
212
        /// Paths whose edits become the first change
213
        paths: Vec<String>,
214
    },
614541c3 Andy McCall ↶ 215
    /// Drop a head from the bookmark; its content stays on disk as uncommitted work
d42369ab Andy McCall 216
    Abandon {
217
        /// The head to drop (ChangeId prefix, #hash prefix)
218
        change: String,
219
    },
fce44ae9 Andy McCall ↶ 220
    /// Show one change (ChangeId prefix, #hash prefix, or @)
c6aa5bd9 Andy McCall ↶ 221
    Show {
d42369ab Andy McCall 222
        /// ChangeId prefix, #hash prefix, or @ for the working copy
c6aa5bd9 Andy McCall ↶ 223
        change: String,
d42369ab Andy McCall 224
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 225
        #[arg(long)]
226
        json: bool,
227
    },
fce44ae9 Andy McCall ↶ 228
    /// Move the working copy to the state formed by CHANGE... (default: the bookmark heads)
229
    Checkout {
d42369ab Andy McCall 230
        /// Changes whose state to check out (default: the bookmark heads)
fce44ae9 Andy McCall ↶ 231
        changes: Vec<String>,
232
        /// Throw away uncommitted working-copy changes
233
        #[arg(long)]
234
        discard: bool,
235
    },
236
    /// Report which conflicts of the working copy's base are resolved by the current files
c6aa5bd9 Andy McCall ↶ 237
    Resolve {
d42369ab Andy McCall 238
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 239
        #[arg(long)]
240
        json: bool,
241
    },
fce44ae9 Andy McCall ↶ 242
    /// Undo the last operation
243
    Undo,
252e8cb2 Andy McCall ↶ 244
    /// Write a checkpoint of the current bookmark's state now
245
    Checkpoint,
d42369ab Andy McCall 246
    /// Print a shell completion script: `oxy completions bash > ~/.local/share/bash-completion/completions/oxy`
247
    Completions {
248
        /// bash, zsh, fish, elvish or powershell
249
        shell: clap_complete::Shell,
250
    },
251
    /// Write man pages (oxy.1 and one per command) into DIR, or print oxy.1
252
    Man {
253
        /// Directory to write every page into, e.g. ~/.local/share/man/man1
254
        #[arg(long)]
255
        dir: Option<PathBuf>,
256
    },
3e5772cc Andy McCall ↶ 257
    /// Check the identity, configuration and remotes, and say what to do about any problem
258
    Doctor {
259
        /// Do not contact the remotes
260
        #[arg(long)]
261
        offline: bool,
d42369ab Andy McCall 262
        /// Machine-readable output: one JSON document on stdout
3e5772cc Andy McCall ↶ 263
        #[arg(long)]
264
        json: bool,
265
    },
387335ff Andy McCall ↶ 266
    /// Check the repository's integrity: objects, operation log, references, signatures, checkpoints
267
    Fsck {
d42369ab Andy McCall 268
        /// Machine-readable output: one JSON document on stdout
387335ff Andy McCall ↶ 269
        #[arg(long)]
270
        json: bool,
271
    },
ba160f60 Andy McCall ↶ 272
    /// Pack loose objects and prune unreachable ones older than the grace period
273
    Gc {
274
        /// Ignore the grace period (core.gc-grace) and prune immediately
275
        #[arg(long)]
276
        now: bool,
277
    },
fce44ae9 Andy McCall ↶ 278
    /// List operations
279
    #[command(name = "op")]
280
    Op {
281
        #[command(subcommand)]
282
        cmd: OpCmd,
283
    },
cdb5beba Andy McCall ↶ 284
    /// Take the advisory local lock on a lockable file, making it writable
d42369ab Andy McCall 285
    Lock {
286
        /// The lockable file
287
        path: String,
288
    },
cdb5beba Andy McCall ↶ 289
    /// Release the local lock and make the file read-only again
d42369ab Andy McCall 290
    Unlock {
291
        /// The locked file
292
        path: String,
293
    },
4e88e774 Andy McCall ↶ 294
    /// Workspaces: extra checkout directories sharing this repository
295
    Workspace {
296
        #[command(subcommand)]
297
        cmd: WorkspaceCmd,
298
    },
7b9809e6 Andy McCall ↶ 299
    /// Bookmarks: named states; each workspace works on one
300
    Bookmark {
301
        #[command(subcommand)]
302
        cmd: BookmarkCmd,
303
    },
304
    /// Union another bookmark's heads into the current one (no merge change)
d42369ab Andy McCall 305
    Merge {
306
        /// The bookmark whose heads to add
307
        bookmark: String,
308
    },
4dee277c Andy McCall ↶ 309
    /// Subrepositories: nested repositories pinned to a state
310
    Submodule {
311
        #[command(subcommand)]
312
        cmd: SubmoduleCmd,
313
    },
132b884b Andy McCall ↶ 314
    /// Tags: immutable named states
315
    Tag {
316
        #[command(subcommand)]
317
        cmd: TagCmd,
318
    },
fce44ae9 Andy McCall ↶ 319
    /// Manage remotes
320
    Remote {
321
        #[command(subcommand)]
322
        cmd: RemoteCmd,
323
    },
324
    /// Fetch every bookmark of a remote into its tracking references
c6aa5bd9 Andy McCall ↶ 325
    Fetch {
d42369ab Andy McCall 326
        /// Remote name (default: origin)
c6aa5bd9 Andy McCall ↶ 327
        remote: Option<String>,
d42369ab Andy McCall 328
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 329
        #[arg(long)]
330
        json: bool,
331
    },
fce44ae9 Andy McCall ↶ 332
    /// Fetch, then union the remote bookmark into the local one (no merge change)
c6aa5bd9 Andy McCall ↶ 333
    Pull {
d42369ab Andy McCall 334
        /// Remote name (default: origin)
c6aa5bd9 Andy McCall ↶ 335
        remote: Option<String>,
d42369ab Andy McCall 336
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 337
        #[arg(long)]
338
        json: bool,
339
    },
fce44ae9 Andy McCall ↶ 340
    /// Push the current bookmark to a remote
341
    Push {
d42369ab Andy McCall 342
        /// Remote name (default: origin)
fce44ae9 Andy McCall ↶ 343
        remote: Option<String>,
344
        /// Allow dropping heads the remote has
345
        #[arg(long)]
346
        force: bool,
7b9809e6 Andy McCall ↶ 347
        /// Push this bookmark instead of the workspace's current one
348
        #[arg(short = 'b', long)]
349
        bookmark: Option<String>,
f8c69576 Andy McCall ↶ 350
        /// Delete this bookmark on the remote (never its default bookmark);
351
        /// the local bookmark is kept
352
        #[arg(long, value_name = "NAME", conflicts_with_all = ["bookmark", "force"])]
353
        delete: Option<String>,
d42369ab Andy McCall 354
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 355
        #[arg(long)]
356
        json: bool,
fce44ae9 Andy McCall ↶ 357
    },
2b5ee371 Andy McCall ↶ 358
    /// Serve repositories under ROOT over HTTPS (with --tls-cert/--tls-key) or plain HTTP
fce44ae9 Andy McCall ↶ 359
    Serve {
360
        /// Directory with one repository per subdirectory
361
        #[arg(long, default_value = ".")]
362
        root: PathBuf,
d42369ab Andy McCall 363
        /// Address and port to listen on
fce44ae9 Andy McCall ↶ 364
        #[arg(long, default_value = "127.0.0.1:8890")]
365
        bind: String,
366
        /// Bearer token allowed to push (repeatable); none means open
367
        #[arg(long = "token")]
368
        tokens: Vec<String>,
2b5ee371 Andy McCall ↶ 369
        /// PEM certificate chain; enables HTTPS together with --tls-key
370
        #[arg(long, requires = "tls_key")]
371
        tls_cert: Option<PathBuf>,
372
        /// PEM private key
373
        #[arg(long, requires = "tls_cert")]
374
        tls_key: Option<PathBuf>,
fce44ae9 Andy McCall ↶ 375
    },
376
    /// Manage the signing identity
377
    Identity {
378
        #[command(subcommand)]
379
        cmd: IdentityCmd,
380
    },
05e71ed6 Andy McCall ↶ 381
    /// Seal changes with your key: named ones, or every change on the current bookmark you can authenticate but have not
382
    Seal {
d42369ab Andy McCall 383
        /// Changes to seal (default: every change on the bookmark you can authenticate and have not sealed)
05e71ed6 Andy McCall ↶ 384
        changes: Vec<String>,
d82e4409 Andy McCall ↶ 385
        /// Seal every change of a hub proposal and push the seal (your approval)
386
        #[arg(long, conflicts_with = "changes")]
387
        proposal: Option<String>,
d42369ab Andy McCall 388
        /// Machine-readable output: one JSON document on stdout
05e71ed6 Andy McCall ↶ 389
        #[arg(long)]
390
        json: bool,
391
    },
d82e4409 Andy McCall ↶ 392
    /// Hub proposals: show one, or land it from this client
393
    Proposal {
394
        #[command(subcommand)]
395
        cmd: ProposalCmd,
396
    },
fce44ae9 Andy McCall ↶ 397
    /// Verify the signatures on a change (default: every change in the log)
c6aa5bd9 Andy McCall ↶ 398
    Verify {
d42369ab Andy McCall 399
        /// The change to verify (default: every change in the log)
c6aa5bd9 Andy McCall ↶ 400
        change: Option<String>,
d42369ab Andy McCall 401
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 402
        #[arg(long)]
403
        json: bool,
404
    },
79ab8528 Andy McCall ↶ 405
    /// Git interoperability
406
    Git {
407
        #[command(subcommand)]
408
        cmd: GitCmd,
409
    },
83e0677b Andy McCall ↶ 410
    /// Manage the trust policy (who may update which bookmarks)
411
    Policy {
412
        #[command(subcommand)]
413
        cmd: PolicyCmd,
414
    },
7421309f Andy McCall ↶ 415
    /// Set a configuration key (author.*, core.sign, core.op-retention, core.gc-grace, core.checkpoint-interval, filter.max-blob, filter.paths, workspace.bookmark, remote.<name>.url|token|ca)
fce44ae9 Andy McCall ↶ 416
    Config {
d42369ab Andy McCall 417
        /// The key, such as author.name or remote.origin.token
fce44ae9 Andy McCall ↶ 418
        key: String,
d42369ab Andy McCall 419
        /// The value to set
fce44ae9 Andy McCall ↶ 420
        value: String,
421
        /// Write to the user file (~/.config/oxy/config.toml) instead of this repository
422
        #[arg(long)]
423
        user: bool,
424
    },
425
}
426
427
#[derive(Subcommand)]
428
enum OpCmd {
d42369ab Andy McCall 429
    /// List operations, newest first
c6aa5bd9 Andy McCall ↶ 430
    Log {
d42369ab Andy McCall 431
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 432
        #[arg(long)]
433
        json: bool,
434
    },
fce44ae9 Andy McCall ↶ 435
}
436
437
#[derive(Subcommand)]
4e88e774 Andy McCall ↶ 438
enum WorkspaceCmd {
439
    /// Create a workspace at PATH checked out on CHANGE... (default: the bookmark heads)
d42369ab Andy McCall 440
    Add {
441
        /// Directory for the new workspace (must be empty or absent)
442
        path: PathBuf,
443
        /// Changes whose state to check out there
444
        changes: Vec<String>,
445
    },
446
    /// List workspaces and their working-copy changes
1196b29b Andy McCall ↶ 447
    List {
d42369ab Andy McCall 448
        /// Machine-readable output: one JSON document on stdout
1196b29b Andy McCall ↶ 449
        #[arg(long)]
450
        json: bool,
451
    },
4e88e774 Andy McCall ↶ 452
    /// Stop tracking a workspace (by id prefix or path); its files stay
d42369ab Andy McCall 453
    Forget {
454
        /// Workspace id prefix or path
455
        workspace: String,
456
    },
4e88e774 Andy McCall ↶ 457
}
458
459
#[derive(Subcommand)]
957fee30 Andy McCall ↶ 460
enum BisectCmd {
461
    /// Begin; remembers where the working copy was
462
    Start,
463
    /// Mark CHANGE... (or the state under test) as good
d42369ab Andy McCall 464
    Good {
465
        /// Changes known to be good (default: the state under test)
466
        changes: Vec<String>,
467
    },
957fee30 Andy McCall ↶ 468
    /// Mark CHANGE... (or the state under test) as bad
d42369ab Andy McCall 469
    Bad {
470
        /// Changes known to be bad (default: the state under test)
471
        changes: Vec<String>,
472
    },
957fee30 Andy McCall ↶ 473
    /// The state under test cannot be tested; try another
474
    Skip,
475
    /// Run a command for each step: exit 0 good, 125 skip, else bad
476
    Run {
d42369ab Andy McCall 477
        /// Command and arguments to run at each step
957fee30 Andy McCall ↶ 478
        #[arg(required = true, trailing_var_arg = true)]
479
        command: Vec<String>,
480
    },
481
    /// Where the search stands
c6aa5bd9 Andy McCall ↶ 482
    Status {
d42369ab Andy McCall 483
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 484
        #[arg(long)]
485
        json: bool,
486
    },
957fee30 Andy McCall ↶ 487
    /// Restore the working copy and forget the search
488
    Reset,
489
}
490
491
#[derive(Subcommand)]
7b9809e6 Andy McCall ↶ 492
enum BookmarkCmd {
493
    /// Create a bookmark at CHANGE... (default: the working copy's base)
d42369ab Andy McCall 494
    Create {
495
        /// Name of the new bookmark
496
        name: String,
497
        /// Its heads (default: the working copy's base)
498
        changes: Vec<String>,
499
    },
7b9809e6 Andy McCall ↶ 500
    /// Point an existing bookmark at CHANGE...
d42369ab Andy McCall 501
    Set {
502
        /// The bookmark to move
503
        name: String,
504
        /// Its new heads
505
        changes: Vec<String>,
506
    },
7b9809e6 Andy McCall ↶ 507
    /// Remove a bookmark; its changes stay
d42369ab Andy McCall 508
    Delete {
509
        /// The bookmark to remove
510
        name: String,
511
    },
7b9809e6 Andy McCall ↶ 512
    /// List bookmarks with their heads and difference from origin
c6aa5bd9 Andy McCall ↶ 513
    List {
d42369ab Andy McCall 514
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 515
        #[arg(long)]
516
        json: bool,
517
    },
7b9809e6 Andy McCall ↶ 518
    /// Make NAME this workspace's bookmark and check it out
519
    Switch {
d42369ab Andy McCall 520
        /// The bookmark to work on
7b9809e6 Andy McCall ↶ 521
        name: String,
522
        /// Throw away uncommitted working-copy changes
523
        #[arg(long)]
524
        discard: bool,
525
    },
526
}
527
528
#[derive(Subcommand)]
4dee277c Andy McCall ↶ 529
enum SubmoduleCmd {
530
    /// Clone URL (Oxygen or Git) into PATH and register it in .oxymodules
531
    Add {
d42369ab Andy McCall 532
        /// URL or path of the Oxygen or Git repository
4dee277c Andy McCall ↶ 533
        url: String,
d42369ab Andy McCall 534
        /// Where to put it, relative to the repository root
4dee277c Andy McCall ↶ 535
        path: String,
536
        /// Bookmark (Oxygen) or branch (Git) to check out and track
537
        #[arg(long)]
538
        bookmark: Option<String>,
539
    },
540
    /// Bring nested repositories to their pins
541
    Update {
542
        /// Clone nested repositories that are absent
543
        #[arg(long)]
544
        init: bool,
d42369ab Andy McCall 545
        /// Subrepos to update (default: all)
4dee277c Andy McCall ↶ 546
        paths: Vec<String>,
547
    },
548
    /// List subrepos with their pins and on-disk state
c6aa5bd9 Andy McCall ↶ 549
    Status {
d42369ab Andy McCall 550
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 551
        #[arg(long)]
552
        json: bool,
553
    },
4dee277c Andy McCall ↶ 554
    /// Unregister PATH; the directory stays, the node goes with the next commit
d42369ab Andy McCall 555
    Remove {
556
        /// The subrepo to unregister
557
        path: String,
558
    },
4dee277c Andy McCall ↶ 559
}
560
561
#[derive(Subcommand)]
132b884b Andy McCall ↶ 562
enum TagCmd {
563
    /// Tag the state of CHANGE... (default: the bookmark heads)
564
    Create {
d42369ab Andy McCall 565
        /// Name of the tag; tags never move
132b884b Andy McCall ↶ 566
        name: String,
d42369ab Andy McCall 567
        /// Changes whose state to tag (default: the bookmark heads)
132b884b Andy McCall ↶ 568
        changes: Vec<String>,
d42369ab Andy McCall 569
        /// A message recorded with the tag
132b884b Andy McCall ↶ 570
        #[arg(short, long, default_value = "")]
571
        message: String,
572
    },
d42369ab Andy McCall 573
    /// List tags and the states they name
1196b29b Andy McCall ↶ 574
    List {
d42369ab Andy McCall 575
        /// Machine-readable output: one JSON document on stdout
1196b29b Andy McCall ↶ 576
        #[arg(long)]
577
        json: bool,
578
    },
132b884b Andy McCall ↶ 579
}
580
581
#[derive(Subcommand)]
fce44ae9 Andy McCall ↶ 582
enum RemoteCmd {
d42369ab Andy McCall 583
    /// Add a remote
75167672 Andy McCall 584
    Add {
d42369ab Andy McCall 585
        /// Name to refer to the remote by, such as origin
75167672 Andy McCall 586
        name: String,
d42369ab Andy McCall 587
        /// Local path or http(s) URL of the repository
75167672 Andy McCall 588
        url: String,
589
    },
d42369ab Andy McCall 590
    /// Remove a remote
75167672 Andy McCall 591
    Remove {
d42369ab Andy McCall 592
        /// The remote to remove
75167672 Andy McCall 593
        name: String,
594
    },
d42369ab Andy McCall 595
    /// List remotes and their URLs
c6aa5bd9 Andy McCall ↶ 596
    List {
d42369ab Andy McCall 597
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 598
        #[arg(long)]
599
        json: bool,
600
    },
fce44ae9 Andy McCall ↶ 601
}
602
603
#[derive(Subcommand)]
d82e4409 Andy McCall ↶ 604
enum ProposalCmd {
605
    /// Show a proposal by its hub URL
606
    Show {
d42369ab Andy McCall 607
        /// The proposal's URL on the hub
d82e4409 Andy McCall ↶ 608
        url: String,
d42369ab Andy McCall 609
        /// Machine-readable output: one JSON document on stdout
d82e4409 Andy McCall ↶ 610
        #[arg(long)]
611
        json: bool,
612
    },
613
    /// Fetch the proposal's changes, set the target bookmark to the projected state, and push with your key
614
    Land {
d42369ab Andy McCall 615
        /// The proposal's URL on the hub
d82e4409 Andy McCall ↶ 616
        url: String,
617
        /// Land even when the hub reports blockers
618
        #[arg(long)]
619
        force: bool,
620
    },
621
}
622
623
#[derive(Subcommand)]
fce44ae9 Andy McCall ↶ 624
enum IdentityCmd {
625
    /// Generate a composite Ed25519 + ML-DSA-65 key pair and make it your author identity
626
    Create {
d42369ab Andy McCall 627
        /// Your name (default: author.name)
fce44ae9 Andy McCall ↶ 628
        #[arg(long)]
629
        name: Option<String>,
d42369ab Andy McCall 630
        /// Your email (default: author.email)
fce44ae9 Andy McCall ↶ 631
        #[arg(long)]
632
        email: Option<String>,
633
        /// Record the author in this repository only, not in the user config
634
        #[arg(long)]
635
        local: bool,
28fc23d7 Andy McCall ↶ 636
        /// Expire the identity this many days from now
637
        #[arg(long)]
638
        expires: Option<u64>,
fce44ae9 Andy McCall ↶ 639
    },
640
    /// Show the configured identity
641
    Show,
83e0677b Andy McCall ↶ 642
    /// Write your identity object to a file, to hand to a policy holder
d42369ab Andy McCall 643
    Export {
e3d071ce Andy McCall ↶ 644
        /// File to write (default: <key>.identity in the current directory)
d42369ab Andy McCall 645
        path: Option<PathBuf>,
646
    },
7aa2dc93 Andy McCall ↶ 647
    /// Sign a host's challenge (hex, at least 16 bytes) to prove you hold your key; prints the signature as hex
648
    SignChallenge {
d42369ab Andy McCall 649
        /// The host's challenge, as hex
7aa2dc93 Andy McCall ↶ 650
        challenge: String,
d42369ab Andy McCall 651
        /// Machine-readable output: one JSON document on stdout
7aa2dc93 Andy McCall ↶ 652
        #[arg(long)]
653
        json: bool,
654
    },
28fc23d7 Andy McCall ↶ 655
    /// Move to a fresh key pair; the policy follows if it names your key
656
    Rotate,
657
    /// Re-issue your identity with a new expiry (in days from now; 0 = never)
658
    Renew {
d42369ab Andy McCall 659
        /// Days from now until it expires; 0 for never
28fc23d7 Andy McCall ↶ 660
        #[arg(long)]
661
        expires: u64,
662
    },
663
    /// Revoke a key: yours by default, or any key if you hold a policy root
664
    Revoke {
665
        /// KeyId prefix (default: your own key)
666
        key: Option<String>,
d42369ab Andy McCall 667
        /// Why, recorded in the revocation
28fc23d7 Andy McCall ↶ 668
        #[arg(long, default_value = "")]
669
        reason: String,
670
    },
671
    /// Keys allowed to sign or seal on your behalf
672
    Delegate {
673
        #[command(subcommand)]
674
        cmd: DelegateCmd,
675
    },
676
}
677
678
#[derive(Subcommand)]
679
enum DelegateCmd {
680
    /// Add a delegate from an exported identity file
d42369ab Andy McCall 681
    Add {
682
        /// The delegate's exported identity file
683
        identity_file: PathBuf,
684
    },
28fc23d7 Andy McCall ↶ 685
    /// Remove a delegate by KeyId prefix
d42369ab Andy McCall 686
    Remove {
687
        /// KeyId prefix of the delegate
688
        key: String,
689
    },
28fc23d7 Andy McCall ↶ 690
    /// List delegates
691
    List,
fce44ae9 Andy McCall ↶ 692
}
693
83e0677b Andy McCall ↶ 694
#[derive(Subcommand)]
79ab8528 Andy McCall ↶ 695
enum GitCmd {
696
    /// Export the current bookmark to a Git repository (created bare if absent)
30ea9c1e Andy McCall ↶ 697
    Export {
d42369ab Andy McCall 698
        /// Git repository to write to (created bare if absent)
30ea9c1e Andy McCall ↶ 699
        git_dir: PathBuf,
700
        /// Git branch to write (default: the bookmark name)
701
        #[arg(long)]
702
        branch: Option<String>,
703
    },
704
    /// Fetch a branch from a Git remote (path or URL) into the current bookmark
705
    Fetch {
d42369ab Andy McCall 706
        /// Git remote: a path or URL
30ea9c1e Andy McCall ↶ 707
        url: String,
d42369ab Andy McCall 708
        /// Branch to fetch
30ea9c1e Andy McCall ↶ 709
        #[arg(long, default_value = "main")]
710
        branch: String,
711
    },
712
    /// Push the current bookmark to a branch of a Git remote (fetch first)
713
    Push {
d42369ab Andy McCall 714
        /// Git remote: a path or URL
30ea9c1e Andy McCall ↶ 715
        url: String,
d42369ab Andy McCall 716
        /// Branch to push to
30ea9c1e Andy McCall ↶ 717
        #[arg(long, default_value = "main")]
718
        branch: String,
719
    },
62794ecc Andy McCall ↶ 720
    /// Check this repository's import of a Git branch: every commit's tree must be reproduced exactly
721
    Verify {
722
        /// The Git repository the import came from
723
        git_dir: PathBuf,
724
        /// Branch that was imported
725
        #[arg(long, default_value = "main")]
726
        branch: String,
727
    },
c3069537 Andy McCall ↶ 728
    /// Import a Git branch into a new Oxygen repository at DEST
729
    Import {
d42369ab Andy McCall 730
        /// Git repository to read
c3069537 Andy McCall ↶ 731
        git_dir: PathBuf,
d42369ab Andy McCall 732
        /// Directory for the new Oxygen repository
c3069537 Andy McCall ↶ 733
        dest: PathBuf,
d42369ab Andy McCall 734
        /// Branch to import
c3069537 Andy McCall ↶ 735
        #[arg(long, default_value = "main")]
736
        branch: String,
737
    },
79ab8528 Andy McCall ↶ 738
}
739
740
#[derive(Subcommand)]
83e0677b Andy McCall ↶ 741
enum PolicyCmd {
742
    /// Create the initial policy with your identity as the only root
743
    Init,
744
    /// Show the current policy
c6aa5bd9 Andy McCall ↶ 745
    Show {
d42369ab Andy McCall 746
        /// Machine-readable output: one JSON document on stdout
c6aa5bd9 Andy McCall ↶ 747
        #[arg(long)]
748
        json: bool,
749
    },
83e0677b Andy McCall ↶ 750
    /// Allow an identity (from `oxy identity export`) to update bookmarks
751
    Grant {
d42369ab Andy McCall 752
        /// The identity to grant, exported with `oxy identity export`
83e0677b Andy McCall ↶ 753
        identity_file: PathBuf,
754
        /// Reference pattern the grant applies to (default: every bookmark)
755
        #[arg(long)]
756
        pattern: Option<String>,
28fc23d7 Andy McCall ↶ 757
        /// Where to write the proposal when more root signatures are needed
758
        #[arg(long)]
759
        out: Option<PathBuf>,
83e0677b Andy McCall ↶ 760
    },
761
    /// Revoke a key (KeyId prefix of an identity in the policy)
28fc23d7 Andy McCall ↶ 762
    Revoke {
d42369ab Andy McCall 763
        /// KeyId prefix of the identity
28fc23d7 Andy McCall ↶ 764
        key: String,
765
        /// Where to write the proposal when more root signatures are needed
766
        #[arg(long)]
767
        out: Option<PathBuf>,
768
    },
769
    /// Manage root keys and the signature threshold for policy updates
770
    Root {
771
        #[command(subcommand)]
772
        cmd: RootCmd,
773
    },
774
    /// Add your root signature to a proposal file; applies it once the threshold is met
775
    Sign {
d42369ab Andy McCall 776
        /// The proposal file to sign
28fc23d7 Andy McCall ↶ 777
        proposal: PathBuf,
778
        /// Where to write the proposal if it still needs signatures (default: in place)
779
        #[arg(long)]
780
        out: Option<PathBuf>,
781
    },
782
}
783
784
#[derive(Subcommand)]
785
enum RootCmd {
786
    /// Make an exported identity a root key
787
    Add {
d42369ab Andy McCall 788
        /// The identity to make a root, exported with `oxy identity export`
28fc23d7 Andy McCall ↶ 789
        identity_file: PathBuf,
d42369ab Andy McCall 790
        /// Where to write the proposal when more root signatures are needed
28fc23d7 Andy McCall ↶ 791
        #[arg(long)]
792
        out: Option<PathBuf>,
793
    },
794
    /// Remove a root key by KeyId prefix
795
    Remove {
d42369ab Andy McCall 796
        /// KeyId prefix of the root key
28fc23d7 Andy McCall ↶ 797
        key: String,
d42369ab Andy McCall 798
        /// Where to write the proposal when more root signatures are needed
28fc23d7 Andy McCall ↶ 799
        #[arg(long)]
800
        out: Option<PathBuf>,
801
    },
802
    /// Require this many root signatures on policy updates
803
    Threshold {
d42369ab Andy McCall 804
        /// Number of root signatures
28fc23d7 Andy McCall ↶ 805
        n: u32,
d42369ab Andy McCall 806
        /// Where to write the proposal when more root signatures are needed
28fc23d7 Andy McCall ↶ 807
        #[arg(long)]
808
        out: Option<PathBuf>,
809
    },
83e0677b Andy McCall ↶ 810
}
811
fce44ae9 Andy McCall ↶ 812
/// Open the repository containing the current directory.
813
fn open() -> Result<Repo> {
814
    Repo::open(&std::env::current_dir()?).context("opening repository")
815
}
816
d42369ab Andy McCall 817
/// `oxy man`: every page into `dir`, or the top-level page on stdout.
818
fn man(dir: Option<PathBuf>) -> Result<i32> {
819
    use clap::CommandFactory;
820
    let cmd = Cli::command();
821
    match dir {
822
        Some(dir) => {
823
            std::fs::create_dir_all(&dir)?;
824
            clap_mangen::generate_to(cmd, &dir)?;
825
            let pages = std::fs::read_dir(&dir)?
826
                .filter(|e| {
827
                    e.as_ref()
828
                        .is_ok_and(|e| e.path().extension().is_some_and(|x| x == "1"))
829
                })
830
                .count();
831
            println!(
832
                "{}",
833
                ui::done(format!("Wrote {pages} man pages to {}", dir.display()))
834
            );
835
        }
836
        None => clap_mangen::Man::new(cmd).render(&mut std::io::stdout())?,
837
    }
838
    Ok(0)
839
}
840
fce44ae9 Andy McCall ↶ 841
/// Parse arguments and run; returns the process exit code.
842
pub fn run() -> Result<i32> {
843
    let cli = Cli::parse();
135212de Andy McCall ↶ 844
    ui::init(cli.plain);
fce44ae9 Andy McCall ↶ 845
    match cli.cmd {
d42369ab Andy McCall 846
        Cmd::Completions { shell } => {
847
            use clap::CommandFactory;
848
            clap_complete::generate(shell, &mut Cli::command(), "oxy", &mut std::io::stdout());
849
            Ok(0)
850
        }
851
        Cmd::Man { dir } => man(dir),
e02bf0cd Andy McCall ↶ 852
        Cmd::Init { path, bare } => workspace::init(path, bare),
50a046e4 Andy McCall ↶ 853
        Cmd::Status { json } => workspace::status(json),
75167672 Andy McCall 854
        Cmd::Prompt {
855
            format,
856
            glyphs,
857
            color,
858
        } => workspace::prompt(&format, glyphs, color.as_deref()),
859
        Cmd::Commit {
860
            message,
861
            depends_on,
862
            paths,
863
            interactive,
864
            hunks,
865
        } => workspace::commit(&message, &depends_on, &paths, interactive, &hunks),
c6aa5bd9 Andy McCall ↶ 866
        Cmd::Cat { path, change } => workspace::cat(&path, change.as_deref()),
867
        Cmd::Root { json } => workspace::root(json),
868
        Cmd::Version { json } => workspace::version(json),
869
        Cmd::Discard { paths, hunks } => workspace::discard(&paths, &hunks),
870
        Cmd::Hunks { json } => workspace::hunks(json),
728da0f9 Andy McCall ↶ 871
        Cmd::Squash { change, into } => workspace::squash(&change, &into),
872
        Cmd::Rebase { change, onto } => workspace::rebase(&change, &onto),
957fee30 Andy McCall ↶ 873
        Cmd::Blame { path, json } => workspace::blame(&path, json),
874
        Cmd::Bisect { cmd } => match cmd {
875
            BisectCmd::Start => workspace::bisect_start(),
876
            BisectCmd::Good { changes } => workspace::bisect_mark(Some(true), &changes),
877
            BisectCmd::Bad { changes } => workspace::bisect_mark(Some(false), &changes),
878
            BisectCmd::Skip => workspace::bisect_mark(None, &[]),
879
            BisectCmd::Run { command } => workspace::bisect_run(&command),
c6aa5bd9 Andy McCall ↶ 880
            BisectCmd::Status { json } => workspace::bisect_status(json),
957fee30 Andy McCall ↶ 881
            BisectCmd::Reset => workspace::bisect_reset(),
882
        },
75167672 Andy McCall 883
        Cmd::Log {
884
            limit,
885
            verbose,
886
            path,
887
            json,
888
        } => workspace::log(limit, verbose, path.as_deref(), json),
c6aa5bd9 Andy McCall ↶ 889
        Cmd::Diff { change, json } => workspace::diff(change.as_deref(), json),
614541c3 Andy McCall ↶ 890
        Cmd::Describe { message, change } => workspace::describe(&message, change.as_deref()),
23b217d7 Andy McCall ↶ 891
        Cmd::Amend { message, into } => workspace::amend(message.as_deref(), into.as_deref()),
892
        Cmd::Split { change, paths } => workspace::split(&change, &paths),
614541c3 Andy McCall ↶ 893
        Cmd::Abandon { change } => workspace::abandon(&change),
c6aa5bd9 Andy McCall ↶ 894
        Cmd::Show { change, json } => workspace::show(&change, json),
fce44ae9 Andy McCall ↶ 895
        Cmd::Checkout { changes, discard } => workspace::checkout(&changes, discard),
c6aa5bd9 Andy McCall ↶ 896
        Cmd::Resolve { json } => workspace::resolve(json),
fce44ae9 Andy McCall ↶ 897
        Cmd::Undo => workspace::undo(),
ba160f60 Andy McCall ↶ 898
        Cmd::Gc { now } => workspace::gc(now),
387335ff Andy McCall ↶ 899
        Cmd::Fsck { json } => workspace::fsck(json),
3e5772cc Andy McCall ↶ 900
        Cmd::Doctor { offline, json } => workspace::doctor(offline, json),
252e8cb2 Andy McCall ↶ 901
        Cmd::Checkpoint => workspace::checkpoint(),
75167672 Andy McCall 902
        Cmd::Op {
903
            cmd: OpCmd::Log { json },
904
        } => workspace::op_log(json),
905
        Cmd::Clone {
906
            url,
907
            dest,
908
            max_blob,
909
            sparse,
910
            depth,
911
        } => sync::clone(&url, dest, max_blob.as_deref(), &sparse, depth),
2863456a Andy McCall ↶ 912
        Cmd::Deepen { depth, remote } => sync::deepen(&remote, depth),
7421309f Andy McCall ↶ 913
        Cmd::Sparse { paths } => workspace::sparse(&paths),
cdb5beba Andy McCall ↶ 914
        Cmd::Lock { path } => workspace::lock(&path),
915
        Cmd::Unlock { path } => workspace::unlock(&path),
4e88e774 Andy McCall ↶ 916
        Cmd::Workspace { cmd } => match cmd {
917
            WorkspaceCmd::Add { path, changes } => workspace::workspace_add(&path, &changes),
1196b29b Andy McCall ↶ 918
            WorkspaceCmd::List { json } => workspace::workspace_list(json),
4e88e774 Andy McCall ↶ 919
            WorkspaceCmd::Forget { workspace } => workspace::workspace_forget(&workspace),
920
        },
7b9809e6 Andy McCall ↶ 921
        Cmd::Bookmark { cmd } => match cmd {
922
            BookmarkCmd::Create { name, changes } => workspace::bookmark_create(&name, &changes),
923
            BookmarkCmd::Set { name, changes } => workspace::bookmark_set(&name, &changes),
924
            BookmarkCmd::Delete { name } => workspace::bookmark_delete(&name),
c6aa5bd9 Andy McCall ↶ 925
            BookmarkCmd::List { json } => workspace::bookmark_list(json),
7b9809e6 Andy McCall ↶ 926
            BookmarkCmd::Switch { name, discard } => workspace::bookmark_switch(&name, discard),
927
        },
928
        Cmd::Merge { bookmark } => workspace::merge(&bookmark),
4dee277c Andy McCall ↶ 929
        Cmd::Submodule { cmd } => match cmd {
75167672 Andy McCall 930
            SubmoduleCmd::Add {
931
                url,
932
                path,
933
                bookmark,
934
            } => sync::submodule_add(&url, &path, bookmark.as_deref()),
4dee277c Andy McCall ↶ 935
            SubmoduleCmd::Update { init, paths } => sync::submodule_update(init, &paths),
c6aa5bd9 Andy McCall ↶ 936
            SubmoduleCmd::Status { json } => sync::submodule_status(json),
4dee277c Andy McCall ↶ 937
            SubmoduleCmd::Remove { path } => sync::submodule_remove(&path),
938
        },
132b884b Andy McCall ↶ 939
        Cmd::Tag { cmd } => match cmd {
75167672 Andy McCall 940
            TagCmd::Create {
941
                name,
942
                changes,
943
                message,
944
            } => workspace::tag_create(&name, &changes, &message),
1196b29b Andy McCall ↶ 945
            TagCmd::List { json } => workspace::tag_list(json),
132b884b Andy McCall ↶ 946
        },
fce44ae9 Andy McCall ↶ 947
        Cmd::Remote { cmd } => match cmd {
948
            RemoteCmd::Add { name, url } => sync::remote_add(&name, &url),
949
            RemoteCmd::Remove { name } => sync::remote_remove(&name),
c6aa5bd9 Andy McCall ↶ 950
            RemoteCmd::List { json } => sync::remote_list(json),
fce44ae9 Andy McCall ↶ 951
        },
c6aa5bd9 Andy McCall ↶ 952
        Cmd::Fetch { remote, json } => sync::fetch(remote.as_deref(), json),
953
        Cmd::Pull { remote, json } => sync::pull(remote.as_deref(), json),
75167672 Andy McCall 954
        Cmd::Push {
955
            remote,
956
            force,
957
            bookmark,
f8c69576 Andy McCall ↶ 958
            delete,
75167672 Andy McCall 959
            json,
f8c69576 Andy McCall ↶ 960
        } => match delete {
961
            Some(name) => sync::push_delete(remote.as_deref(), &name, json),
962
            None => sync::push(remote.as_deref(), force, bookmark.as_deref(), json),
963
        },
75167672 Andy McCall 964
        Cmd::Serve {
965
            root,
966
            bind,
967
            tokens,
968
            tls_cert,
969
            tls_key,
970
        } => sync::serve(root, &bind, tokens, tls_cert.zip(tls_key)),
fce44ae9 Andy McCall ↶ 971
        Cmd::Identity { cmd } => match cmd {
75167672 Andy McCall 972
            IdentityCmd::Create {
973
                name,
974
                email,
975
                local,
976
                expires,
977
            } => identity::create(name, email, local, expires),
fce44ae9 Andy McCall ↶ 978
            IdentityCmd::Show => identity::show(),
83e0677b Andy McCall ↶ 979
            IdentityCmd::Export { path } => identity::export(path),
119bbf50 Andy McCall ↶ 980
            IdentityCmd::SignChallenge { challenge, json } => {
981
                identity::sign_challenge(&challenge, json)
982
            }
28fc23d7 Andy McCall ↶ 983
            IdentityCmd::Rotate => identity::rotate(),
984
            IdentityCmd::Renew { expires } => identity::renew(expires),
985
            IdentityCmd::Revoke { key, reason } => identity::revoke(key.as_deref(), &reason),
986
            IdentityCmd::Delegate { cmd } => match cmd {
987
                DelegateCmd::Add { identity_file } => identity::delegate_add(&identity_file),
988
                DelegateCmd::Remove { key } => identity::delegate_remove(&key),
989
                DelegateCmd::List => identity::delegate_list(),
990
            },
83e0677b Andy McCall ↶ 991
        },
75167672 Andy McCall 992
        Cmd::Git {
993
            cmd: GitCmd::Export { git_dir, branch },
994
        } => sync::git_export(&git_dir, branch.as_deref()),
995
        Cmd::Git {
996
            cmd: GitCmd::Fetch { url, branch },
997
        } => sync::git_fetch(&url, &branch),
998
        Cmd::Git {
999
            cmd: GitCmd::Push { url, branch },
1000
        } => sync::git_push(&url, &branch),
1001
        Cmd::Git {
1002
            cmd:
1003
                GitCmd::Import {
1004
                    git_dir,
1005
                    dest,
1006
                    branch,
1007
                },
1008
        } => sync::git_import(&git_dir, &dest, &branch),
62794ecc Andy McCall ↶ 1009
        Cmd::Git {
1010
            cmd: GitCmd::Verify { git_dir, branch },
1011
        } => sync::git_verify(&git_dir, &branch),
83e0677b Andy McCall ↶ 1012
        Cmd::Policy { cmd } => match cmd {
1013
            PolicyCmd::Init => identity::policy_init(),
c6aa5bd9 Andy McCall ↶ 1014
            PolicyCmd::Show { json } => identity::policy_show(json),
75167672 Andy McCall 1015
            PolicyCmd::Grant {
1016
                identity_file,
1017
                pattern,
1018
                out,
1019
            } => identity::policy_grant(&identity_file, pattern.as_deref(), out),
28fc23d7 Andy McCall ↶ 1020
            PolicyCmd::Revoke { key, out } => identity::policy_revoke(&key, out),
1021
            PolicyCmd::Root { cmd } => match cmd {
75167672 Andy McCall 1022
                RootCmd::Add { identity_file, out } => {
1023
                    identity::policy_root_add(&identity_file, out)
1024
                }
28fc23d7 Andy McCall ↶ 1025
                RootCmd::Remove { key, out } => identity::policy_root_remove(&key, out),
1026
                RootCmd::Threshold { n, out } => identity::policy_threshold(n, out),
1027
            },
1028
            PolicyCmd::Sign { proposal, out } => identity::policy_sign(&proposal, out),
fce44ae9 Andy McCall ↶ 1029
        },
4213c41d Andy McCall ↶ 1030
        Cmd::Seal {
1031
            changes,
1032
            proposal: Some(url),
1033
            json,
1034
        } if changes.is_empty() => proposal::seal(&url, json),
d82e4409 Andy McCall ↶ 1035
        Cmd::Seal { changes, json, .. } => identity::seal(&changes, json),
1036
        Cmd::Proposal { cmd } => match cmd {
1037
            ProposalCmd::Show { url, json } => proposal::show(&url, json),
1038
            ProposalCmd::Land { url, force } => proposal::land(&url, force),
1039
        },
c6aa5bd9 Andy McCall ↶ 1040
        Cmd::Verify { change, json } => identity::verify(change.as_deref(), json),
fce44ae9 Andy McCall ↶ 1041
        Cmd::Config { key, value, user } => identity::config(&key, &value, user),
1042
    }
1043
}
d42369ab Andy McCall 1044
1045
#[cfg(test)]
1046
mod help_tests {
1047
    use super::Cli;
1048
    use clap::CommandFactory;
1049
1050
    /// Every command and every argument explains itself, so `--help`,
1051
    /// completions and the man pages are complete.
1052
    #[test]
1053
    fn every_command_and_argument_has_help() {
1054
        fn walk(cmd: &clap::Command, path: &str, missing: &mut Vec<String>) {
1055
            let here = format!("{path} {}", cmd.get_name()).trim().to_string();
1056
            if cmd.get_about().is_none() && path != "" {
1057
                missing.push(format!("{here} (command)"));
1058
            }
1059
            for a in cmd.get_arguments() {
1060
                let id = a.get_id().as_str();
1061
                if id == "help" || id == "version" || a.is_global_set() && path != "" {
1062
                    continue;
1063
                }
1064
                if a.get_help().is_none() && a.get_long_help().is_none() {
1065
                    missing.push(format!("{here} {id}"));
1066
                }
1067
            }
1068
            for sub in cmd.get_subcommands() {
1069
                walk(sub, &here, missing);
1070
            }
1071
        }
1072
        let mut missing = Vec::new();
1073
        walk(&Cli::command(), "", &mut missing);
1074
        assert!(
1075
            missing.is_empty(),
1076
            "{} without help:\n{}",
1077
            missing.len(),
1078
            missing.join("\n")
1079
        );
1080
    }
1081
}