summaryrefslogtreecommitdiff
path: root/src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java')
-rw-r--r--src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java b/src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java
new file mode 100644
index 0000000..35f30cd
--- /dev/null
+++ b/src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java
@@ -0,0 +1,82 @@
+package io.trygvis.rules.engine.cli;
+
+import io.trygvis.rules.engine.Engine;
+
+import java.io.File;
+import java.util.concurrent.Callable;
+
+import static picocli.CommandLine.Command;
+import static picocli.CommandLine.Option;
+
+@Command(name = "run")
+public class RunCommand implements Callable<Integer> {
+
+ @Option(names = {"-n", "--name"})
+ public String name;
+
+ @Option(names = {"-i", "--input"})
+ public File[] input;
+
+ @Option(names = {"--output-state"})
+ public File outputState;
+
+ @Option(names = {"--output-include"}, split = ",", arity = "1..*")
+ public String[] outputIncludes;
+
+ @Option(names = {"--generated-output"})
+ public File generatedOutput;
+
+ @Option(names = {"--agenda-group"})
+ public String[] agendaGroups;
+
+ @Option(names = {"--module"}, split = ",", arity = "1..*")
+ public File[] module;
+
+ @Override
+ public Integer call() throws Exception {
+
+ if (agendaGroups == null || agendaGroups.length == 0) {
+ agendaGroups = new String[]{"init", "generate"};
+ }
+
+ try (var engine = new Engine(name, input, generatedOutput, agendaGroups, module)) {
+ engine.io.dump(outputState, engine.session.getFactHandles(), (Object o) ->
+ {
+ if (outputIncludes == null || outputIncludes.length == 0) {
+ return true;
+ }
+
+ var name = o.getClass().getName();
+ var simpleName = o.getClass().getSimpleName();
+
+ for (var i : outputIncludes) {
+ 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);
+ } else {
+ ok = name.equals(i) || simpleName.equals(i);
+ }
+
+ if (ok) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+ );
+ }
+
+ return 0;
+ }
+}