|
@@ -26,17 +26,25 @@ public final class Parameters {
|
|
|
|
|
|
|
|
private static Logger logger = LogManager.getLogger(Parameters.class);
|
|
private static Logger logger = LogManager.getLogger(Parameters.class);
|
|
|
|
|
|
|
|
|
|
+ private JCommander jCommander;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Static method to parse input parameters.
|
|
* Static method to parse input parameters.
|
|
|
|
|
+ * @param appConfig - main configuration of the application.
|
|
|
* @param args - array of parameters in format e.g. ["-cf", "fileName"].
|
|
* @param args - array of parameters in format e.g. ["-cf", "fileName"].
|
|
|
* @return instance of {@code Parameters}.
|
|
* @return instance of {@code Parameters}.
|
|
|
* @throws IOException throws if is chosen "-cf" or "-config-file" parameter and the file does not exist.
|
|
* @throws IOException throws if is chosen "-cf" or "-config-file" parameter and the file does not exist.
|
|
|
*/
|
|
*/
|
|
|
- public static Parameters parse(String... args) throws IOException {
|
|
|
|
|
|
|
+ public static Parameters parse(AppConfig appConfig, String... args) throws IOException {
|
|
|
logger.debug("Parsing input parameters {}", Arrays.toString(args));
|
|
logger.debug("Parsing input parameters {}", Arrays.toString(args));
|
|
|
|
|
|
|
|
Parameters parameters = new Parameters();
|
|
Parameters parameters = new Parameters();
|
|
|
- JCommander.newBuilder().addObject(parameters).build().parse(args);
|
|
|
|
|
|
|
+ JCommander jCommander = JCommander.newBuilder()
|
|
|
|
|
+ .programName(appConfig.getName())
|
|
|
|
|
+ .addObject(parameters).build();
|
|
|
|
|
+ parameters.jCommander = jCommander;
|
|
|
|
|
+
|
|
|
|
|
+ jCommander.parse(args);
|
|
|
|
|
|
|
|
String configFileName = parameters.getConfigFileName();
|
|
String configFileName = parameters.getConfigFileName();
|
|
|
logger.debug("Checking existence of configuration file {}", configFileName);
|
|
logger.debug("Checking existence of configuration file {}", configFileName);
|
|
@@ -48,6 +56,9 @@ public final class Parameters {
|
|
|
return parameters;
|
|
return parameters;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Parameter(names = {"-h", "-help"}, help = true)
|
|
|
|
|
+ private boolean help = false;
|
|
|
|
|
+
|
|
|
@Parameter(names = {"-cf", "-config-file"}, description = "Configuration file in .yaml format.")
|
|
@Parameter(names = {"-cf", "-config-file"}, description = "Configuration file in .yaml format.")
|
|
|
private String configFileName;
|
|
private String configFileName;
|
|
|
|
|
|
|
@@ -58,4 +69,12 @@ public final class Parameters {
|
|
|
public String getConfigFileName() {
|
|
public String getConfigFileName() {
|
|
|
return configFileName;
|
|
return configFileName;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public boolean isHelp() {
|
|
|
|
|
+ return help;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void printHelp() {
|
|
|
|
|
+ jCommander.usage();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|