This is an automated email from the ASF dual-hosted git repository.

fmariani pushed a commit to branch jbang-user-config
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 0f231bc9e587a656b16fda31534e58c534c07363
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Mar 7 15:34:16 2023 +0100

    CAMEL-18508: camel-jbang - User config. WIP
---
 .../dsl/jbang/core/common/CommandLineHelper.java   | 24 +++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/CommandLineHelper.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/CommandLineHelper.java
index b3fda856a4f..0856fdd55fc 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/CommandLineHelper.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/CommandLineHelper.java
@@ -40,7 +40,7 @@ public class CommandLineHelper {
                 prop.load(fis);
                 IOHelper.close(fis);
                 if (!prop.isEmpty()) {
-                    commandLine.setDefaultValueProvider(new 
CommandLine.PropertiesDefaultProvider(prop));
+                    commandLine.setDefaultValueProvider(new 
CamelUserConfigDefaultValueProvider(prop));
                 }
             } catch (Exception e) {
                 throw new RuntimeException("Cannot load user configuration: " 
+ file);
@@ -50,4 +50,26 @@ public class CommandLineHelper {
         }
     }
 
+    private static class CamelUserConfigDefaultValueProvider extends 
CommandLine.PropertiesDefaultProvider {
+
+        public CamelUserConfigDefaultValueProvider(Properties properties) {
+            super(properties);
+        }
+
+        @Override
+        public String defaultValue(CommandLine.Model.ArgSpec arg) throws 
Exception {
+            String value = super.defaultValue(arg);
+            if (value != null) {
+                if (arg instanceof CommandLine.Model.OptionSpec) {
+                    // TODO: capture these default values that are in use
+                    // and find a way to log them only once (and have an 
option to turn this off)
+                    CommandLine.Model.OptionSpec os = 
(CommandLine.Model.OptionSpec) arg;
+                    String k = os.longestName();
+                    System.out.println(k + "=" + value);
+                }
+            }
+            return value;
+        }
+    }
+
 }

Reply via email to