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

fmariani pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit c7cd0282805a467e350ee397aa181756fc28250f
Author: Croway <federico.mariani.1...@gmail.com>
AuthorDate: Thu Mar 27 14:37:03 2025 +0100

    Allow configuration preset per directory
---
 .../dsl/jbang/core/commands/CamelCommand.java      | 15 +++++-
 .../dsl/jbang/core/commands/CamelJBangMain.java    | 33 +++++++++++-
 .../dsl/jbang/core/commands/config/ConfigGet.java  |  5 +-
 .../dsl/jbang/core/commands/config/ConfigList.java |  5 +-
 .../dsl/jbang/core/commands/config/ConfigSet.java  |  9 ++--
 .../jbang/core/commands/config/ConfigUnset.java    |  7 ++-
 .../jbang/core/commands/version/VersionGet.java    |  5 +-
 .../jbang/core/commands/version/VersionSet.java    |  9 ++--
 .../dsl/jbang/core/common/CommandLineHelper.java   | 62 ++++++++++++++++++----
 .../dsl/jbang/core/commands/UserConfigHelper.java  | 17 ++++--
 .../BaseConfigTest.java}                           | 27 +++-------
 .../jbang/core/commands/config/ConfigGetTest.java  | 15 +++++-
 .../jbang/core/commands/config/ConfigListTest.java | 19 ++++++-
 .../jbang/core/commands/config/ConfigSetTest.java  | 18 ++++++-
 .../core/commands/config/ConfigUnsetTest.java      | 22 +++++++-
 15 files changed, 212 insertions(+), 56 deletions(-)

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 188c9abd295..1477d27f129 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
@@ -17,6 +17,8 @@
 package org.apache.camel.dsl.jbang.core.commands;
 
 import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -129,8 +131,17 @@ public abstract class CamelCommand implements 
Callable<Integer> {
 
     protected void printConfigurationValues(String header) {
         if (spec != null) {
-            final Properties configProperties = new Properties();
-            CommandLineHelper.loadProperties(configProperties::putAll);
+            Properties configProperties = new Properties();
+            Path userConfigInCurrentDirectory = 
Path.of(CommandLineHelper.USER_CONFIG);
+            if (main.isMergeUserConfigurations()) {
+                CommandLineHelper.loadProperties(configProperties::putAll, 
false);
+                if (Files.exists(userConfigInCurrentDirectory)) {
+                    CommandLineHelper.loadProperties(configProperties::putAll, 
true);
+                }
+            } else {
+                boolean isLocalConfiguration = 
Files.exists(userConfigInCurrentDirectory);
+                CommandLineHelper.loadProperties(configProperties::putAll, 
isLocalConfiguration);
+            }
             List<String> lines = new ArrayList<>();
             spec.options().forEach(opt -> {
                 if (Arrays.stream(opt.names()).anyMatch(name ->
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
index d192bd894fa..bd1013c14ab 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.dsl.jbang.core.commands;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.concurrent.Callable;
 
 import org.apache.camel.catalog.CamelCatalog;
@@ -72,6 +74,8 @@ public class CamelJBangMain implements Callable<Integer> {
         run(new CamelJBangMain(), args);
     }
 
+    private static boolean mergeUserConfigurations;
+
     public static void run(CamelJBangMain main, String... args) {
         // set pid as system property as logging ${sys:pid} needs to be 
resolved on windows
         try {
@@ -192,11 +196,34 @@ public class CamelJBangMain implements Callable<Integer> {
             return new String[] { v };
         });
 
-        CommandLineHelper.augmentWithUserConfiguration(commandLine, args);
+        List<String> arguments = new ArrayList<>(args.length);
+        mergeUserConfigurations = isMergeUserConfigurations(args, 
mergeUserConfigurations, arguments);
+        args = arguments.toArray(new String[0]);
+        CommandLineHelper.augmentWithUserConfiguration(commandLine, 
mergeUserConfigurations);
         int exitCode = commandLine.execute(args);
         main.quit(exitCode);
     }
 
+    /**
+     * The option --mergeConfigurations is used only during PicoCLI 
UserConfigDefaultProvider initialization if args
+     * contains the string --mergeConfigurations, it is removed, this way, it 
won't mess with PicoCLI @CommandLine.*
+     *
+     * @param  args
+     * @param  mergeConfigurations
+     * @param  arguments
+     * @return
+     */
+    private static boolean isMergeUserConfigurations(String[] args, boolean 
mergeConfigurations, List<String> arguments) {
+        for (String arg : args) {
+            if ("--mergeConfigurations".equals(arg)) {
+                mergeConfigurations = true;
+            } else {
+                arguments.add(arg);
+            }
+        }
+        return mergeConfigurations;
+    }
+
     /**
      * Finish this main with given exit code. By default, uses system exit to 
terminate. Subclasses may want to
      * overwrite this exit behavior e.g. during unit tests.
@@ -244,4 +271,8 @@ public class CamelJBangMain implements Callable<Integer> {
     public static CommandLine getCommandLine() {
         return commandLine;
     }
+
+    public boolean isMergeUserConfigurations() {
+        return mergeUserConfigurations;
+    }
 }
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigGet.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigGet.java
index 855258f38ef..89257352327 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigGet.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigGet.java
@@ -30,6 +30,9 @@ public class ConfigGet extends CamelCommand {
     @CommandLine.Parameters(description = "Configuration key", arity = "1")
     String key;
 
+    @CommandLine.Option(names = { "--local" }, description = "Retrieve 
configurations from current directory")
+    boolean local;
+
     public ConfigGet(CamelJBangMain main) {
         super(main);
     }
@@ -43,7 +46,7 @@ public class ConfigGet extends CamelCommand {
             } else {
                 printer().println(key + " key not found");
             }
-        });
+        }, local);
 
         return 0;
     }
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigList.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigList.java
index 2c215dbeaed..1c20bf6731a 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigList.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigList.java
@@ -24,6 +24,9 @@ import picocli.CommandLine;
 @CommandLine.Command(name = "list", description = "Displays user 
configuration", sortOptions = false, showDefaultValues = true)
 public class ConfigList extends CamelCommand {
 
+    @CommandLine.Option(names = { "--local" }, description = "Retrieve 
configurations from current directory")
+    boolean local;
+
     public ConfigList(CamelJBangMain main) {
         super(main);
     }
@@ -36,7 +39,7 @@ public class ConfigList extends CamelCommand {
                         String v = p.getProperty(k);
                         printer().printf("%s = %s%n", k, v);
                     }
-                });
+                }, local);
         return 0;
     }
 }
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigSet.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigSet.java
index 174800e97ad..913e7c92fa7 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigSet.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigSet.java
@@ -29,13 +29,16 @@ public class ConfigSet extends CamelCommand {
     @CommandLine.Parameters(description = "Configuration parameter (ex. 
key=value)", arity = "1")
     String configuration;
 
+    @CommandLine.Option(names = { "--local" }, description = "Retrieve 
configurations from current directory")
+    boolean local;
+
     public ConfigSet(CamelJBangMain main) {
         super(main);
     }
 
     @Override
     public Integer doCall() throws Exception {
-        CommandLineHelper.createPropertyFile();
+        CommandLineHelper.createPropertyFile(local);
 
         if (configuration.split("=").length == 1) {
             printer().println("Configuration parameter not in key=value 
format");
@@ -46,8 +49,8 @@ public class ConfigSet extends CamelCommand {
             String key = StringHelper.before(configuration, "=").trim();
             String value = StringHelper.after(configuration, "=").trim();
             properties.put(key, value);
-            CommandLineHelper.storeProperties(properties, printer());
-        });
+            CommandLineHelper.storeProperties(properties, printer(), local);
+        }, local);
 
         return 0;
     }
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigUnset.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigUnset.java
index 375a289af14..ded8cdcb60d 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigUnset.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigUnset.java
@@ -28,6 +28,9 @@ public class ConfigUnset extends CamelCommand {
     @CommandLine.Parameters(description = "Configuration key", arity = "1")
     String key;
 
+    @CommandLine.Option(names = { "--local" }, description = "Retrieve 
configurations from current directory")
+    boolean local;
+
     public ConfigUnset(CamelJBangMain main) {
         super(main);
     }
@@ -36,8 +39,8 @@ public class ConfigUnset extends CamelCommand {
     public Integer doCall() throws Exception {
         CommandLineHelper.loadProperties(properties -> {
             properties.remove(key);
-            CommandLineHelper.storeProperties(properties, printer());
-        });
+            CommandLineHelper.storeProperties(properties, printer(), local);
+        }, local);
 
         return 0;
     }
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/version/VersionGet.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/version/VersionGet.java
index c8af9e9d94c..0ea49504056 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/version/VersionGet.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/version/VersionGet.java
@@ -28,6 +28,9 @@ import picocli.CommandLine;
                      showDefaultValues = true)
 public class VersionGet extends CamelCommand {
 
+    @CommandLine.Option(names = { "--local" }, description = "Retrieve 
configurations from current directory")
+    boolean local;
+
     public VersionGet(CamelJBangMain main) {
         super(main);
     }
@@ -63,7 +66,7 @@ public class VersionGet extends CamelCommand {
                     printer().println("    repos = " + repos);
                 }
             }
-        });
+        }, local);
 
         return 0;
     }
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/version/VersionSet.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/version/VersionSet.java
index 1c95a3475bd..b67fad3cb38 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/version/VersionSet.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/version/VersionSet.java
@@ -43,13 +43,16 @@ public class VersionSet extends CamelCommand {
     @CommandLine.Option(names = { "--reset" }, description = "Reset by 
removing any custom version settings")
     boolean reset;
 
+    @CommandLine.Option(names = { "--local" }, description = "Retrieve 
configurations from current directory")
+    boolean local;
+
     public VersionSet(CamelJBangMain main) {
         super(main);
     }
 
     @Override
     public Integer doCall() throws Exception {
-        CommandLineHelper.createPropertyFile();
+        CommandLineHelper.createPropertyFile(local);
 
         CommandLineHelper.loadProperties(properties -> {
             if (reset) {
@@ -67,8 +70,8 @@ public class VersionSet extends CamelCommand {
                     properties.put("runtime", runtime.runtime());
                 }
             }
-            CommandLineHelper.storeProperties(properties, printer());
-        });
+            CommandLineHelper.storeProperties(properties, printer(), local);
+        }, local);
 
         return 0;
     }
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 518af842471..0c1103977f7 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
@@ -19,7 +19,10 @@ package org.apache.camel.dsl.jbang.core.common;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.FileReader;
 import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.Properties;
 import java.util.function.Consumer;
 
@@ -41,22 +44,47 @@ public final class CommandLineHelper {
         super();
     }
 
-    public static void augmentWithUserConfiguration(CommandLine commandLine, 
String... args) {
-        File file = getUserPropertyFile();
+    public static void augmentWithUserConfiguration(CommandLine commandLine, 
boolean mergeConfigurations) {
+        File file = getUserConfigurationFile();
         if (file.isFile() && file.exists()) {
-            commandLine.setDefaultValueProvider(new 
CamelUserConfigDefaultValueProvider(file));
+            Properties properties = new Properties();
+            try {
+                if (mergeConfigurations) {
+                    properties.load(new 
FileReader(getUserPropertyFile(false)));
+                }
+
+                properties.load(new FileReader(file));
+            } catch (IOException e) {
+                commandLine.setDefaultValueProvider(new 
CamelUserConfigDefaultValueProvider(file));
+            }
+
+            commandLine.setDefaultValueProvider(new 
CamelUserConfigDefaultValueProvider(properties));
         }
     }
 
-    public static void createPropertyFile() throws IOException {
-        File file = getUserPropertyFile();
+    private static File getUserConfigurationFile() {
+        File file;
+        if (Files.exists(Path.of(USER_CONFIG))) {
+            file = new File(USER_CONFIG);
+        } else {
+            file = getUserPropertyFile(false);
+        }
+        return file;
+    }
+
+    public static void createPropertyFile(boolean local) throws IOException {
+        File file = getUserPropertyFile(local);
         if (!file.exists()) {
             file.createNewFile();
         }
     }
 
     public static void loadProperties(Consumer<Properties> consumer) {
-        File file = getUserPropertyFile();
+        loadProperties(consumer, false);
+    }
+
+    public static void loadProperties(Consumer<Properties> consumer, boolean 
local) {
+        File file = getUserPropertyFile(local);
         if (file.isFile() && file.exists()) {
             FileInputStream fis = null;
             try {
@@ -72,8 +100,8 @@ public final class CommandLineHelper {
         }
     }
 
-    public static void storeProperties(Properties properties, Printer printer) 
{
-        File file = getUserPropertyFile();
+    public static void storeProperties(Properties properties, Printer printer, 
boolean local) {
+        File file = getUserPropertyFile(local);
         if (file.isFile() && file.exists()) {
             try (FileOutputStream fos = new FileOutputStream(file)) {
                 properties.store(fos, null);
@@ -85,8 +113,18 @@ public final class CommandLineHelper {
         }
     }
 
-    private static File getUserPropertyFile() {
-        return new File(homeDir, USER_CONFIG);
+    /**
+     * Get the config file in current directory (local = true) or the default 
one
+     *
+     * @param  local
+     * @return
+     */
+    private static File getUserPropertyFile(boolean local) {
+        if (local) {
+            return new File(USER_CONFIG);
+        } else {
+            return new File(homeDir, USER_CONFIG);
+        }
     }
 
     /**
@@ -131,6 +169,10 @@ public final class CommandLineHelper {
         public CamelUserConfigDefaultValueProvider(File file) {
             super(file);
         }
+
+        public CamelUserConfigDefaultValueProvider(Properties properties) {
+            super(properties);
+        }
     }
 
 }
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/UserConfigHelper.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/UserConfigHelper.java
index a0ea04775e1..8fbb630f2c6 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/UserConfigHelper.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/UserConfigHelper.java
@@ -32,10 +32,19 @@ public final class UserConfigHelper {
     }
 
     public static void createUserConfig(String content) throws IOException {
-        CommandLineHelper.useHomeDir("target");
-        Path userConfigDir = Paths.get("target");
-        if (!userConfigDir.toFile().exists()) {
-            userConfigDir.toFile().mkdirs();
+        createUserConfig(content, false);
+    }
+
+    public static void createUserConfig(String content, boolean local) throws 
IOException {
+        Path userConfigDir;
+        if (!local) {
+            CommandLineHelper.useHomeDir("target");
+            userConfigDir = Paths.get("target");
+            if (!userConfigDir.toFile().exists()) {
+                userConfigDir.toFile().mkdirs();
+            }
+        } else {
+            userConfigDir = Paths.get(".");
         }
 
         
Files.writeString(userConfigDir.resolve(CommandLineHelper.USER_CONFIG), content,
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/UserConfigHelper.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/config/BaseConfigTest.java
similarity index 56%
copy from 
dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/UserConfigHelper.java
copy to 
dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/config/BaseConfigTest.java
index a0ea04775e1..9f7cd2bb9b0 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/UserConfigHelper.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/config/BaseConfigTest.java
@@ -14,33 +14,20 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-package org.apache.camel.dsl.jbang.core.commands;
+package org.apache.camel.dsl.jbang.core.commands.config;
 
 import java.io.IOException;
 import java.nio.file.Files;
-import java.nio.file.Path;
 import java.nio.file.Paths;
-import java.nio.file.StandardOpenOption;
 
+import org.apache.camel.dsl.jbang.core.commands.CamelCommandBaseTest;
 import org.apache.camel.dsl.jbang.core.common.CommandLineHelper;
+import org.junit.jupiter.api.AfterEach;
 
-public final class UserConfigHelper {
-
-    private UserConfigHelper() {
-        // prevent instantiation of utility class
-    }
-
-    public static void createUserConfig(String content) throws IOException {
-        CommandLineHelper.useHomeDir("target");
-        Path userConfigDir = Paths.get("target");
-        if (!userConfigDir.toFile().exists()) {
-            userConfigDir.toFile().mkdirs();
-        }
+public class BaseConfigTest extends CamelCommandBaseTest {
 
-        
Files.writeString(userConfigDir.resolve(CommandLineHelper.USER_CONFIG), content,
-                StandardOpenOption.CREATE,
-                StandardOpenOption.WRITE,
-                StandardOpenOption.TRUNCATE_EXISTING);
+    @AfterEach
+    void removeLocalConfigFile() throws IOException {
+        Files.deleteIfExists(Paths.get(CommandLineHelper.USER_CONFIG));
     }
 }
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigGetTest.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigGetTest.java
index 5bd4e722d8d..3c4556aa0b3 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigGetTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigGetTest.java
@@ -17,13 +17,12 @@
 
 package org.apache.camel.dsl.jbang.core.commands.config;
 
-import org.apache.camel.dsl.jbang.core.commands.CamelCommandBaseTest;
 import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
 import org.apache.camel.dsl.jbang.core.commands.UserConfigHelper;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
-class ConfigGetTest extends CamelCommandBaseTest {
+class ConfigGetTest extends BaseConfigTest {
 
     @Test
     public void shouldGetConfig() throws Exception {
@@ -47,4 +46,16 @@ class ConfigGetTest extends CamelCommandBaseTest {
         Assertions.assertEquals("foo key not found", printer.getOutput());
     }
 
+    @Test
+    public void shouldGetLocalConfig() throws Exception {
+        UserConfigHelper.createUserConfig("foo=bar", true);
+
+        ConfigGet command = new ConfigGet(new 
CamelJBangMain().withPrinter(printer));
+        command.key = "foo";
+        command.local = true;
+        command.doCall();
+
+        Assertions.assertEquals("bar", printer.getOutput());
+    }
+
 }
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigListTest.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigListTest.java
index ab458d5564b..7058d3266fd 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigListTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigListTest.java
@@ -19,13 +19,12 @@ package org.apache.camel.dsl.jbang.core.commands.config;
 
 import java.util.List;
 
-import org.apache.camel.dsl.jbang.core.commands.CamelCommandBaseTest;
 import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
 import org.apache.camel.dsl.jbang.core.commands.UserConfigHelper;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
-class ConfigListTest extends CamelCommandBaseTest {
+class ConfigListTest extends BaseConfigTest {
 
     @Test
     public void shouldHandleEmptyConfig() throws Exception {
@@ -55,4 +54,20 @@ class ConfigListTest extends CamelCommandBaseTest {
         Assertions.assertEquals("foo = bar", lines.get(2));
     }
 
+    @Test
+    public void shouldListLocalUserConfig() throws Exception {
+        UserConfigHelper.createUserConfig("""
+                camel-version=local
+                kamelets-version=local
+                """, true);
+
+        ConfigList command = new ConfigList(new 
CamelJBangMain().withPrinter(printer));
+        command.local = true;
+        command.doCall();
+
+        List<String> lines = printer.getLines();
+        Assertions.assertEquals(2, lines.size());
+        Assertions.assertEquals("camel-version = local", lines.get(0));
+        Assertions.assertEquals("kamelets-version = local", lines.get(1));
+    }
 }
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigSetTest.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigSetTest.java
index 4aaeeda5b5f..9165bc2f086 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigSetTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigSetTest.java
@@ -17,14 +17,13 @@
 
 package org.apache.camel.dsl.jbang.core.commands.config;
 
-import org.apache.camel.dsl.jbang.core.commands.CamelCommandBaseTest;
 import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
 import org.apache.camel.dsl.jbang.core.commands.UserConfigHelper;
 import org.apache.camel.dsl.jbang.core.common.CommandLineHelper;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
-class ConfigSetTest extends CamelCommandBaseTest {
+class ConfigSetTest extends BaseConfigTest {
 
     @Test
     public void shouldSetConfig() throws Exception {
@@ -58,4 +57,19 @@ class ConfigSetTest extends CamelCommandBaseTest {
         });
     }
 
+    @Test
+    public void setLocalConfig() throws Exception {
+        ConfigSet command = new ConfigSet(new 
CamelJBangMain().withPrinter(printer));
+        command.configuration = "foo=local";
+        command.local = true;
+        command.doCall();
+
+        Assertions.assertEquals("", printer.getOutput());
+
+        CommandLineHelper.loadProperties(properties -> {
+            Assertions.assertEquals(1, properties.size());
+            Assertions.assertEquals("local", properties.get("foo"));
+        }, true);
+    }
+
 }
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigUnsetTest.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigUnsetTest.java
index 3be78082a20..a1c7f6bb2bf 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigUnsetTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/config/ConfigUnsetTest.java
@@ -17,14 +17,13 @@
 
 package org.apache.camel.dsl.jbang.core.commands.config;
 
-import org.apache.camel.dsl.jbang.core.commands.CamelCommandBaseTest;
 import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
 import org.apache.camel.dsl.jbang.core.commands.UserConfigHelper;
 import org.apache.camel.dsl.jbang.core.common.CommandLineHelper;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
-class ConfigUnsetTest extends CamelCommandBaseTest {
+class ConfigUnsetTest extends BaseConfigTest {
 
     @Test
     public void shouldUnsetConfig() throws Exception {
@@ -67,4 +66,23 @@ class ConfigUnsetTest extends CamelCommandBaseTest {
         });
     }
 
+    @Test
+    public void unsetLocalConfig() throws Exception {
+        UserConfigHelper.createUserConfig("""
+                camel-version=local
+                foo=bar
+                """, true);
+
+        ConfigUnset command = new ConfigUnset(new 
CamelJBangMain().withPrinter(printer));
+        command.key = "foo";
+        command.local = true;
+        command.doCall();
+
+        Assertions.assertEquals("", printer.getOutput());
+
+        CommandLineHelper.loadProperties(properties -> {
+            Assertions.assertEquals(1, properties.size());
+            Assertions.assertEquals("local", properties.get("camel-version"));
+        }, true);
+    }
 }

Reply via email to