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