davsclaus commented on code in PR #29917:
URL: https://github.com/apache/camel/pull/29917#discussion_r4573217144


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/CommandLineHelper.java:
##########
@@ -136,36 +136,45 @@ public static void 
augmentWithUserConfiguration(CommandTree commandLine) {
     }
 
     public static void augmentWithUserConfiguration(CommandTree commandLine, 
Printer printer) {
-        Path file = getUserConfigurationFile();
-        if (Files.isRegularFile(file) && Files.exists(file)) {
-            Properties properties = new Properties();
-            try (Reader reader = Files.newBufferedReader(file, 
StandardCharsets.UTF_8)) {
-                properties.load(reader);
-            } catch (Exception e) {
-                // best-effort: a malformed config file (e.g. malformed 
unicode escape) must never break the CLI;
-                // warn the user so they know to fix it, but let the command 
continue without defaults.
-                // Warn once per path: loadProperties may also warn for the 
same file, so we deduplicate here.
-                String key = file.toAbsolutePath().toString();
-                if (WARNED_PATHS.add(key)) {
-                    printer.printErr(
-                            "Warning: could not parse '" + 
file.toAbsolutePath() + "' (" + e.getMessage()
-                                     + "). Edit the file by hand, escaping 
'\\' as '\\\\' or using '/'.");
-                }
-                return;
-            }
-
+        Properties properties = loadUserConfiguration(printer);
+        if (!properties.isEmpty()) {
             commandLine.setDefaultValueProvider(new 
CamelUserConfigDefaultValueProvider(properties));
         }
     }
 
-    private static Path getUserConfigurationFile() {
-        Path file;
-        if (Files.exists(Paths.get(LOCAL_USER_CONFIG))) {
-            file = Paths.get(LOCAL_USER_CONFIG);
-        } else {
-            file = getUserPropertyFile(false);
+    /**
+     * The user configuration as the commands use it: the global file in the 
user home ({@value #USER_CONFIG}), with the
+     * local file of the current directory ({@value #LOCAL_USER_CONFIG}) laid 
over it, so a key of the local file wins.
+     * Before, a local file hid the whole global one, such as its repos or 
camel-version (CAMEL-26931). A file that
+     * cannot be parsed is left out, with a warning (once per file).
+     */
+    public static Properties loadUserConfiguration(Printer printer) {
+        Properties answer = new OrderedProperties();
+        readInto(getUserPropertyFile(false), answer, printer);
+        readInto(Paths.get(LOCAL_USER_CONFIG), answer, printer);
+        return answer;
+    }
+
+    private static void readInto(Path file, Properties answer, Printer 
printer) {
+        if (!Files.isRegularFile(file)) {
+            return;
+        }
+        Properties properties = new Properties();

Review Comment:
   Done in acf3ef205545 (the comment) and 7b495579dfd0 (`OrderedProperties` for 
the file buffer, and the `@param`/`@return` tags). acf3ef205545's message 
mentions all three, but it only has the comment fix; 7b495579dfd0 adds the 
other two.
   
   _Claude Code on behalf of davsclaus_



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to