You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/05/15 15:50:13 UTC
[camel] 01/02: CAMEL-19313: resolve option placeholder
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-3.x
in repository https://gitbox.apache.org/repos/asf/camel.git
commit f23f132141a0138567056791d337a55a5e2ff9e4
Author: Croway <fe...@gmail.com>
AuthorDate: Wed May 3 14:02:30 2023 +0200
CAMEL-19313: resolve option placeholder
---
.../camel/dsl/jbang/core/commands/CamelCommand.java | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelCommand.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelCommand.java
index 554f962fb17..583350317bb 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelCommand.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelCommand.java
@@ -26,6 +26,7 @@ import java.util.concurrent.Callable;
import org.apache.camel.dsl.jbang.core.common.CommandLineHelper;
import org.apache.camel.dsl.jbang.core.common.RuntimeUtil;
+import org.apache.camel.util.StringHelper;
import picocli.CommandLine;
import picocli.CommandLine.IParameterConsumer;
import picocli.CommandLine.Model.ArgSpec;
@@ -67,9 +68,28 @@ public abstract class CamelCommand implements Callable<Integer> {
configureLoggingOff();
}
+ replacePlaceholders();
+
return doCall();
}
+ private void replacePlaceholders() throws Exception {
+ for (CommandLine.Model.ArgSpec argSpec : spec.args()) {
+ String defaultValue = spec.defaultValueProvider().defaultValue(argSpec);
+
+ if (defaultValue != null &&
+ argSpec instanceof CommandLine.Model.OptionSpec optionSpec) {
+ for (String name : optionSpec.names()) {
+ String placeholder = "$" + StringHelper.after(name, "--");
+ if (argSpec.getValue() != null &&
+ argSpec.getValue().toString().contains(placeholder)) {
+ argSpec.setValue(argSpec.getValue().toString().replace(placeholder, defaultValue));
+ }
+ }
+ }
+ }
+ }
+
public abstract Integer doCall() throws Exception;
public File getStatusFile(String pid) {