-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve diagnose for invalide environment/command line arguments #19
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,7 @@ public static MetaConfig parseOptions(String[] args, String defaultConfigFile, O | |
} | ||
|
||
CmdLineException problem = null; | ||
boolean invalidValueGiven = false; | ||
try { | ||
// First try, use options form environment and command line. | ||
Collection<String> arguments = new ArrayList<>(envArgs); | ||
|
@@ -71,13 +72,18 @@ public static MetaConfig parseOptions(String[] args, String defaultConfigFile, O | |
} catch (CmdLineException ex) { | ||
// Happens, when required configurations are not given on the command line. | ||
problem = ex; | ||
String message = ex.getMessage(); | ||
invalidValueGiven = message != null && message.contains(" is not a valid value for "); | ||
if (invalidValueGiven) { | ||
LOG.warn("{}. Reading from environment/command line aborted", message); | ||
} | ||
} | ||
|
||
String argFile = metaConfig.configFile; | ||
|
||
File file; | ||
if (argFile != null && !argFile.isBlank()) { | ||
if ("none".equals(argFile.toLowerCase())) { | ||
if ("none".equalsIgnoreCase(argFile)) { | ||
file = null; | ||
} else { | ||
file = new File(argFile); | ||
|
@@ -87,7 +93,7 @@ public static MetaConfig parseOptions(String[] args, String defaultConfigFile, O | |
} | ||
} | ||
} else if (defaultConfigFile != null) { | ||
String fileName = System.getProperty("user.home") + "/" + defaultConfigFile; | ||
String fileName = System.getProperty("user.home") + File.pathSeparator + defaultConfigFile; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Top! Was für ein Anfängerfehler von mir.... |
||
file = new File(fileName); | ||
if (!file.exists()) { | ||
file = null; | ||
|
@@ -97,13 +103,21 @@ public static MetaConfig parseOptions(String[] args, String defaultConfigFile, O | |
} | ||
|
||
if (file!= null) { | ||
LOG.debug("Reading options from: " + file.getAbsolutePath()); | ||
if (invalidValueGiven) { | ||
LOG.warn("Reading options from: {}", file.getAbsolutePath()); | ||
} else { | ||
LOG.debug("Reading options from: {}", file.getAbsolutePath()); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Das eigentliche Problem ist aber wohl, dass beim zweiten Durchlauf, wenn die Konfigurationsdatei gelesen wird, die Umgebungsvariablen komplett ignoriert werden. Die Argumente werden wieder hinzugefügt, die Umgebungsvariablen aber nicht. |
||
|
||
ConfigFile configFile = new ConfigFile(file); | ||
|
||
// Parse all arguments again to check for required arguments not given but give | ||
// precedence to arguments given on the command line. | ||
// Parse all arguments again to check for required arguments not given and to | ||
// allow overwriting configuration file arguments with environment and command | ||
// line. | ||
// Use the following precedence order: Arguments in the configuration file (lowest), | ||
// arguments from the environment, arguments given on the command line (highest). | ||
Collection<String> arguments = new ArrayList<>(configFile.toArguments()); | ||
arguments.addAll(envArgs); | ||
arguments.addAll(Arrays.asList(args)); | ||
|
||
parser.parseArgument(arguments); | ||
|
@@ -135,7 +149,7 @@ public static String getValueFromEnvironment(String optionName) { | |
String env = optionName.substring(2).replace('-', '_').toUpperCase(); | ||
String value = System.getenv(env); | ||
if (value != null) { | ||
LOG.info("Using '" + optionName + "' from environment: " + env + "=" + value); | ||
LOG.info("Using '{}' from environment: {}={}", optionName, env, value); | ||
} | ||
return value; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gute Idee - wird das an anderen Stellen der Konfigurationsverarbeitung eigentlich auch so gemacht?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aktuell wird in phoneblock
recordings
noch nur mit equals geprüft und die MethodegetConfigFile
ausMetaConfig
ist auch noch nicht angepasst.