OXYGENHUB
# 05e71ed6cdf1 oxygen / src / cli / mod.rs
25.5 KiB · Rust · last changed Seals adopt anonymous changes; oxy seal command 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;
fce44ae9 Andy McCall ↶ 6
mod sync;
135212de Andy McCall ↶ 7
pub mod ui;
fce44ae9 Andy McCall ↶ 8
mod workspace;
9
10
use anyhow::{Context, Result};
11
use clap::{Parser, Subcommand};
12
use oxy_core::repo::Repo;
13
use std::path::PathBuf;
14
15
#[derive(Parser)]
75167672 Andy McCall 16
#[command(
17
    name = "oxy",
18
    version,
19
    about = "Oxygen: breathing fresh air into version control"
20
)]
fce44ae9 Andy McCall ↶ 21
struct Cli {
135212de Andy McCall ↶ 22
    /// Plain output: no colour, no spinner (also implied by NO_COLOR or a non-terminal)
23
    #[arg(long, global = true)]
24
    plain: bool,
fce44ae9 Andy McCall ↶ 25
    #[command(subcommand)]
26
    cmd: Cmd,
27
}
28
29
#[derive(Subcommand)]
30
enum Cmd {
31
    /// Create a repository in PATH (default: current directory)
e02bf0cd Andy McCall ↶ 32
    Init {
33
        path: Option<PathBuf>,
34
        /// No working copy: an object store and references only, for hosting
35
        #[arg(long)]
36
        bare: bool,
37
    },
fce44ae9 Andy McCall ↶ 38
    /// Clone a repository from a local path or an http(s) URL
b3c5a59a Andy McCall ↶ 39
    Clone {
40
        url: String,
41
        dest: Option<PathBuf>,
42
        /// Leave blobs larger than this (e.g. 1M) to be fetched on first read
43
        #[arg(long)]
44
        max_blob: Option<String>,
7421309f Andy McCall ↶ 45
        /// Materialize only these paths (repeatable); implies lazy blobs
46
        #[arg(long = "sparse")]
47
        sparse: Vec<String>,
2863456a Andy McCall ↶ 48
        /// Shallow clone: fetch only this many levels of history below the heads
49
        #[arg(long)]
50
        depth: Option<u32>,
b3c5a59a Andy McCall ↶ 51
    },
2863456a Andy McCall ↶ 52
    /// Fetch more history below a shallow clone's boundary
53
    Deepen {
54
        #[arg(default_value_t = 10)]
55
        depth: u32,
56
        #[arg(long, default_value = "origin")]
57
        remote: String,
58
    },
7421309f Andy McCall ↶ 59
    /// Show or set the sparse filter (paths to materialize); re-checks out the bookmark
60
    Sparse { paths: Vec<String> },
fce44ae9 Andy McCall ↶ 61
    /// Show the working copy: changed paths and conflicts
50a046e4 Andy McCall ↶ 62
    Status {
63
        /// Machine-readable output: paths, and every conflict with its kind and contributing changes
64
        #[arg(long)]
65
        json: bool,
66
    },
135212de Andy McCall ↶ 67
    /// One-line summary for shell prompts; fast and records nothing
68
    Prompt {
694805cc Andy McCall ↶ 69
        /// 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 ↶ 70
        #[arg(long, default_value = oxy_core::repo::DEFAULT_PROMPT_FORMAT)]
71
        format: String,
694805cc Andy McCall ↶ 72
        /// Glyph format (%i %b %c %s%U%O) instead of the plain default
73
        #[arg(long)]
74
        glyphs: bool,
75
        /// Colour by state (cyan clean, yellow dirty, red conflicted): raw escapes, or guarded for a bash or zsh PS1
76
        #[arg(long, value_parser = ["raw", "bash", "zsh"])]
77
        color: Option<String>,
135212de Andy McCall ↶ 78
    },
fce44ae9 Andy McCall ↶ 79
    /// Record the working copy as a change on the current bookmark
80
    Commit {
81
        #[arg(short, long)]
82
        message: String,
83
        /// Extra explicit dependencies (ChangeId prefix, #hash prefix)
84
        #[arg(long = "depends-on")]
85
        depends_on: Vec<String>,
957fee30 Andy McCall ↶ 86
        /// Commit only these paths; the rest stays as uncommitted work
87
        paths: Vec<String>,
88
        /// Choose hunks one by one
89
        #[arg(short, long)]
90
        interactive: bool,
c6aa5bd9 Andy McCall ↶ 91
        /// Commit these hunks (as `oxy hunks` numbers them), comma separated
92
        #[arg(long, value_delimiter = ',')]
93
        hunks: Vec<usize>,
fce44ae9 Andy McCall ↶ 94
    },
728da0f9 Andy McCall ↶ 95
    /// Fold CHANGE into one of its dependencies (keeps that change's id)
96
    Squash {
97
        change: String,
98
        #[arg(long)]
99
        into: String,
100
    },
101
    /// Re-express CHANGE against another base state
102
    Rebase {
103
        change: String,
104
        /// The changes, bookmark or tag whose state becomes the new base
105
        #[arg(long, required = true, num_args = 1..)]
106
        onto: Vec<String>,
107
    },
957fee30 Andy McCall ↶ 108
    /// Show which change introduced each line of a file
109
    Blame {
110
        path: String,
111
        #[arg(long)]
112
        json: bool,
113
    },
114
    /// Find the change that introduced a regression
115
    Bisect {
116
        #[command(subcommand)]
117
        cmd: BisectCmd,
118
    },
fce44ae9 Andy McCall ↶ 119
    /// List changes reachable from the bookmark and the working copy
94084087 Andy McCall ↶ 120
    Log {
121
        /// Show at most this many changes
122
        #[arg(short = 'n', long)]
123
        limit: Option<usize>,
124
        /// Show full messages, dependencies, and signatures
125
        #[arg(short, long)]
126
        verbose: bool,
c6aa5bd9 Andy McCall ↶ 127
        /// Only changes touching this path (renames followed)
128
        #[arg(long)]
129
        path: Option<String>,
130
        #[arg(long)]
131
        json: bool,
94084087 Andy McCall ↶ 132
    },
fce44ae9 Andy McCall ↶ 133
    /// Show what the working copy changes against its base
c6aa5bd9 Andy McCall ↶ 134
    Diff {
135
        /// A change instead of the working copy
136
        change: Option<String>,
137
        #[arg(long)]
138
        json: bool,
139
    },
140
    /// Print a file as it is in a state (default: the working copy's base)
141
    Cat {
142
        path: String,
143
        /// A change, bookmark, or tag
144
        #[arg(short = 'r', long)]
145
        change: Option<String>,
146
    },
147
    /// Print the repository root, workspace, and bookmark
148
    Root {
149
        #[arg(long)]
150
        json: bool,
151
    },
152
    /// Print the version of oxy, its repository format, and protocol
153
    Version {
154
        #[arg(long)]
155
        json: bool,
156
    },
157
    /// Restore paths to the working copy's base, or undo chosen hunks
158
    Discard {
159
        paths: Vec<String>,
160
        /// Hunk indices as `oxy hunks` numbers them, comma separated
161
        #[arg(long, value_delimiter = ',')]
162
        hunks: Vec<usize>,
163
    },
164
    /// List the working copy's hunks, numbered as commit --hunks expects
165
    Hunks {
166
        #[arg(long)]
167
        json: bool,
168
    },
614541c3 Andy McCall ↶ 169
    /// Change the message of a head (default: the head the working copy sits on)
170
    Describe {
171
        #[arg(short, long)]
172
        message: String,
173
        change: Option<String>,
174
    },
23b217d7 Andy McCall ↶ 175
    /// Fold the working copy into the head it sits on, or into CHANGE with --into
614541c3 Andy McCall ↶ 176
    Amend {
177
        #[arg(short, long)]
178
        message: Option<String>,
23b217d7 Andy McCall ↶ 179
        /// Amend an older change; the edits must touch only lines it already knows
180
        #[arg(long)]
181
        into: Option<String>,
614541c3 Andy McCall ↶ 182
    },
23b217d7 Andy McCall ↶ 183
    /// Split a head: the named paths become a separate first change
75167672 Andy McCall 184
    Split { change: String, paths: Vec<String> },
614541c3 Andy McCall ↶ 185
    /// Drop a head from the bookmark; its content stays on disk as uncommitted work
186
    Abandon { change: String },
fce44ae9 Andy McCall ↶ 187
    /// Show one change (ChangeId prefix, #hash prefix, or @)
c6aa5bd9 Andy McCall ↶ 188
    Show {
189
        change: String,
190
        #[arg(long)]
191
        json: bool,
192
    },
fce44ae9 Andy McCall ↶ 193
    /// Move the working copy to the state formed by CHANGE... (default: the bookmark heads)
194
    Checkout {
195
        changes: Vec<String>,
196
        /// Throw away uncommitted working-copy changes
197
        #[arg(long)]
198
        discard: bool,
199
    },
200
    /// Report which conflicts of the working copy's base are resolved by the current files
c6aa5bd9 Andy McCall ↶ 201
    Resolve {
202
        #[arg(long)]
203
        json: bool,
204
    },
fce44ae9 Andy McCall ↶ 205
    /// Undo the last operation
206
    Undo,
252e8cb2 Andy McCall ↶ 207
    /// Write a checkpoint of the current bookmark's state now
208
    Checkpoint,
ba160f60 Andy McCall ↶ 209
    /// Pack loose objects and prune unreachable ones older than the grace period
210
    Gc {
211
        /// Ignore the grace period (core.gc-grace) and prune immediately
212
        #[arg(long)]
213
        now: bool,
214
    },
fce44ae9 Andy McCall ↶ 215
    /// List operations
216
    #[command(name = "op")]
217
    Op {
218
        #[command(subcommand)]
219
        cmd: OpCmd,
220
    },
cdb5beba Andy McCall ↶ 221
    /// Take the advisory local lock on a lockable file, making it writable
222
    Lock { path: String },
223
    /// Release the local lock and make the file read-only again
224
    Unlock { path: String },
4e88e774 Andy McCall ↶ 225
    /// Workspaces: extra checkout directories sharing this repository
226
    Workspace {
227
        #[command(subcommand)]
228
        cmd: WorkspaceCmd,
229
    },
7b9809e6 Andy McCall ↶ 230
    /// Bookmarks: named states; each workspace works on one
231
    Bookmark {
232
        #[command(subcommand)]
233
        cmd: BookmarkCmd,
234
    },
235
    /// Union another bookmark's heads into the current one (no merge change)
236
    Merge { bookmark: String },
4dee277c Andy McCall ↶ 237
    /// Subrepositories: nested repositories pinned to a state
238
    Submodule {
239
        #[command(subcommand)]
240
        cmd: SubmoduleCmd,
241
    },
132b884b Andy McCall ↶ 242
    /// Tags: immutable named states
243
    Tag {
244
        #[command(subcommand)]
245
        cmd: TagCmd,
246
    },
fce44ae9 Andy McCall ↶ 247
    /// Manage remotes
248
    Remote {
249
        #[command(subcommand)]
250
        cmd: RemoteCmd,
251
    },
252
    /// Fetch every bookmark of a remote into its tracking references
c6aa5bd9 Andy McCall ↶ 253
    Fetch {
254
        remote: Option<String>,
255
        #[arg(long)]
256
        json: bool,
257
    },
fce44ae9 Andy McCall ↶ 258
    /// Fetch, then union the remote bookmark into the local one (no merge change)
c6aa5bd9 Andy McCall ↶ 259
    Pull {
260
        remote: Option<String>,
261
        #[arg(long)]
262
        json: bool,
263
    },
fce44ae9 Andy McCall ↶ 264
    /// Push the current bookmark to a remote
265
    Push {
266
        remote: Option<String>,
267
        /// Allow dropping heads the remote has
268
        #[arg(long)]
269
        force: bool,
7b9809e6 Andy McCall ↶ 270
        /// Push this bookmark instead of the workspace's current one
271
        #[arg(short = 'b', long)]
272
        bookmark: Option<String>,
c6aa5bd9 Andy McCall ↶ 273
        #[arg(long)]
274
        json: bool,
fce44ae9 Andy McCall ↶ 275
    },
2b5ee371 Andy McCall ↶ 276
    /// Serve repositories under ROOT over HTTPS (with --tls-cert/--tls-key) or plain HTTP
fce44ae9 Andy McCall ↶ 277
    Serve {
278
        /// Directory with one repository per subdirectory
279
        #[arg(long, default_value = ".")]
280
        root: PathBuf,
281
        #[arg(long, default_value = "127.0.0.1:8890")]
282
        bind: String,
283
        /// Bearer token allowed to push (repeatable); none means open
284
        #[arg(long = "token")]
285
        tokens: Vec<String>,
2b5ee371 Andy McCall ↶ 286
        /// PEM certificate chain; enables HTTPS together with --tls-key
287
        #[arg(long, requires = "tls_key")]
288
        tls_cert: Option<PathBuf>,
289
        /// PEM private key
290
        #[arg(long, requires = "tls_cert")]
291
        tls_key: Option<PathBuf>,
fce44ae9 Andy McCall ↶ 292
    },
293
    /// Manage the signing identity
294
    Identity {
295
        #[command(subcommand)]
296
        cmd: IdentityCmd,
297
    },
05e71ed6 Andy McCall ↶ 298
    /// Seal changes with your key: named ones, or every change on the current bookmark you can authenticate but have not
299
    Seal {
300
        changes: Vec<String>,
301
        #[arg(long)]
302
        json: bool,
303
    },
fce44ae9 Andy McCall ↶ 304
    /// Verify the signatures on a change (default: every change in the log)
c6aa5bd9 Andy McCall ↶ 305
    Verify {
306
        change: Option<String>,
307
        #[arg(long)]
308
        json: bool,
309
    },
79ab8528 Andy McCall ↶ 310
    /// Git interoperability
311
    Git {
312
        #[command(subcommand)]
313
        cmd: GitCmd,
314
    },
83e0677b Andy McCall ↶ 315
    /// Manage the trust policy (who may update which bookmarks)
316
    Policy {
317
        #[command(subcommand)]
318
        cmd: PolicyCmd,
319
    },
7421309f Andy McCall ↶ 320
    /// 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 ↶ 321
    Config {
322
        key: String,
323
        value: String,
324
        /// Write to the user file (~/.config/oxy/config.toml) instead of this repository
325
        #[arg(long)]
326
        user: bool,
327
    },
328
}
329
330
#[derive(Subcommand)]
331
enum OpCmd {
c6aa5bd9 Andy McCall ↶ 332
    Log {
333
        #[arg(long)]
334
        json: bool,
335
    },
fce44ae9 Andy McCall ↶ 336
}
337
338
#[derive(Subcommand)]
4e88e774 Andy McCall ↶ 339
enum WorkspaceCmd {
340
    /// Create a workspace at PATH checked out on CHANGE... (default: the bookmark heads)
341
    Add { path: PathBuf, changes: Vec<String> },
1196b29b Andy McCall ↶ 342
    List {
343
        #[arg(long)]
344
        json: bool,
345
    },
4e88e774 Andy McCall ↶ 346
    /// Stop tracking a workspace (by id prefix or path); its files stay
347
    Forget { workspace: String },
348
}
349
350
#[derive(Subcommand)]
957fee30 Andy McCall ↶ 351
enum BisectCmd {
352
    /// Begin; remembers where the working copy was
353
    Start,
354
    /// Mark CHANGE... (or the state under test) as good
355
    Good { changes: Vec<String> },
356
    /// Mark CHANGE... (or the state under test) as bad
357
    Bad { changes: Vec<String> },
358
    /// The state under test cannot be tested; try another
359
    Skip,
360
    /// Run a command for each step: exit 0 good, 125 skip, else bad
361
    Run {
362
        #[arg(required = true, trailing_var_arg = true)]
363
        command: Vec<String>,
364
    },
365
    /// Where the search stands
c6aa5bd9 Andy McCall ↶ 366
    Status {
367
        #[arg(long)]
368
        json: bool,
369
    },
957fee30 Andy McCall ↶ 370
    /// Restore the working copy and forget the search
371
    Reset,
372
}
373
374
#[derive(Subcommand)]
7b9809e6 Andy McCall ↶ 375
enum BookmarkCmd {
376
    /// Create a bookmark at CHANGE... (default: the working copy's base)
377
    Create { name: String, changes: Vec<String> },
378
    /// Point an existing bookmark at CHANGE...
379
    Set { name: String, changes: Vec<String> },
380
    /// Remove a bookmark; its changes stay
381
    Delete { name: String },
382
    /// List bookmarks with their heads and difference from origin
c6aa5bd9 Andy McCall ↶ 383
    List {
384
        #[arg(long)]
385
        json: bool,
386
    },
7b9809e6 Andy McCall ↶ 387
    /// Make NAME this workspace's bookmark and check it out
388
    Switch {
389
        name: String,
390
        /// Throw away uncommitted working-copy changes
391
        #[arg(long)]
392
        discard: bool,
393
    },
394
}
395
396
#[derive(Subcommand)]
4dee277c Andy McCall ↶ 397
enum SubmoduleCmd {
398
    /// Clone URL (Oxygen or Git) into PATH and register it in .oxymodules
399
    Add {
400
        url: String,
401
        path: String,
402
        /// Bookmark (Oxygen) or branch (Git) to check out and track
403
        #[arg(long)]
404
        bookmark: Option<String>,
405
    },
406
    /// Bring nested repositories to their pins
407
    Update {
408
        /// Clone nested repositories that are absent
409
        #[arg(long)]
410
        init: bool,
411
        paths: Vec<String>,
412
    },
413
    /// List subrepos with their pins and on-disk state
c6aa5bd9 Andy McCall ↶ 414
    Status {
415
        #[arg(long)]
416
        json: bool,
417
    },
4dee277c Andy McCall ↶ 418
    /// Unregister PATH; the directory stays, the node goes with the next commit
419
    Remove { path: String },
420
}
421
422
#[derive(Subcommand)]
132b884b Andy McCall ↶ 423
enum TagCmd {
424
    /// Tag the state of CHANGE... (default: the bookmark heads)
425
    Create {
426
        name: String,
427
        changes: Vec<String>,
428
        #[arg(short, long, default_value = "")]
429
        message: String,
430
    },
1196b29b Andy McCall ↶ 431
    List {
432
        #[arg(long)]
433
        json: bool,
434
    },
132b884b Andy McCall ↶ 435
}
436
437
#[derive(Subcommand)]
fce44ae9 Andy McCall ↶ 438
enum RemoteCmd {
75167672 Andy McCall 439
    Add {
440
        name: String,
441
        url: String,
442
    },
443
    Remove {
444
        name: String,
445
    },
c6aa5bd9 Andy McCall ↶ 446
    List {
447
        #[arg(long)]
448
        json: bool,
449
    },
fce44ae9 Andy McCall ↶ 450
}
451
452
#[derive(Subcommand)]
453
enum IdentityCmd {
454
    /// Generate a composite Ed25519 + ML-DSA-65 key pair and make it your author identity
455
    Create {
456
        #[arg(long)]
457
        name: Option<String>,
458
        #[arg(long)]
459
        email: Option<String>,
460
        /// Record the author in this repository only, not in the user config
461
        #[arg(long)]
462
        local: bool,
28fc23d7 Andy McCall ↶ 463
        /// Expire the identity this many days from now
464
        #[arg(long)]
465
        expires: Option<u64>,
fce44ae9 Andy McCall ↶ 466
    },
467
    /// Show the configured identity
468
    Show,
83e0677b Andy McCall ↶ 469
    /// Write your identity object to a file, to hand to a policy holder
470
    Export { path: Option<PathBuf> },
28fc23d7 Andy McCall ↶ 471
    /// Move to a fresh key pair; the policy follows if it names your key
472
    Rotate,
473
    /// Re-issue your identity with a new expiry (in days from now; 0 = never)
474
    Renew {
475
        #[arg(long)]
476
        expires: u64,
477
    },
478
    /// Revoke a key: yours by default, or any key if you hold a policy root
479
    Revoke {
480
        /// KeyId prefix (default: your own key)
481
        key: Option<String>,
482
        #[arg(long, default_value = "")]
483
        reason: String,
484
    },
485
    /// Keys allowed to sign or seal on your behalf
486
    Delegate {
487
        #[command(subcommand)]
488
        cmd: DelegateCmd,
489
    },
490
}
491
492
#[derive(Subcommand)]
493
enum DelegateCmd {
494
    /// Add a delegate from an exported identity file
495
    Add { identity_file: PathBuf },
496
    /// Remove a delegate by KeyId prefix
497
    Remove { key: String },
498
    /// List delegates
499
    List,
fce44ae9 Andy McCall ↶ 500
}
501
83e0677b Andy McCall ↶ 502
#[derive(Subcommand)]
79ab8528 Andy McCall ↶ 503
enum GitCmd {
504
    /// Export the current bookmark to a Git repository (created bare if absent)
30ea9c1e Andy McCall ↶ 505
    Export {
506
        git_dir: PathBuf,
507
        /// Git branch to write (default: the bookmark name)
508
        #[arg(long)]
509
        branch: Option<String>,
510
    },
511
    /// Fetch a branch from a Git remote (path or URL) into the current bookmark
512
    Fetch {
513
        url: String,
514
        #[arg(long, default_value = "main")]
515
        branch: String,
516
    },
517
    /// Push the current bookmark to a branch of a Git remote (fetch first)
518
    Push {
519
        url: String,
520
        #[arg(long, default_value = "main")]
521
        branch: String,
522
    },
c3069537 Andy McCall ↶ 523
    /// Import a Git branch into a new Oxygen repository at DEST
524
    Import {
525
        git_dir: PathBuf,
526
        dest: PathBuf,
527
        #[arg(long, default_value = "main")]
528
        branch: String,
529
    },
79ab8528 Andy McCall ↶ 530
}
531
532
#[derive(Subcommand)]
83e0677b Andy McCall ↶ 533
enum PolicyCmd {
534
    /// Create the initial policy with your identity as the only root
535
    Init,
536
    /// Show the current policy
c6aa5bd9 Andy McCall ↶ 537
    Show {
538
        #[arg(long)]
539
        json: bool,
540
    },
83e0677b Andy McCall ↶ 541
    /// Allow an identity (from `oxy identity export`) to update bookmarks
542
    Grant {
543
        identity_file: PathBuf,
544
        /// Reference pattern the grant applies to (default: every bookmark)
545
        #[arg(long)]
546
        pattern: Option<String>,
28fc23d7 Andy McCall ↶ 547
        /// Where to write the proposal when more root signatures are needed
548
        #[arg(long)]
549
        out: Option<PathBuf>,
83e0677b Andy McCall ↶ 550
    },
551
    /// Revoke a key (KeyId prefix of an identity in the policy)
28fc23d7 Andy McCall ↶ 552
    Revoke {
553
        key: String,
554
        /// Where to write the proposal when more root signatures are needed
555
        #[arg(long)]
556
        out: Option<PathBuf>,
557
    },
558
    /// Manage root keys and the signature threshold for policy updates
559
    Root {
560
        #[command(subcommand)]
561
        cmd: RootCmd,
562
    },
563
    /// Add your root signature to a proposal file; applies it once the threshold is met
564
    Sign {
565
        proposal: PathBuf,
566
        /// Where to write the proposal if it still needs signatures (default: in place)
567
        #[arg(long)]
568
        out: Option<PathBuf>,
569
    },
570
}
571
572
#[derive(Subcommand)]
573
enum RootCmd {
574
    /// Make an exported identity a root key
575
    Add {
576
        identity_file: PathBuf,
577
        #[arg(long)]
578
        out: Option<PathBuf>,
579
    },
580
    /// Remove a root key by KeyId prefix
581
    Remove {
582
        key: String,
583
        #[arg(long)]
584
        out: Option<PathBuf>,
585
    },
586
    /// Require this many root signatures on policy updates
587
    Threshold {
588
        n: u32,
589
        #[arg(long)]
590
        out: Option<PathBuf>,
591
    },
83e0677b Andy McCall ↶ 592
}
593
fce44ae9 Andy McCall ↶ 594
/// Open the repository containing the current directory.
595
fn open() -> Result<Repo> {
596
    Repo::open(&std::env::current_dir()?).context("opening repository")
597
}
598
599
/// Parse arguments and run; returns the process exit code.
600
pub fn run() -> Result<i32> {
601
    let cli = Cli::parse();
135212de Andy McCall ↶ 602
    ui::init(cli.plain);
fce44ae9 Andy McCall ↶ 603
    match cli.cmd {
e02bf0cd Andy McCall ↶ 604
        Cmd::Init { path, bare } => workspace::init(path, bare),
50a046e4 Andy McCall ↶ 605
        Cmd::Status { json } => workspace::status(json),
75167672 Andy McCall 606
        Cmd::Prompt {
607
            format,
608
            glyphs,
609
            color,
610
        } => workspace::prompt(&format, glyphs, color.as_deref()),
611
        Cmd::Commit {
612
            message,
613
            depends_on,
614
            paths,
615
            interactive,
616
            hunks,
617
        } => workspace::commit(&message, &depends_on, &paths, interactive, &hunks),
c6aa5bd9 Andy McCall ↶ 618
        Cmd::Cat { path, change } => workspace::cat(&path, change.as_deref()),
619
        Cmd::Root { json } => workspace::root(json),
620
        Cmd::Version { json } => workspace::version(json),
621
        Cmd::Discard { paths, hunks } => workspace::discard(&paths, &hunks),
622
        Cmd::Hunks { json } => workspace::hunks(json),
728da0f9 Andy McCall ↶ 623
        Cmd::Squash { change, into } => workspace::squash(&change, &into),
624
        Cmd::Rebase { change, onto } => workspace::rebase(&change, &onto),
957fee30 Andy McCall ↶ 625
        Cmd::Blame { path, json } => workspace::blame(&path, json),
626
        Cmd::Bisect { cmd } => match cmd {
627
            BisectCmd::Start => workspace::bisect_start(),
628
            BisectCmd::Good { changes } => workspace::bisect_mark(Some(true), &changes),
629
            BisectCmd::Bad { changes } => workspace::bisect_mark(Some(false), &changes),
630
            BisectCmd::Skip => workspace::bisect_mark(None, &[]),
631
            BisectCmd::Run { command } => workspace::bisect_run(&command),
c6aa5bd9 Andy McCall ↶ 632
            BisectCmd::Status { json } => workspace::bisect_status(json),
957fee30 Andy McCall ↶ 633
            BisectCmd::Reset => workspace::bisect_reset(),
634
        },
75167672 Andy McCall 635
        Cmd::Log {
636
            limit,
637
            verbose,
638
            path,
639
            json,
640
        } => workspace::log(limit, verbose, path.as_deref(), json),
c6aa5bd9 Andy McCall ↶ 641
        Cmd::Diff { change, json } => workspace::diff(change.as_deref(), json),
614541c3 Andy McCall ↶ 642
        Cmd::Describe { message, change } => workspace::describe(&message, change.as_deref()),
23b217d7 Andy McCall ↶ 643
        Cmd::Amend { message, into } => workspace::amend(message.as_deref(), into.as_deref()),
644
        Cmd::Split { change, paths } => workspace::split(&change, &paths),
614541c3 Andy McCall ↶ 645
        Cmd::Abandon { change } => workspace::abandon(&change),
c6aa5bd9 Andy McCall ↶ 646
        Cmd::Show { change, json } => workspace::show(&change, json),
fce44ae9 Andy McCall ↶ 647
        Cmd::Checkout { changes, discard } => workspace::checkout(&changes, discard),
c6aa5bd9 Andy McCall ↶ 648
        Cmd::Resolve { json } => workspace::resolve(json),
fce44ae9 Andy McCall ↶ 649
        Cmd::Undo => workspace::undo(),
ba160f60 Andy McCall ↶ 650
        Cmd::Gc { now } => workspace::gc(now),
252e8cb2 Andy McCall ↶ 651
        Cmd::Checkpoint => workspace::checkpoint(),
75167672 Andy McCall 652
        Cmd::Op {
653
            cmd: OpCmd::Log { json },
654
        } => workspace::op_log(json),
655
        Cmd::Clone {
656
            url,
657
            dest,
658
            max_blob,
659
            sparse,
660
            depth,
661
        } => sync::clone(&url, dest, max_blob.as_deref(), &sparse, depth),
2863456a Andy McCall ↶ 662
        Cmd::Deepen { depth, remote } => sync::deepen(&remote, depth),
7421309f Andy McCall ↶ 663
        Cmd::Sparse { paths } => workspace::sparse(&paths),
cdb5beba Andy McCall ↶ 664
        Cmd::Lock { path } => workspace::lock(&path),
665
        Cmd::Unlock { path } => workspace::unlock(&path),
4e88e774 Andy McCall ↶ 666
        Cmd::Workspace { cmd } => match cmd {
667
            WorkspaceCmd::Add { path, changes } => workspace::workspace_add(&path, &changes),
1196b29b Andy McCall ↶ 668
            WorkspaceCmd::List { json } => workspace::workspace_list(json),
4e88e774 Andy McCall ↶ 669
            WorkspaceCmd::Forget { workspace } => workspace::workspace_forget(&workspace),
670
        },
7b9809e6 Andy McCall ↶ 671
        Cmd::Bookmark { cmd } => match cmd {
672
            BookmarkCmd::Create { name, changes } => workspace::bookmark_create(&name, &changes),
673
            BookmarkCmd::Set { name, changes } => workspace::bookmark_set(&name, &changes),
674
            BookmarkCmd::Delete { name } => workspace::bookmark_delete(&name),
c6aa5bd9 Andy McCall ↶ 675
            BookmarkCmd::List { json } => workspace::bookmark_list(json),
7b9809e6 Andy McCall ↶ 676
            BookmarkCmd::Switch { name, discard } => workspace::bookmark_switch(&name, discard),
677
        },
678
        Cmd::Merge { bookmark } => workspace::merge(&bookmark),
4dee277c Andy McCall ↶ 679
        Cmd::Submodule { cmd } => match cmd {
75167672 Andy McCall 680
            SubmoduleCmd::Add {
681
                url,
682
                path,
683
                bookmark,
684
            } => sync::submodule_add(&url, &path, bookmark.as_deref()),
4dee277c Andy McCall ↶ 685
            SubmoduleCmd::Update { init, paths } => sync::submodule_update(init, &paths),
c6aa5bd9 Andy McCall ↶ 686
            SubmoduleCmd::Status { json } => sync::submodule_status(json),
4dee277c Andy McCall ↶ 687
            SubmoduleCmd::Remove { path } => sync::submodule_remove(&path),
688
        },
132b884b Andy McCall ↶ 689
        Cmd::Tag { cmd } => match cmd {
75167672 Andy McCall 690
            TagCmd::Create {
691
                name,
692
                changes,
693
                message,
694
            } => workspace::tag_create(&name, &changes, &message),
1196b29b Andy McCall ↶ 695
            TagCmd::List { json } => workspace::tag_list(json),
132b884b Andy McCall ↶ 696
        },
fce44ae9 Andy McCall ↶ 697
        Cmd::Remote { cmd } => match cmd {
698
            RemoteCmd::Add { name, url } => sync::remote_add(&name, &url),
699
            RemoteCmd::Remove { name } => sync::remote_remove(&name),
c6aa5bd9 Andy McCall ↶ 700
            RemoteCmd::List { json } => sync::remote_list(json),
fce44ae9 Andy McCall ↶ 701
        },
c6aa5bd9 Andy McCall ↶ 702
        Cmd::Fetch { remote, json } => sync::fetch(remote.as_deref(), json),
703
        Cmd::Pull { remote, json } => sync::pull(remote.as_deref(), json),
75167672 Andy McCall 704
        Cmd::Push {
705
            remote,
706
            force,
707
            bookmark,
708
            json,
709
        } => sync::push(remote.as_deref(), force, bookmark.as_deref(), json),
710
        Cmd::Serve {
711
            root,
712
            bind,
713
            tokens,
714
            tls_cert,
715
            tls_key,
716
        } => sync::serve(root, &bind, tokens, tls_cert.zip(tls_key)),
fce44ae9 Andy McCall ↶ 717
        Cmd::Identity { cmd } => match cmd {
75167672 Andy McCall 718
            IdentityCmd::Create {
719
                name,
720
                email,
721
                local,
722
                expires,
723
            } => identity::create(name, email, local, expires),
fce44ae9 Andy McCall ↶ 724
            IdentityCmd::Show => identity::show(),
83e0677b Andy McCall ↶ 725
            IdentityCmd::Export { path } => identity::export(path),
28fc23d7 Andy McCall ↶ 726
            IdentityCmd::Rotate => identity::rotate(),
727
            IdentityCmd::Renew { expires } => identity::renew(expires),
728
            IdentityCmd::Revoke { key, reason } => identity::revoke(key.as_deref(), &reason),
729
            IdentityCmd::Delegate { cmd } => match cmd {
730
                DelegateCmd::Add { identity_file } => identity::delegate_add(&identity_file),
731
                DelegateCmd::Remove { key } => identity::delegate_remove(&key),
732
                DelegateCmd::List => identity::delegate_list(),
733
            },
83e0677b Andy McCall ↶ 734
        },
75167672 Andy McCall 735
        Cmd::Git {
736
            cmd: GitCmd::Export { git_dir, branch },
737
        } => sync::git_export(&git_dir, branch.as_deref()),
738
        Cmd::Git {
739
            cmd: GitCmd::Fetch { url, branch },
740
        } => sync::git_fetch(&url, &branch),
741
        Cmd::Git {
742
            cmd: GitCmd::Push { url, branch },
743
        } => sync::git_push(&url, &branch),
744
        Cmd::Git {
745
            cmd:
746
                GitCmd::Import {
747
                    git_dir,
748
                    dest,
749
                    branch,
750
                },
751
        } => sync::git_import(&git_dir, &dest, &branch),
83e0677b Andy McCall ↶ 752
        Cmd::Policy { cmd } => match cmd {
753
            PolicyCmd::Init => identity::policy_init(),
c6aa5bd9 Andy McCall ↶ 754
            PolicyCmd::Show { json } => identity::policy_show(json),
75167672 Andy McCall 755
            PolicyCmd::Grant {
756
                identity_file,
757
                pattern,
758
                out,
759
            } => identity::policy_grant(&identity_file, pattern.as_deref(), out),
28fc23d7 Andy McCall ↶ 760
            PolicyCmd::Revoke { key, out } => identity::policy_revoke(&key, out),
761
            PolicyCmd::Root { cmd } => match cmd {
75167672 Andy McCall 762
                RootCmd::Add { identity_file, out } => {
763
                    identity::policy_root_add(&identity_file, out)
764
                }
28fc23d7 Andy McCall ↶ 765
                RootCmd::Remove { key, out } => identity::policy_root_remove(&key, out),
766
                RootCmd::Threshold { n, out } => identity::policy_threshold(n, out),
767
            },
768
            PolicyCmd::Sign { proposal, out } => identity::policy_sign(&proposal, out),
fce44ae9 Andy McCall ↶ 769
        },
05e71ed6 Andy McCall ↶ 770
        Cmd::Seal { changes, json } => identity::seal(&changes, json),
c6aa5bd9 Andy McCall ↶ 771
        Cmd::Verify { change, json } => identity::verify(change.as_deref(), json),
fce44ae9 Andy McCall ↶ 772
        Cmd::Config { key, value, user } => identity::config(&key, &value, user),
773
    }
774
}