33import org .jetbrains .annotations .Contract ;
44import org .jspecify .annotations .NonNull ;
55import org .jspecify .annotations .Nullable ;
6+ import tect .host .tpl .module .ModuleCommand ;
7+ import tect .host .tpl .module .ModuleContext ;
68import tect .host .tpl .module .ModulePhase ;
79
810import java .util .Set ;
11+ import java .util .function .BiFunction ;
12+ import java .util .function .Function ;
913
1014public final class ModuleDescriptor {
1115
@@ -15,6 +19,7 @@ public final class ModuleDescriptor {
1519 private final Set <String > requiredModules ;
1620 private final @ Nullable ModulePhase phase ;
1721 private final int priority ;
22+ private final @ Nullable Function <ModuleManager , ModuleCommand > commandFactory ;
1823
1924 private ModuleDescriptor (@ NonNull Builder builder ) {
2025 this .id = builder .id ;
@@ -23,6 +28,7 @@ private ModuleDescriptor(@NonNull Builder builder) {
2328 this .requiredModules = Set .copyOf (builder .requiredModules );
2429 this .phase = builder .phase ;
2530 this .priority = builder .priority ;
31+ this .commandFactory = builder .commandFactory ;
2632 }
2733
2834 @ Contract ("_, _, _ -> new" )
@@ -37,6 +43,10 @@ private ModuleDescriptor(@NonNull Builder builder) {
3743 public @ Nullable ModulePhase getPhase () { return phase ; }
3844 public int getPriority () { return priority ; }
3945
46+ public @ Nullable Function <ModuleManager , ModuleCommand > getCommandFactory () {
47+ return commandFactory ;
48+ }
49+
4050 public static final class Builder {
4151
4252 private final String id ;
@@ -45,17 +55,14 @@ public static final class Builder {
4555 private Set <String > requiredModules = Set .of ();
4656 private @ Nullable ModulePhase phase = null ;
4757 private int priority = 100 ;
58+ private @ Nullable Function <ModuleManager , ModuleCommand > commandFactory = null ;
4859
4960 private Builder (String id , String togglePath , ModuleFactory factory ) {
5061 this .id = id ;
5162 this .togglePath = togglePath ;
5263 this .factory = factory ;
5364 }
5465
55- /**
56- * Each call to requires() replaces the previous set entirely
57- * To declare multiple dependencies, pass all IDs in one call: .requires("a", "b")
58- */
5966 public Builder requires (@ NonNull String ... moduleIds ) {
6067 this .requiredModules = Set .of (moduleIds );
6168 return this ;
@@ -71,6 +78,11 @@ public Builder priority(int priority) {
7178 return this ;
7279 }
7380
81+ public Builder command (@ NonNull Function <ModuleManager , ModuleCommand > commandFactory ) {
82+ this .commandFactory = commandFactory ;
83+ return this ;
84+ }
85+
7486 @ Contract (" -> new" )
7587 public @ NonNull ModuleDescriptor build () {
7688 return new ModuleDescriptor (this );
0 commit comments