solverforge-cli 2.2.2

CLI for scaffolding and managing SolverForge constraint solver projects
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
use clap::{Args, CommandFactory, Parser, Subcommand};
use clap_complete::Shell;

mod app_spec;
mod commands;
mod error;
mod managed_block;
mod model_contract;
mod model_id;
mod output;
mod rc;
mod scaffold_target;
mod scalar_variable_hooks;
mod solver_config;
mod template;
#[cfg(test)]
mod test_support;

use commands::model_resource::{ConflictRepairRequest, ScalarGroupRequest};
use commands::new::ScaffoldShell;
use error::CliResult;
use scaffold_target::LONG_VERSION_TEXT;
use scalar_variable_hooks::ScalarVariableHooks;

const CLI_VERSION: &str = env!("CARGO_PKG_VERSION");

fn parse_variable_kind(value: &str) -> Result<String, String> {
    match value {
        "scalar" => Ok("scalar".to_string()),
        "list" => Ok("list".to_string()),
        _ => Err("valid values: scalar, list".to_string()),
    }
}

const EXAMPLES: &str = "\x1b[1mExamples:\x1b[0m
  solverforge new my-optimizer
  solverforge new batch-optimizer --shell cli
  solverforge generate entity shift --planning-variable employee_idx
  solverforge generate constraint no_overlap --pair --hard
  solverforge server
  solverforge info
  solverforge check
  solverforge test
  solverforge routes
  solverforge config show";

#[derive(Parser)]
#[command(
    name = "solverforge",
    about = "CLI for scaffolding and managing SolverForge projects",
    version = CLI_VERSION,
    long_version = LONG_VERSION_TEXT,
    infer_subcommands = true,
    after_help = EXAMPLES,
)]
struct Cli {
    /// Suppress all output except errors
    #[arg(long, short, global = true)]
    quiet: bool,

    /// Show extra diagnostic output
    #[arg(long, short, global = true)]
    verbose: bool,

    /// Disable colored output (also respects NO_COLOR env var)
    #[arg(long, global = true)]
    no_color: bool,

    #[command(subcommand)]
    command: Command,
}

#[derive(Subcommand)]
enum Command {
    /// Scaffold a new SolverForge project
    #[command(
        after_help = "Examples:\n  solverforge new my-optimizer\n  solverforge new batch-optimizer --shell cli\n  solverforge new api-optimizer --shell api"
    )]
    New {
        /// Project name (directory that will be created)
        name: String,

        /// Generated shell: web, api, or cli
        #[arg(long, value_enum, default_value_t = ScaffoldShell::Web)]
        shell: ScaffoldShell,

        /// Skip running `git init` and initial commit
        #[arg(long)]
        skip_git: bool,

        /// Skip generating README.md
        #[arg(long)]
        skip_readme: bool,
    },
    /// Generate a new resource for the current project
    #[command(
        after_help = "Examples:\n  solverforge generate entity shift --planning-variable employee_idx\n  solverforge generate fact employee\n  solverforge generate constraint no_overlap --pair --hard\n  solverforge generate solution schedule --score HardSoftScore\n  solverforge generate data\n  solverforge generate data --size large\n  solverforge generate data --mode stub"
    )]
    Generate {
        #[command(subcommand)]
        resource: Box<GenerateResource>,
    },
    /// Remove a resource from the current project
    #[command(
        after_help = "Examples:\n  solverforge destroy entity shift\n  solverforge destroy constraint no_overlap"
    )]
    Destroy {
        /// Skip confirmation prompt
        #[arg(long, short)]
        yes: bool,

        #[command(subcommand)]
        resource: DestroyResource,
    },
    /// Start the development server
    #[command(
        after_help = "Examples:\n  solverforge server\n  solverforge server --port 8080\n  solverforge server --debug"
    )]
    Server {
        /// Port to bind the server to
        #[arg(long, short, default_value = "7860")]
        port: u16,

        /// Run in debug mode (faster compilation, slower runtime)
        #[arg(long)]
        debug: bool,
    },
    /// Show project summary: entities, facts, constraints, score type
    #[command(after_help = "Examples:\n  solverforge info")]
    Info,
    /// Validate project structure and configuration
    #[command(after_help = "Examples:\n  solverforge check")]
    Check,
    /// Run `cargo test` with optional passthrough arguments
    #[command(
        after_help = "Examples:\n  solverforge test\n  solverforge test -- --nocapture\n  solverforge test integration"
    )]
    Test {
        /// Extra arguments passed directly to `cargo test`
        #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
        extra_args: Vec<String>,
    },
    /// List HTTP routes defined in src/api/
    #[command(after_help = "Examples:\n  solverforge routes")]
    Routes,
    /// Manage solver configuration (solver.toml)
    #[command(
        after_help = "Examples:\n  solverforge config show\n  solverforge config set termination.seconds_spent_limit 60"
    )]
    Config {
        #[command(subcommand)]
        subcommand: ConfigSubcommand,
    },
    /// Generate shell completions
    #[command(
        after_help = "Examples:\n  solverforge completions bash >> ~/.bashrc\n  solverforge completions zsh >> ~/.zshrc\n  solverforge completions fish > ~/.config/fish/completions/solverforge.fish"
    )]
    Completions {
        /// Shell to generate completions for
        shell: Shell,
    },
}

#[derive(Subcommand)]
enum ConfigSubcommand {
    /// Print the contents of solver.toml
    Show,
    /// Set a key in solver.toml (e.g. termination.seconds_spent_limit = 60)
    Set {
        /// Dotted key path (e.g. termination.seconds_spent_limit)
        key: String,
        /// New value
        value: String,
    },
}

#[derive(Subcommand)]
enum GenerateResource {
    /// Add a new constraint skeleton to src/constraints/
    #[command(
        after_help = "Examples:\n  solverforge generate constraint max_hours --unary --hard\n  solverforge generate constraint no_overlap --pair\n  solverforge generate constraint required_skill --join --hard"
    )]
    Constraint {
        /// Constraint module name in snake_case (e.g. max_hours)
        name: String,

        /// Hard constraint — must be satisfied (default)
        #[arg(long, conflicts_with = "soft")]
        hard: bool,

        /// Soft constraint — should be optimized
        #[arg(long, conflicts_with = "hard")]
        soft: bool,

        /// Penalize matching entities (for_each + filter + penalize)
        #[arg(long, conflicts_with_all = ["pair", "join", "balance", "reward", "runs", "presence", "collect_vec", "group_complement", "projected_group"])]
        unary: bool,

        /// Penalize conflicting pairs (for_each_unique_pair)
        #[arg(long, conflicts_with_all = ["unary", "join", "balance", "reward", "runs", "presence", "collect_vec", "group_complement", "projected_group"])]
        pair: bool,

        /// Penalize entity-fact mismatch (for_each + join)
        #[arg(long, conflicts_with_all = ["unary", "pair", "balance", "reward", "runs", "presence", "collect_vec", "group_complement", "projected_group"])]
        join: bool,

        /// Balance assignments across entities
        #[arg(long, conflicts_with_all = ["unary", "pair", "join", "reward", "runs", "presence", "collect_vec", "group_complement", "projected_group"])]
        balance: bool,

        /// Reward matching entities (for_each + filter + reward)
        #[arg(long, conflicts_with_all = ["unary", "pair", "join", "balance", "runs", "presence", "collect_vec", "group_complement", "projected_group"])]
        reward: bool,

        /// Generate a grouped consecutive-runs collector skeleton
        #[arg(long, conflicts_with_all = ["unary", "pair", "join", "balance", "reward", "presence", "collect_vec", "group_complement", "projected_group"])]
        runs: bool,

        /// Generate a grouped indexed-presence collector skeleton
        #[arg(long, conflicts_with_all = ["unary", "pair", "join", "balance", "reward", "runs", "collect_vec", "group_complement", "projected_group"])]
        presence: bool,

        /// Generate a grouped collect_vec collector skeleton
        #[arg(long, conflicts_with_all = ["unary", "pair", "join", "balance", "reward", "runs", "presence", "group_complement", "projected_group"])]
        collect_vec: bool,

        /// Generate a grouped complement skeleton
        #[arg(long, conflicts_with_all = ["unary", "pair", "join", "balance", "reward", "runs", "presence", "collect_vec", "projected_group"])]
        group_complement: bool,

        /// Generate a projected join plus grouped collector skeleton
        #[arg(long, conflicts_with_all = ["unary", "pair", "join", "balance", "reward", "runs", "presence", "collect_vec", "group_complement"])]
        projected_group: bool,

        /// Overwrite if constraint already exists
        #[arg(long, short)]
        force: bool,

        /// Preview changes without writing files
        #[arg(long)]
        pretend: bool,
    },
    /// Scaffold a planning entity struct in src/domain/
    #[command(
        after_help = "Examples:\n  solverforge generate entity shift --planning-variable employee_idx\n  solverforge generate entity task"
    )]
    Entity {
        /// Entity name in snake_case (e.g. shift)
        name: String,

        /// Planning variable field name (e.g. employee_idx)
        #[arg(long = "planning-variable", value_name = "FIELD")]
        planning_variable: Option<String>,

        /// Additional fields in "name:Type" format (repeatable, e.g. --field "start:String")
        #[arg(long = "field", value_name = "NAME:TYPE")]
        fields: Vec<String>,

        /// Overwrite if entity already exists
        #[arg(long, short)]
        force: bool,

        /// Preview changes without writing files
        #[arg(long)]
        pretend: bool,
    },
    /// Scaffold a problem fact struct in src/domain/
    #[command(
        after_help = "Examples:\n  solverforge generate fact employee\n  solverforge generate fact location --field \"lat:f64\" --field \"lng:f64\""
    )]
    Fact {
        /// Fact name in snake_case (e.g. employee)
        name: String,

        /// Additional fields in "name:Type" format (repeatable, e.g. --field "skill:String")
        #[arg(long = "field", value_name = "NAME:TYPE")]
        fields: Vec<String>,

        /// Overwrite if fact already exists
        #[arg(long, short)]
        force: bool,

        /// Preview changes without writing files
        #[arg(long)]
        pretend: bool,
    },
    /// Scaffold a planning solution struct in src/domain/
    #[command(
        after_help = "Examples:\n  solverforge generate solution schedule --score HardSoftScore"
    )]
    Solution {
        /// Solution name in snake_case (e.g. schedule)
        name: String,

        /// Score type (e.g. HardSoftScore, HardSoftDecimalScore)
        #[arg(long, value_name = "SCORE_TYPE", default_value = "HardSoftScore")]
        score: String,
    },
    /// Add a planning variable field to an existing entity
    #[command(
        after_help = "Examples:\n  solverforge generate variable employee_idx --entity Shift --kind scalar --range employees --allows-unassigned\n  solverforge generate variable employee_idx --entity Shift --kind scalar --range employees --candidate-values employee_candidates\n  solverforge generate variable stops --entity Route --kind list --elements visits"
    )]
    Variable(Box<VariableArgs>),
    /// Change the score type in the existing planning solution
    #[command(after_help = "Examples:\n  solverforge generate score HardSoftDecimalScore")]
    Score {
        /// Score type (e.g. HardSoftScore, HardSoftDecimalScore, HardMediumSoftScore, SoftScore, BendableScore<2, 3>)
        score_type: String,
    },
    /// Regenerate compiler-owned demo data from the project model
    #[command(
        after_help = "Examples:\n  solverforge generate data\n  solverforge generate data --size large\n  solverforge generate data --mode stub"
    )]
    Data {
        /// Data generation mode
        #[arg(long, value_parser = ["sample", "stub"], default_value = "sample")]
        mode: String,

        /// Default dataset size exposed by the generated demo data
        #[arg(long, value_parser = ["small", "standard", "large"])]
        size: Option<String>,
    },
    /// Declare a SolverForge scalar group for coupled scalar construction/search
    #[command(
        after_help = "Examples:\n  solverforge generate scalar-group required_assignment --assignment Task.resource_idx --required-entity required_task\n  solverforge generate scalar-group paired_assignment --candidates paired_candidates --target Task.primary_idx --target Task.secondary_idx"
    )]
    ScalarGroup(Box<ScalarGroupArgs>),
    /// Declare a conflict repair provider for a constraint
    #[command(
        after_help = "Examples:\n  solverforge generate conflict-repair required_assignment --provider repair_required_assignment"
    )]
    ConflictRepair(Box<ConflictRepairArgs>),
}

#[derive(Args)]
struct VariableArgs {
    /// Field name in snake_case (e.g. preferred_shift)
    field: String,

    /// Entity struct name (e.g. Shift)
    #[arg(long, value_name = "ENTITY_TYPE")]
    entity: String,

    /// Variable kind (`scalar` or `list`)
    #[arg(long, value_parser = parse_variable_kind)]
    kind: String,

    /// Scalar-variable value range collection (e.g. employees)
    #[arg(long, value_name = "FACT_COLLECTION")]
    range: Option<String>,

    /// List-variable element collection (e.g. visits)
    #[arg(long, value_name = "FACT_COLLECTION")]
    elements: Option<String>,

    /// Allow leaving the scalar variable unassigned
    #[arg(long, default_value_t = false)]
    allows_unassigned: bool,

    /// Scalar hook returning candidate value indexes for construction/search
    #[arg(long, value_name = "FN_PATH")]
    candidate_values: Option<String>,

    /// Scalar hook returning nearby value indexes for nearby change moves
    #[arg(long, value_name = "FN_PATH")]
    nearby_value_candidates: Option<String>,

    /// Scalar hook returning nearby entity indexes for nearby swap moves
    #[arg(long, value_name = "FN_PATH")]
    nearby_entity_candidates: Option<String>,

    /// Scalar distance meter for nearby value candidates
    #[arg(long, value_name = "FN_PATH")]
    nearby_value_distance_meter: Option<String>,

    /// Scalar distance meter for nearby entity candidates
    #[arg(long, value_name = "FN_PATH")]
    nearby_entity_distance_meter: Option<String>,

    /// Scalar construction hook ranking entity assignment order
    #[arg(long, value_name = "FN_PATH")]
    construction_entity_order_key: Option<String>,

    /// Scalar construction hook ranking candidate value order
    #[arg(long, value_name = "FN_PATH")]
    construction_value_order_key: Option<String>,
}

#[derive(Args)]
struct ScalarGroupArgs {
    /// Group name used by ScalarGroup and solver.toml group_name
    name: String,

    /// Assignment-backed scalar target in Entity.field form
    #[arg(long, value_name = "ENTITY.FIELD", conflicts_with = "candidates")]
    assignment: Option<String>,

    /// Candidate-backed provider function path
    #[arg(long, value_name = "FN_PATH", conflicts_with = "assignment")]
    candidates: Option<String>,

    /// Candidate-backed scalar target in Entity.field form; repeat for multi-target groups
    #[arg(long = "target", value_name = "ENTITY.FIELD")]
    targets: Vec<String>,

    /// Assignment hook deciding whether an entity must be assigned
    #[arg(long, value_name = "FN_PATH")]
    required_entity: Option<String>,

    /// Assignment hook returning a capacity bucket for entity/value pairs
    #[arg(long, value_name = "FN_PATH")]
    capacity_key: Option<String>,

    /// Assignment hook filtering legal pairwise assignments
    #[arg(long, value_name = "FN_PATH")]
    assignment_rule: Option<String>,

    /// Assignment hook returning sequence position for an entity
    #[arg(long, value_name = "FN_PATH")]
    position_key: Option<String>,

    /// Assignment hook returning sequence key for entity/value pairs
    #[arg(long, value_name = "FN_PATH")]
    sequence_key: Option<String>,

    /// Assignment hook ranking entity construction order
    #[arg(long, value_name = "FN_PATH")]
    entity_order: Option<String>,

    /// Assignment hook ranking candidate values
    #[arg(long, value_name = "FN_PATH")]
    value_order: Option<String>,

    /// Limit candidate values per scalar target
    #[arg(long, value_name = "N")]
    value_candidate_limit: Option<usize>,

    /// Limit grouped construction candidates
    #[arg(long, value_name = "N")]
    group_candidate_limit: Option<usize>,

    /// Limit grouped scalar local-search moves per step
    #[arg(long, value_name = "N")]
    max_moves_per_step: Option<usize>,

    /// Limit augmenting-path depth for assignment groups
    #[arg(long, value_name = "N")]
    max_augmenting_depth: Option<usize>,

    /// Limit rematch size for assignment groups
    #[arg(long, value_name = "N")]
    max_rematch_size: Option<usize>,

    /// Do not add matching solver.toml phases
    #[arg(long)]
    skip_solver_config: bool,
}

#[derive(Args)]
struct ConflictRepairArgs {
    /// Exact constraint ID matched by the repair selector
    constraint: String,

    /// Repair provider function path
    #[arg(long, value_name = "FN_PATH")]
    provider: String,

    /// Move selector kind to add to solver.toml
    #[arg(long, value_parser = ["compound", "conflict"], default_value = "compound")]
    selector: String,

    /// Limit conflict matches per step
    #[arg(long, value_name = "N")]
    max_matches_per_step: Option<usize>,

    /// Limit repairs per matched conflict
    #[arg(long, value_name = "N")]
    max_repairs_per_match: Option<usize>,

    /// Limit emitted repair moves per step
    #[arg(long, value_name = "N")]
    max_moves_per_step: Option<usize>,

    /// Allow selectors to match soft-constraint conflicts
    #[arg(long)]
    include_soft_matches: bool,

    /// Do not add a matching solver.toml phase
    #[arg(long)]
    skip_solver_config: bool,
}

#[derive(Subcommand)]
enum DestroyResource {
    /// Remove the planning solution struct
    Solution,
    /// Remove a planning entity struct
    Entity {
        /// Entity name to remove
        name: String,
    },
    /// Remove a planning variable field from an entity
    Variable {
        /// Variable field to remove
        field: String,

        /// Entity struct name (e.g. Shift)
        #[arg(long, value_name = "ENTITY_TYPE")]
        entity: String,
    },
    /// Remove a problem fact struct
    Fact {
        /// Fact name to remove
        name: String,
    },
    /// Remove a constraint
    Constraint {
        /// Exact constraint ID to remove
        name: String,
    },
    /// Remove a scalar group declaration
    ScalarGroup {
        /// Scalar group name to remove
        name: String,
    },
    /// Remove a conflict repair declaration
    ConflictRepair {
        /// Exact constraint ID to remove
        name: String,
    },
}

fn main() {
    // Load rc config first so CLI flags can override it.
    let rc = rc::load_rc().unwrap_or_default();

    let cli = Cli::parse();

    // Configure output — CLI flags override rc config.
    if cli.quiet || rc.quiet {
        output::set_verbosity(0);
    } else if cli.verbose {
        output::set_verbosity(2);
    }
    if cli.no_color || rc.no_color || std::env::var("NO_COLOR").is_ok() {
        output::set_no_color(true);
    }

    let result: CliResult = match cli.command {
        Command::New {
            name,
            shell,
            skip_git,
            skip_readme,
        } => commands::new::run(&name, shell, skip_git, skip_readme, cli.quiet),
        Command::Generate { resource } => match *resource {
            GenerateResource::Constraint {
                name,
                hard: _,
                soft,
                unary,
                pair,
                join,
                balance,
                reward,
                runs,
                presence,
                collect_vec,
                group_complement,
                projected_group,
                force,
                pretend,
            } => commands::generate_constraint::run(
                &name,
                soft,
                unary,
                pair,
                join,
                balance,
                reward,
                runs,
                presence,
                collect_vec,
                group_complement,
                projected_group,
                force,
                pretend,
            ),
            GenerateResource::Entity {
                name,
                planning_variable,
                fields,
                force,
                pretend,
            } => commands::generate_domain::run_entity(
                &name,
                planning_variable.as_deref(),
                &fields,
                force,
                pretend,
            ),
            GenerateResource::Fact {
                name,
                fields,
                force,
                pretend,
            } => commands::generate_domain::run_fact(&name, &fields, force, pretend),
            GenerateResource::Solution { name, score } => {
                commands::generate_domain::run_solution(&name, &score)
            }
            GenerateResource::Variable(variable_args) => {
                let VariableArgs {
                    field,
                    entity,
                    kind,
                    range,
                    elements,
                    allows_unassigned,
                    candidate_values,
                    nearby_value_candidates,
                    nearby_entity_candidates,
                    nearby_value_distance_meter,
                    nearby_entity_distance_meter,
                    construction_entity_order_key,
                    construction_value_order_key,
                } = *variable_args;
                commands::generate_domain::run_variable(
                    &field,
                    &entity,
                    &kind,
                    range.as_deref(),
                    elements.as_deref(),
                    allows_unassigned,
                    &ScalarVariableHooks {
                        candidate_values,
                        nearby_value_candidates,
                        nearby_entity_candidates,
                        nearby_value_distance_meter,
                        nearby_entity_distance_meter,
                        construction_entity_order_key,
                        construction_value_order_key,
                    },
                )
            }
            GenerateResource::Score { score_type } => {
                commands::generate_domain::run_score(&score_type)
            }
            GenerateResource::Data { mode, size } => {
                commands::generate_domain::run_data(&mode, size.as_deref())
            }
            GenerateResource::ScalarGroup(args) => {
                let ScalarGroupArgs {
                    name,
                    assignment,
                    candidates,
                    targets,
                    required_entity,
                    capacity_key,
                    assignment_rule,
                    position_key,
                    sequence_key,
                    entity_order,
                    value_order,
                    value_candidate_limit,
                    group_candidate_limit,
                    max_moves_per_step,
                    max_augmenting_depth,
                    max_rematch_size,
                    skip_solver_config,
                } = *args;
                commands::model_resource::run_scalar_group(ScalarGroupRequest {
                    name,
                    assignment,
                    candidates,
                    targets,
                    required_entity,
                    capacity_key,
                    assignment_rule,
                    position_key,
                    sequence_key,
                    entity_order,
                    value_order,
                    value_candidate_limit,
                    group_candidate_limit,
                    max_moves_per_step,
                    max_augmenting_depth,
                    max_rematch_size,
                    skip_solver_config,
                })
            }
            GenerateResource::ConflictRepair(args) => {
                let ConflictRepairArgs {
                    constraint,
                    provider,
                    selector,
                    max_matches_per_step,
                    max_repairs_per_match,
                    max_moves_per_step,
                    include_soft_matches,
                    skip_solver_config,
                } = *args;
                commands::model_resource::run_conflict_repair(ConflictRepairRequest {
                    constraint,
                    provider,
                    selector,
                    max_matches_per_step,
                    max_repairs_per_match,
                    max_moves_per_step,
                    include_soft_matches,
                    skip_solver_config,
                })
            }
        },
        Command::Destroy {
            yes,
            resource: DestroyResource::Solution,
        } => commands::destroy::run_solution(yes),
        Command::Destroy {
            yes,
            resource: DestroyResource::Entity { name },
        } => commands::destroy::run_entity(&name, yes),
        Command::Destroy {
            yes,
            resource: DestroyResource::Variable { field, entity },
        } => commands::destroy::run_variable(&field, &entity, yes),
        Command::Destroy {
            yes,
            resource: DestroyResource::Fact { name },
        } => commands::destroy::run_fact(&name, yes),
        Command::Destroy {
            yes,
            resource: DestroyResource::Constraint { name },
        } => commands::destroy::run_constraint(&name, yes),
        Command::Destroy {
            yes,
            resource: DestroyResource::ScalarGroup { name },
        } => commands::destroy::run_scalar_group(&name, yes),
        Command::Destroy {
            yes,
            resource: DestroyResource::ConflictRepair { name },
        } => commands::destroy::run_conflict_repair(&name, yes),
        Command::Server { port, debug } => commands::server::run(port, debug),
        Command::Info => commands::info::run(),
        Command::Check => commands::check::run(),
        Command::Test { extra_args } => commands::test::run(&extra_args),
        Command::Routes => commands::routes::run(),
        Command::Config {
            subcommand: ConfigSubcommand::Show,
        } => commands::config::run_show(),
        Command::Config {
            subcommand: ConfigSubcommand::Set { key, value },
        } => commands::config::run_set(&key, &value),
        Command::Completions { shell } => {
            let mut cmd = Cli::command();
            clap_complete::generate(shell, &mut cmd, "solverforge", &mut std::io::stdout());
            Ok(())
        }
    };

    if let Err(e) = result {
        output::print_error(&e.to_string());
        std::process::exit(1);
    }
}