OXYGENHUB
# 84b9e9ac0ab4 oxygen / src / cli / mod.rs
25.8 KiB · Rust · last changed Challenge signatures and a push report for hosts 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> },
7aa2dc93 Andy McCall ↶ 471
    /// Sign a host's challenge (hex, at least 16 bytes) to prove you hold your key; prints the signature as hex
472
    SignChallenge {
473
        challenge: String,
474
        #[arg(long)]
475
        json: bool,
476
    },
28fc23d7 Andy McCall ↶ 477
    /// Move to a fresh key pair; the policy follows if it names your key
478
    Rotate,
479
    /// Re-issue your identity with a new expiry (in days from now; 0 = never)
480
    Renew {
481
        #[arg(long)]
482
        expires: u64,
483
    },
484
    /// Revoke a key: yours by default, or any key if you hold a policy root
485
    Revoke {
486
        /// KeyId prefix (default: your own key)
487
        key: Option<String>,
488
        #[arg(long, default_value = "")]
489
        reason: String,
490
    },
491
    /// Keys allowed to sign or seal on your behalf
492
    Delegate {
493
        #[command(subcommand)]
494
        cmd: DelegateCmd,
495
    },
496
}
497
498
#[derive(Subcommand)]
499
enum DelegateCmd {
500
    /// Add a delegate from an exported identity file
501
    Add { identity_file: PathBuf },
502
    /// Remove a delegate by KeyId prefix
503
    Remove { key: String },
504
    /// List delegates
505
    List,
fce44ae9 Andy McCall ↶ 506
}
507
83e0677b Andy McCall ↶ 508
#[derive(Subcommand)]
79ab8528 Andy McCall ↶ 509
enum GitCmd {
510
    /// Export the current bookmark to a Git repository (created bare if absent)
30ea9c1e Andy McCall ↶ 511
    Export {
512
        git_dir: PathBuf,
513
        /// Git branch to write (default: the bookmark name)
514
        #[arg(long)]
515
        branch: Option<String>,
516
    },
517
    /// Fetch a branch from a Git remote (path or URL) into the current bookmark
518
    Fetch {
519
        url: String,
520
        #[arg(long, default_value = "main")]
521
        branch: String,
522
    },
523
    /// Push the current bookmark to a branch of a Git remote (fetch first)
524
    Push {
525
        url: String,
526
        #[arg(long, default_value = "main")]
527
        branch: String,
528
    },
c3069537 Andy McCall ↶ 529
    /// Import a Git branch into a new Oxygen repository at DEST
530
    Import {
531
        git_dir: PathBuf,
532
        dest: PathBuf,
533
        #[arg(long, default_value = "main")]
534
        branch: String,
535
    },
79ab8528 Andy McCall ↶ 536
}
537
538
#[derive(Subcommand)]
83e0677b Andy McCall ↶ 539
enum PolicyCmd {
540
    /// Create the initial policy with your identity as the only root
541
    Init,
542
    /// Show the current policy
c6aa5bd9 Andy McCall ↶ 543
    Show {
544
        #[arg(long)]
545
        json: bool,
546
    },
83e0677b Andy McCall ↶ 547
    /// Allow an identity (from `oxy identity export`) to update bookmarks
548
    Grant {
549
        identity_file: PathBuf,
550
        /// Reference pattern the grant applies to (default: every bookmark)
551
        #[arg(long)]
552
        pattern: Option<String>,
28fc23d7 Andy McCall ↶ 553
        /// Where to write the proposal when more root signatures are needed
554
        #[arg(long)]
555
        out: Option<PathBuf>,
83e0677b Andy McCall ↶ 556
    },
557
    /// Revoke a key (KeyId prefix of an identity in the policy)
28fc23d7 Andy McCall ↶ 558
    Revoke {
559
        key: String,
560
        /// Where to write the proposal when more root signatures are needed
561
        #[arg(long)]
562
        out: Option<PathBuf>,
563
    },
564
    /// Manage root keys and the signature threshold for policy updates
565
    Root {
566
        #[command(subcommand)]
567
        cmd: RootCmd,
568
    },
569
    /// Add your root signature to a proposal file; applies it once the threshold is met
570
    Sign {
571
        proposal: PathBuf,
572
        /// Where to write the proposal if it still needs signatures (default: in place)
573
        #[arg(long)]
574
        out: Option<PathBuf>,
575
    },
576
}
577
578
#[derive(Subcommand)]
579
enum RootCmd {
580
    /// Make an exported identity a root key
581
    Add {
582
        identity_file: PathBuf,
583
        #[arg(long)]
584
        out: Option<PathBuf>,
585
    },
586
    /// Remove a root key by KeyId prefix
587
    Remove {
588
        key: String,
589
        #[arg(long)]
590
        out: Option<PathBuf>,
591
    },
592
    /// Require this many root signatures on policy updates
593
    Threshold {
594
        n: u32,
595
        #[arg(long)]
596
        out: Option<PathBuf>,
597
    },
83e0677b Andy McCall ↶ 598
}
599
fce44ae9 Andy McCall ↶ 600
/// Open the repository containing the current directory.
601
fn open() -> Result<Repo> {
602
    Repo::open(&std::env::current_dir()?).context("opening repository")
603
}
604
605
/// Parse arguments and run; returns the process exit code.
606
pub fn run() -> Result<i32> {
607
    let cli = Cli::parse();
135212de Andy McCall ↶ 608
    ui::init(cli.plain);
fce44ae9 Andy McCall ↶ 609
    match cli.cmd {
e02bf0cd Andy McCall ↶ 610
        Cmd::Init { path, bare } => workspace::init(path, bare),
50a046e4 Andy McCall ↶ 611
        Cmd::Status { json } => workspace::status(json),
75167672 Andy McCall 612
        Cmd::Prompt {
613
            format,
614
            glyphs,
615
            color,
616
        } => workspace::prompt(&format, glyphs, color.as_deref()),
617
        Cmd::Commit {
618
            message,
619
            depends_on,
620
            paths,
621
            interactive,
622
            hunks,
623
        } => workspace::commit(&message, &depends_on, &paths, interactive, &hunks),
c6aa5bd9 Andy McCall ↶ 624
        Cmd::Cat { path, change } => workspace::cat(&path, change.as_deref()),
625
        Cmd::Root { json } => workspace::root(json),
626
        Cmd::Version { json } => workspace::version(json),
627
        Cmd::Discard { paths, hunks } => workspace::discard(&paths, &hunks),
628
        Cmd::Hunks { json } => workspace::hunks(json),
728da0f9 Andy McCall ↶ 629
        Cmd::Squash { change, into } => workspace::squash(&change, &into),
630
        Cmd::Rebase { change, onto } => workspace::rebase(&change, &onto),
957fee30 Andy McCall ↶ 631
        Cmd::Blame { path, json } => workspace::blame(&path, json),
632
        Cmd::Bisect { cmd } => match cmd {
633
            BisectCmd::Start => workspace::bisect_start(),
634
            BisectCmd::Good { changes } => workspace::bisect_mark(Some(true), &changes),
635
            BisectCmd::Bad { changes } => workspace::bisect_mark(Some(false), &changes),
636
            BisectCmd::Skip => workspace::bisect_mark(None, &[]),
637
            BisectCmd::Run { command } => workspace::bisect_run(&command),
c6aa5bd9 Andy McCall ↶ 638
            BisectCmd::Status { json } => workspace::bisect_status(json),
957fee30 Andy McCall ↶ 639
            BisectCmd::Reset => workspace::bisect_reset(),
640
        },
75167672 Andy McCall 641
        Cmd::Log {
642
            limit,
643
            verbose,
644
            path,
645
            json,
646
        } => workspace::log(limit, verbose, path.as_deref(), json),
c6aa5bd9 Andy McCall ↶ 647
        Cmd::Diff { change, json } => workspace::diff(change.as_deref(), json),
614541c3 Andy McCall ↶ 648
        Cmd::Describe { message, change } => workspace::describe(&message, change.as_deref()),
23b217d7 Andy McCall ↶ 649
        Cmd::Amend { message, into } => workspace::amend(message.as_deref(), into.as_deref()),
650
        Cmd::Split { change, paths } => workspace::split(&change, &paths),
614541c3 Andy McCall ↶ 651
        Cmd::Abandon { change } => workspace::abandon(&change),
c6aa5bd9 Andy McCall ↶ 652
        Cmd::Show { change, json } => workspace::show(&change, json),
fce44ae9 Andy McCall ↶ 653
        Cmd::Checkout { changes, discard } => workspace::checkout(&changes, discard),
c6aa5bd9 Andy McCall ↶ 654
        Cmd::Resolve { json } => workspace::resolve(json),
fce44ae9 Andy McCall ↶ 655
        Cmd::Undo => workspace::undo(),
ba160f60 Andy McCall ↶ 656
        Cmd::Gc { now } => workspace::gc(now),
252e8cb2 Andy McCall ↶ 657
        Cmd::Checkpoint => workspace::checkpoint(),
75167672 Andy McCall 658
        Cmd::Op {
659
            cmd: OpCmd::Log { json },
660
        } => workspace::op_log(json),
661
        Cmd::Clone {
662
            url,
663
            dest,
664
            max_blob,
665
            sparse,
666
            depth,
667
        } => sync::clone(&url, dest, max_blob.as_deref(), &sparse, depth),
2863456a Andy McCall ↶ 668
        Cmd::Deepen { depth, remote } => sync::deepen(&remote, depth),
7421309f Andy McCall ↶ 669
        Cmd::Sparse { paths } => workspace::sparse(&paths),
cdb5beba Andy McCall ↶ 670
        Cmd::Lock { path } => workspace::lock(&path),
671
        Cmd::Unlock { path } => workspace::unlock(&path),
4e88e774 Andy McCall ↶ 672
        Cmd::Workspace { cmd } => match cmd {
673
            WorkspaceCmd::Add { path, changes } => workspace::workspace_add(&path, &changes),
1196b29b Andy McCall ↶ 674
            WorkspaceCmd::List { json } => workspace::workspace_list(json),
4e88e774 Andy McCall ↶ 675
            WorkspaceCmd::Forget { workspace } => workspace::workspace_forget(&workspace),
676
        },
7b9809e6 Andy McCall ↶ 677
        Cmd::Bookmark { cmd } => match cmd {
678
            BookmarkCmd::Create { name, changes } => workspace::bookmark_create(&name, &changes),
679
            BookmarkCmd::Set { name, changes } => workspace::bookmark_set(&name, &changes),
680
            BookmarkCmd::Delete { name } => workspace::bookmark_delete(&name),
c6aa5bd9 Andy McCall ↶ 681
            BookmarkCmd::List { json } => workspace::bookmark_list(json),
7b9809e6 Andy McCall ↶ 682
            BookmarkCmd::Switch { name, discard } => workspace::bookmark_switch(&name, discard),
683
        },
684
        Cmd::Merge { bookmark } => workspace::merge(&bookmark),
4dee277c Andy McCall ↶ 685
        Cmd::Submodule { cmd } => match cmd {
75167672 Andy McCall 686
            SubmoduleCmd::Add {
687
                url,
688
                path,
689
                bookmark,
690
            } => sync::submodule_add(&url, &path, bookmark.as_deref()),
4dee277c Andy McCall ↶ 691
            SubmoduleCmd::Update { init, paths } => sync::submodule_update(init, &paths),
c6aa5bd9 Andy McCall ↶ 692
            SubmoduleCmd::Status { json } => sync::submodule_status(json),
4dee277c Andy McCall ↶ 693
            SubmoduleCmd::Remove { path } => sync::submodule_remove(&path),
694
        },
132b884b Andy McCall ↶ 695
        Cmd::Tag { cmd } => match cmd {
75167672 Andy McCall 696
            TagCmd::Create {
697
                name,
698
                changes,
699
                message,
700
            } => workspace::tag_create(&name, &changes, &message),
1196b29b Andy McCall ↶ 701
            TagCmd::List { json } => workspace::tag_list(json),
132b884b Andy McCall ↶ 702
        },
fce44ae9 Andy McCall ↶ 703
        Cmd::Remote { cmd } => match cmd {
704
            RemoteCmd::Add { name, url } => sync::remote_add(&name, &url),
705
            RemoteCmd::Remove { name } => sync::remote_remove(&name),
c6aa5bd9 Andy McCall ↶ 706
            RemoteCmd::List { json } => sync::remote_list(json),
fce44ae9 Andy McCall ↶ 707
        },
c6aa5bd9 Andy McCall ↶ 708
        Cmd::Fetch { remote, json } => sync::fetch(remote.as_deref(), json),
709
        Cmd::Pull { remote, json } => sync::pull(remote.as_deref(), json),
75167672 Andy McCall 710
        Cmd::Push {
711
            remote,
712
            force,
713
            bookmark,
714
            json,
715
        } => sync::push(remote.as_deref(), force, bookmark.as_deref(), json),
716
        Cmd::Serve {
717
            root,
718
            bind,
719
            tokens,
720
            tls_cert,
721
            tls_key,
722
        } => sync::serve(root, &bind, tokens, tls_cert.zip(tls_key)),
fce44ae9 Andy McCall ↶ 723
        Cmd::Identity { cmd } => match cmd {
75167672 Andy McCall 724
            IdentityCmd::Create {
725
                name,
726
                email,
727
                local,
728
                expires,
729
            } => identity::create(name, email, local, expires),
fce44ae9 Andy McCall ↶ 730
            IdentityCmd::Show => identity::show(),
83e0677b Andy McCall ↶ 731
            IdentityCmd::Export { path } => identity::export(path),
7aa2dc93 Andy McCall ↶ 732
            IdentityCmd::SignChallenge { challenge, json } => identity::sign_challenge(&challenge, json),
28fc23d7 Andy McCall ↶ 733
            IdentityCmd::Rotate => identity::rotate(),
734
            IdentityCmd::Renew { expires } => identity::renew(expires),
735
            IdentityCmd::Revoke { key, reason } => identity::revoke(key.as_deref(), &reason),
736
            IdentityCmd::Delegate { cmd } => match cmd {
737
                DelegateCmd::Add { identity_file } => identity::delegate_add(&identity_file),
738
                DelegateCmd::Remove { key } => identity::delegate_remove(&key),
739
                DelegateCmd::List => identity::delegate_list(),
740
            },
83e0677b Andy McCall ↶ 741
        },
75167672 Andy McCall 742
        Cmd::Git {
743
            cmd: GitCmd::Export { git_dir, branch },
744
        } => sync::git_export(&git_dir, branch.as_deref()),
745
        Cmd::Git {
746
            cmd: GitCmd::Fetch { url, branch },
747
        } => sync::git_fetch(&url, &branch),
748
        Cmd::Git {
749
            cmd: GitCmd::Push { url, branch },
750
        } => sync::git_push(&url, &branch),
751
        Cmd::Git {
752
            cmd:
753
                GitCmd::Import {
754
                    git_dir,
755
                    dest,
756
                    branch,
757
                },
758
        } => sync::git_import(&git_dir, &dest, &branch),
83e0677b Andy McCall ↶ 759
        Cmd::Policy { cmd } => match cmd {
760
            PolicyCmd::Init => identity::policy_init(),
c6aa5bd9 Andy McCall ↶ 761
            PolicyCmd::Show { json } => identity::policy_show(json),
75167672 Andy McCall 762
            PolicyCmd::Grant {
763
                identity_file,
764
                pattern,
765
                out,
766
            } => identity::policy_grant(&identity_file, pattern.as_deref(), out),
28fc23d7 Andy McCall ↶ 767
            PolicyCmd::Revoke { key, out } => identity::policy_revoke(&key, out),
768
            PolicyCmd::Root { cmd } => match cmd {
75167672 Andy McCall 769
                RootCmd::Add { identity_file, out } => {
770
                    identity::policy_root_add(&identity_file, out)
771
                }
28fc23d7 Andy McCall ↶ 772
                RootCmd::Remove { key, out } => identity::policy_root_remove(&key, out),
773
                RootCmd::Threshold { n, out } => identity::policy_threshold(n, out),
774
            },
775
            PolicyCmd::Sign { proposal, out } => identity::policy_sign(&proposal, out),
fce44ae9 Andy McCall ↶ 776
        },
05e71ed6 Andy McCall ↶ 777
        Cmd::Seal { changes, json } => identity::seal(&changes, json),
c6aa5bd9 Andy McCall ↶ 778
        Cmd::Verify { change, json } => identity::verify(change.as_deref(), json),
fce44ae9 Andy McCall ↶ 779
        Cmd::Config { key, value, user } => identity::config(&key, &value, user),
780
    }
781
}