diff --git a/core/src/main/java/io/xpipe/core/process/CommandBuilder.java b/core/src/main/java/io/xpipe/core/process/CommandBuilder.java index 8c6307a5..98044f5c 100644 --- a/core/src/main/java/io/xpipe/core/process/CommandBuilder.java +++ b/core/src/main/java/io/xpipe/core/process/CommandBuilder.java @@ -1,5 +1,7 @@ package io.xpipe.core.process; +import lombok.SneakyThrows; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -61,6 +63,10 @@ public class CommandBuilder { public CommandBuilder addQuoted(String s) { elements.add(sc -> { + if (s == null) { + return null; + } + if (sc == null) { return "\"" + s + "\""; } @@ -102,6 +108,10 @@ public class CommandBuilder { public CommandBuilder addFile(String s) { elements.add(sc -> { + if (s == null) { + return null; + } + if (sc == null) { return "\"" + s + "\""; } @@ -128,13 +138,17 @@ public class CommandBuilder { return sc.command(this); } + @SneakyThrows public String buildSimple() { - return String.join(" ", elements.stream().map(element -> { - try { - return element.evaluate(null); - } catch (Exception e) { - throw new RuntimeException(e); + List list = new ArrayList<>(); + for (Element element : elements) { + String evaluate = element.evaluate(null); + if (evaluate == null) { + continue; } - }).toList()); + + list.add(evaluate); + } + return String.join(" ", list); } }