2018-11-14 20:38:51 +01:00
|
|
|
package de.vanitasvitae.imi.codes;
|
|
|
|
|
2018-11-15 02:03:52 +01:00
|
|
|
import java.io.File;
|
|
|
|
|
2018-11-14 20:38:51 +01:00
|
|
|
import org.apache.commons.cli.CommandLine;
|
|
|
|
import org.apache.commons.cli.CommandLineParser;
|
|
|
|
import org.apache.commons.cli.DefaultParser;
|
|
|
|
import org.apache.commons.cli.HelpFormatter;
|
|
|
|
import org.apache.commons.cli.Options;
|
|
|
|
import org.apache.commons.cli.ParseException;
|
|
|
|
|
|
|
|
public class Main {
|
|
|
|
|
|
|
|
private static final String NAME_JAR = "imicodes";
|
|
|
|
private static final String HELP_HEADER = "Generate ID codes for sample tubes.";
|
|
|
|
private static final String HELP_FOOTER = "\nAuthor: Paul Schaub <paul.schaub@wwu.de>";
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
Options options = Arguments.getCommandLineOptions();
|
|
|
|
CommandLineParser parser = new DefaultParser();
|
|
|
|
|
|
|
|
CommandLine arguments;
|
|
|
|
try {
|
|
|
|
arguments = parser.parse(options, args);
|
|
|
|
} catch (ParseException e) {
|
|
|
|
System.out.println(e.getMessage());
|
|
|
|
printHelp(options);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-15 02:03:52 +01:00
|
|
|
// User issues '-h', so just show help text and exit right now.
|
2018-11-14 20:38:51 +01:00
|
|
|
if (arguments.hasOption(Arguments.HELP)) {
|
|
|
|
printHelp(options);
|
|
|
|
return;
|
|
|
|
}
|
2018-11-15 02:03:52 +01:00
|
|
|
|
|
|
|
// Parse arguments
|
2018-11-15 17:54:34 +01:00
|
|
|
StudyNumber studyNumber;
|
2018-11-15 02:03:52 +01:00
|
|
|
SampleType sampleType;
|
|
|
|
int numberOfCodes;
|
|
|
|
File outputPath;
|
|
|
|
boolean externalBrowser;
|
|
|
|
|
|
|
|
try {
|
|
|
|
studyNumber = InputValidator.validateStudyNumber(arguments.getOptionValue(Arguments.STUDY_NUMBER));
|
|
|
|
sampleType = InputValidator.validateSampleType(arguments.getOptionValue(Arguments.SAMPLE_TYPE));
|
|
|
|
numberOfCodes = InputValidator.validateNumberOfCodes(arguments.getOptionValue(Arguments.NUMBER_CODES));
|
|
|
|
outputPath = InputValidator.validateOutputPath(arguments.getOptionValue(Arguments.OUTPUT_DESTINATION));
|
|
|
|
externalBrowser = arguments.hasOption(Arguments.EXTERNAL_BROWSER);
|
|
|
|
} catch (InvalidOptionException e) {
|
|
|
|
// Something is wrong with the users input, so exit.
|
|
|
|
System.out.println(e.getMessage());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Debug. TODO: Remove
|
|
|
|
System.out.println("StudyNr: " + studyNumber + " sampleType: " + sampleType + " #codes: " + numberOfCodes
|
|
|
|
+ " output: " + outputPath + " browser: " + externalBrowser);
|
|
|
|
|
|
|
|
for (int i = 0; i < numberOfCodes; i++) {
|
2018-11-15 17:54:34 +01:00
|
|
|
System.out.format("%s%04d%n", studyNumber.toString() + sampleType, i);
|
2018-11-15 02:03:52 +01:00
|
|
|
}
|
2018-11-14 20:38:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print a descriptive help text to the console.
|
|
|
|
*
|
|
|
|
* @param options {@link Options} for which we want to print a help text.
|
|
|
|
*/
|
|
|
|
private static void printHelp(Options options) {
|
|
|
|
HelpFormatter formatter = new HelpFormatter();
|
|
|
|
|
|
|
|
formatter.printHelp(NAME_JAR, HELP_HEADER, options, HELP_FOOTER, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|