OXYGENHUB
# eae595568832 oxygen / src / cli / mod.rs
25.9 KiB · Rust · last changed State is Send + Sync; shared lane layout; log_window 1 month ago source blame history raw
1
//! Command-line definitions and dispatch.
2
3
mod format;
4
mod identity;
5
mod json;
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(
17
    name = "oxy",
18
    version,
19
    about = "Oxygen: breathing fresh air into version control"
20
)]
21
struct Cli {
22
    /// Plain output: no colour, no spinner (also implied by NO_COLOR or a non-terminal)
23
    #[arg(long, global = true)]
24
    plain: bool,
25
    #[command(subcommand)]
26
    cmd: Cmd,
27
}
28
29
#[derive(Subcommand)]
30
enum Cmd {
31
    /// Create a repository in PATH (default: current directory)
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
    },
38
    /// Clone a repository from a local path or an http(s) URL
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>,
45
        /// Materialize only these paths (repeatable); implies lazy blobs
46
        #[arg(long = "sparse")]
47
        sparse: Vec<String>,
48
        /// Shallow clone: fetch only this many levels of history below the heads
49
        #[arg(long)]
50
        depth: Option<u32>,
51
    },
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
    },
59
    /// Show or set the sparse filter (paths to materialize); re-checks out the bookmark
60
    Sparse { paths: Vec<String> },
61
    /// Show the working copy: changed paths and conflicts
62
    Status {
63
        /// Machine-readable output: paths, and every conflict with its kind and contributing changes
64
        #[arg(long)]
65
        json: bool,
66
    },
67
    /// One-line summary for shell prompts; fast and records nothing
68
    Prompt {
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
70
        #[arg(long, default_value = oxy_core::repo::DEFAULT_PROMPT_FORMAT)]
71
        format: String,
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>,
78
    },
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>,
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,
91
        /// Commit these hunks (as `oxy hunks` numbers them), comma separated
92
        #[arg(long, value_delimiter = ',')]
93
        hunks: Vec<usize>,
94
    },
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
    },
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
    },
119
    /// List changes reachable from the bookmark and the working copy
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,
127
        /// Only changes touching this path (renames followed)
128
        #[arg(long)]
129
        path: Option<String>,
130
        #[arg(long)]
131
        json: bool,
132
    },
133
    /// Show what the working copy changes against its base
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
    },
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
    },
175
    /// Fold the working copy into the head it sits on, or into CHANGE with --into
176
    Amend {
177
        #[arg(short, long)]
178
        message: Option<String>,
179
        /// Amend an older change; the edits must touch only lines it already knows
180
        #[arg(long)]
181
        into: Option<String>,
182
    },
183
    /// Split a head: the named paths become a separate first change
184
    Split { change: String, paths: Vec<String> },
185
    /// Drop a head from the bookmark; its content stays on disk as uncommitted work
186
    Abandon { change: String },
187
    /// Show one change (ChangeId prefix, #hash prefix, or @)
188
    Show {
189
        change: String,
190
        #[arg(long)]
191
        json: bool,
192
    },
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
201
    Resolve {
202
        #[arg(long)]
203
        json: bool,
204
    },
205
    /// Undo the last operation
206
    Undo,
207
    /// Write a checkpoint of the current bookmark's state now
208
    Checkpoint,
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
    },
215
    /// List operations
216
    #[command(name = "op")]
217
    Op {
218
        #[command(subcommand)]
219
        cmd: OpCmd,
220
    },
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 },
225
    /// Workspaces: extra checkout directories sharing this repository
226
    Workspace {
227
        #[command(subcommand)]
228
        cmd: WorkspaceCmd,
229
    },
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 },
237
    /// Subrepositories: nested repositories pinned to a state
238
    Submodule {
239
        #[command(subcommand)]
240
        cmd: SubmoduleCmd,
241
    },
242
    /// Tags: immutable named states
243
    Tag {
244
        #[command(subcommand)]
245
        cmd: TagCmd,
246
    },
247
    /// Manage remotes
248
    Remote {
249
        #[command(subcommand)]
250
        cmd: RemoteCmd,
251
    },
252
    /// Fetch every bookmark of a remote into its tracking references
253
    Fetch {
254
        remote: Option<String>,
255
        #[arg(long)]
256
        json: bool,
257
    },
258
    /// Fetch, then union the remote bookmark into the local one (no merge change)
259
    Pull {
260
        remote: Option<String>,
261
        #[arg(long)]
262
        json: bool,
263
    },
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,
270
        /// Push this bookmark instead of the workspace's current one
271
        #[arg(short = 'b', long)]
272
        bookmark: Option<String>,
273
        #[arg(long)]
274
        json: bool,
275
    },
276
    /// Serve repositories under ROOT over HTTPS (with --tls-cert/--tls-key) or plain HTTP
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>,
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>,
292
    },
293
    /// Manage the signing identity
294
    Identity {
295
        #[command(subcommand)]
296
        cmd: IdentityCmd,
297
    },
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
    },
304
    /// Verify the signatures on a change (default: every change in the log)
305
    Verify {
306
        change: Option<String>,
307
        #[arg(long)]
308
        json: bool,
309
    },
310
    /// Git interoperability
311
    Git {
312
        #[command(subcommand)]
313
        cmd: GitCmd,
314
    },
315
    /// Manage the trust policy (who may update which bookmarks)
316
    Policy {
317
        #[command(subcommand)]
318
        cmd: PolicyCmd,
319
    },
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)
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 {
332
    Log {
333
        #[arg(long)]
334
        json: bool,
335
    },
336
}
337
338
#[derive(Subcommand)]
339
enum WorkspaceCmd {
340
    /// Create a workspace at PATH checked out on CHANGE... (default: the bookmark heads)
341
    Add { path: PathBuf, changes: Vec<String> },
342
    List {
343
        #[arg(long)]
344
        json: bool,
345
    },
346
    /// Stop tracking a workspace (by id prefix or path); its files stay
347
    Forget { workspace: String },
348
}
349
350
#[derive(Subcommand)]
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
366
    Status {
367
        #[arg(long)]
368
        json: bool,
369
    },
370
    /// Restore the working copy and forget the search
371
    Reset,
372
}
373
374
#[derive(Subcommand)]
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
383
    List {
384
        #[arg(long)]
385
        json: bool,
386
    },
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)]
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
414
    Status {
415
        #[arg(long)]
416
        json: bool,
417
    },
418
    /// Unregister PATH; the directory stays, the node goes with the next commit
419
    Remove { path: String },
420
}
421
422
#[derive(Subcommand)]
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
    },
431
    List {
432
        #[arg(long)]
433
        json: bool,
434
    },
435
}
436
437
#[derive(Subcommand)]
438
enum RemoteCmd {
439
    Add {
440
        name: String,
441
        url: String,
442
    },
443
    Remove {
444
        name: String,
445
    },
446
    List {
447
        #[arg(long)]
448
        json: bool,
449
    },
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,
463
        /// Expire the identity this many days from now
464
        #[arg(long)]
465
        expires: Option<u64>,
466
    },
467
    /// Show the configured identity
468
    Show,
469
    /// Write your identity object to a file, to hand to a policy holder
470
    Export { path: Option<PathBuf> },
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
    },
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,
506
}
507
508
#[derive(Subcommand)]
509
enum GitCmd {
510
    /// Export the current bookmark to a Git repository (created bare if absent)
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
    },
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
    },
536
}
537
538
#[derive(Subcommand)]
539
enum PolicyCmd {
540
    /// Create the initial policy with your identity as the only root
541
    Init,
542
    /// Show the current policy
543
    Show {
544
        #[arg(long)]
545
        json: bool,
546
    },
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>,
553
        /// Where to write the proposal when more root signatures are needed
554
        #[arg(long)]
555
        out: Option<PathBuf>,
556
    },
557
    /// Revoke a key (KeyId prefix of an identity in the policy)
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
    },
598
}
599
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();
608
    ui::init(cli.plain);
609
    match cli.cmd {
610
        Cmd::Init { path, bare } => workspace::init(path, bare),
611
        Cmd::Status { json } => workspace::status(json),
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),
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),
629
        Cmd::Squash { change, into } => workspace::squash(&change, &into),
630
        Cmd::Rebase { change, onto } => workspace::rebase(&change, &onto),
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),
638
            BisectCmd::Status { json } => workspace::bisect_status(json),
639
            BisectCmd::Reset => workspace::bisect_reset(),
640
        },
641
        Cmd::Log {
642
            limit,
643
            verbose,
644
            path,
645
            json,
646
        } => workspace::log(limit, verbose, path.as_deref(), json),
647
        Cmd::Diff { change, json } => workspace::diff(change.as_deref(), json),
648
        Cmd::Describe { message, change } => workspace::describe(&message, change.as_deref()),
649
        Cmd::Amend { message, into } => workspace::amend(message.as_deref(), into.as_deref()),
650
        Cmd::Split { change, paths } => workspace::split(&change, &paths),
651
        Cmd::Abandon { change } => workspace::abandon(&change),
652
        Cmd::Show { change, json } => workspace::show(&change, json),
653
        Cmd::Checkout { changes, discard } => workspace::checkout(&changes, discard),
654
        Cmd::Resolve { json } => workspace::resolve(json),
655
        Cmd::Undo => workspace::undo(),
656
        Cmd::Gc { now } => workspace::gc(now),
657
        Cmd::Checkpoint => workspace::checkpoint(),
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),
668
        Cmd::Deepen { depth, remote } => sync::deepen(&remote, depth),
669
        Cmd::Sparse { paths } => workspace::sparse(&paths),
670
        Cmd::Lock { path } => workspace::lock(&path),
671
        Cmd::Unlock { path } => workspace::unlock(&path),
672
        Cmd::Workspace { cmd } => match cmd {
673
            WorkspaceCmd::Add { path, changes } => workspace::workspace_add(&path, &changes),
674
            WorkspaceCmd::List { json } => workspace::workspace_list(json),
675
            WorkspaceCmd::Forget { workspace } => workspace::workspace_forget(&workspace),
676
        },
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),
681
            BookmarkCmd::List { json } => workspace::bookmark_list(json),
682
            BookmarkCmd::Switch { name, discard } => workspace::bookmark_switch(&name, discard),
683
        },
684
        Cmd::Merge { bookmark } => workspace::merge(&bookmark),
685
        Cmd::Submodule { cmd } => match cmd {
686
            SubmoduleCmd::Add {
687
                url,
688
                path,
689
                bookmark,
690
            } => sync::submodule_add(&url, &path, bookmark.as_deref()),
691
            SubmoduleCmd::Update { init, paths } => sync::submodule_update(init, &paths),
692
            SubmoduleCmd::Status { json } => sync::submodule_status(json),
693
            SubmoduleCmd::Remove { path } => sync::submodule_remove(&path),
694
        },
695
        Cmd::Tag { cmd } => match cmd {
696
            TagCmd::Create {
697
                name,
698
                changes,
699
                message,
700
            } => workspace::tag_create(&name, &changes, &message),
701
            TagCmd::List { json } => workspace::tag_list(json),
702
        },
703
        Cmd::Remote { cmd } => match cmd {
704
            RemoteCmd::Add { name, url } => sync::remote_add(&name, &url),
705
            RemoteCmd::Remove { name } => sync::remote_remove(&name),
706
            RemoteCmd::List { json } => sync::remote_list(json),
707
        },
708
        Cmd::Fetch { remote, json } => sync::fetch(remote.as_deref(), json),
709
        Cmd::Pull { remote, json } => sync::pull(remote.as_deref(), json),
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)),
723
        Cmd::Identity { cmd } => match cmd {
724
            IdentityCmd::Create {
725
                name,
726
                email,
727
                local,
728
                expires,
729
            } => identity::create(name, email, local, expires),
730
            IdentityCmd::Show => identity::show(),
731
            IdentityCmd::Export { path } => identity::export(path),
732
            IdentityCmd::SignChallenge { challenge, json } => {
733
                identity::sign_challenge(&challenge, json)
734
            }
735
            IdentityCmd::Rotate => identity::rotate(),
736
            IdentityCmd::Renew { expires } => identity::renew(expires),
737
            IdentityCmd::Revoke { key, reason } => identity::revoke(key.as_deref(), &reason),
738
            IdentityCmd::Delegate { cmd } => match cmd {
739
                DelegateCmd::Add { identity_file } => identity::delegate_add(&identity_file),
740
                DelegateCmd::Remove { key } => identity::delegate_remove(&key),
741
                DelegateCmd::List => identity::delegate_list(),
742
            },
743
        },
744
        Cmd::Git {
745
            cmd: GitCmd::Export { git_dir, branch },
746
        } => sync::git_export(&git_dir, branch.as_deref()),
747
        Cmd::Git {
748
            cmd: GitCmd::Fetch { url, branch },
749
        } => sync::git_fetch(&url, &branch),
750
        Cmd::Git {
751
            cmd: GitCmd::Push { url, branch },
752
        } => sync::git_push(&url, &branch),
753
        Cmd::Git {
754
            cmd:
755
                GitCmd::Import {
756
                    git_dir,
757
                    dest,
758
                    branch,
759
                },
760
        } => sync::git_import(&git_dir, &dest, &branch),
761
        Cmd::Policy { cmd } => match cmd {
762
            PolicyCmd::Init => identity::policy_init(),
763
            PolicyCmd::Show { json } => identity::policy_show(json),
764
            PolicyCmd::Grant {
765
                identity_file,
766
                pattern,
767
                out,
768
            } => identity::policy_grant(&identity_file, pattern.as_deref(), out),
769
            PolicyCmd::Revoke { key, out } => identity::policy_revoke(&key, out),
770
            PolicyCmd::Root { cmd } => match cmd {
771
                RootCmd::Add { identity_file, out } => {
772
                    identity::policy_root_add(&identity_file, out)
773
                }
774
                RootCmd::Remove { key, out } => identity::policy_root_remove(&key, out),
775
                RootCmd::Threshold { n, out } => identity::policy_threshold(n, out),
776
            },
777
            PolicyCmd::Sign { proposal, out } => identity::policy_sign(&proposal, out),
778
        },
779
        Cmd::Seal { changes, json } => identity::seal(&changes, json),
780
        Cmd::Verify { change, json } => identity::verify(change.as_deref(), json),
781
        Cmd::Config { key, value, user } => identity::config(&key, &value, user),
782
    }
783
}