summaryrefslogtreecommitdiff
path: root/module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2021-01-26 21:06:24 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2021-01-26 21:06:24 +0100
commit0ae7ecd47fd76921e8e1137739497578fe703354 (patch)
treee06a9b45b5e1e7a8922cdba11b1a39188ddeeee2 /module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java
parent71010ae3fefbe897227343e44573385df9cd60cc (diff)
downloadrules-sandbox-0ae7ecd47fd76921e8e1137739497578fe703354.tar.gz
rules-sandbox-0ae7ecd47fd76921e8e1137739497578fe703354.tar.bz2
rules-sandbox-0ae7ecd47fd76921e8e1137739497578fe703354.tar.xz
rules-sandbox-0ae7ecd47fd76921e8e1137739497578fe703354.zip
Better main().
* Moving templates into their respective modules. * Supporting export type-based filtering. Probably not perfect.
Diffstat (limited to 'module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java')
-rw-r--r--module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java46
1 files changed, 38 insertions, 8 deletions
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java b/module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java
index 2b016f2..203a9b0 100644
--- a/module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java
+++ b/module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java
@@ -20,14 +20,18 @@ public class RunCommand implements Callable<Integer> {
@Option(names = {"--output-state"})
public File outputState;
+ @Option(names = {"--include"}, split = ",", arity = "1..*")
+ public String[] includes;
+
@Option(names = {"--generated-output"})
public File generatedOutput;
@Option(names = {"--agenda-groups"})
public String[] agendaGroups;
- @Option(names = {"--modules"}, split = ",", arity = "1..*")
- public File[] modules;
+ // TODO: Remove --modules
+ @Option(names = {"--modules", "--module"}, split = ",", arity = "1..*")
+ public File[] module;
@Override
public Integer call() throws Exception {
@@ -36,13 +40,39 @@ public class RunCommand implements Callable<Integer> {
agendaGroups = new String[]{"init", "generate"};
}
- try (var engine = new Engine(name, input, generatedOutput, agendaGroups, modules)) {
+ try (var engine = new Engine(name, input, generatedOutput, agendaGroups, module)) {
engine.io.dump(outputState, engine.session.getFactHandles(), (Object o) ->
- o.getClass().getName().contains("Wg") ||
- o.getClass().getSimpleName().contains("Machine") ||
- o.getClass().getSimpleName().contains("DnsEntry") ||
- o.getClass().getSimpleName().contains("Ipv4Cidr") ||
- o.getClass().getSimpleName().contains("Ipv4Address")
+ {
+ if (includes == null || includes.length == 0) {
+ return true;
+ }
+
+ var name = o.getClass().getName();
+ var simpleName = o.getClass().getSimpleName();
+
+ for (var i : includes) {
+ var ok = false;
+ if (i.startsWith("*")) {
+ i = i.substring(1);
+
+ if (i.endsWith("*")) {
+ i = i.substring(1, i.length() - 2);
+ ok = name.contains(i);
+ } else {
+ ok = name.startsWith(i) || simpleName.startsWith(i);
+ }
+ } else if (i.endsWith("*")) {
+ i = i.substring(0, i.length() - 2);
+ ok = name.startsWith(i) || simpleName.startsWith(i);
+ }
+
+ if (ok) {
+ return true;
+ }
+ }
+
+ return false;
+ }
);
}