davsclaus commented on code in PR #29917:
URL: https://github.com/apache/camel/pull/29917#discussion_r4573217030
##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelCommand.java:
##########
@@ -347,8 +347,8 @@ protected int terminalWidth() {
protected void printConfigurationValues(String header) {
if (processedCommand != null) {
- final Properties configProperties = new Properties();
- CommandLineHelper.loadProperties(configProperties::putAll);
+ // the global user configuration with the local one laid over it,
as the option defaults come from
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_
##########
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).
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]