Simple prototype
This commit is contained in:
parent
8534efdf60
commit
cb7e0e4c35
2 changed files with 46 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
package de.vanitasvitae.imi.codes;
|
package de.vanitasvitae.imi.codes;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class InputValidator {
|
public class InputValidator {
|
||||||
|
@ -74,4 +75,19 @@ public class InputValidator {
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate, that the user-provided path is writable and that any parent folders exist.
|
||||||
|
* Otherwise throw a {@link InvalidOptionException}.
|
||||||
|
*
|
||||||
|
* @param path file path (absolut or relative) as a string.
|
||||||
|
* @return file
|
||||||
|
*
|
||||||
|
* @throws InvalidOptionException in case any parent folder does not exist, the path points to a directory or the
|
||||||
|
* destination is not writable.
|
||||||
|
*/
|
||||||
|
public static File validateOutputPath(String path) throws InvalidOptionException {
|
||||||
|
// TODO
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package de.vanitasvitae.imi.codes;
|
package de.vanitasvitae.imi.codes;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import org.apache.commons.cli.CommandLine;
|
import org.apache.commons.cli.CommandLine;
|
||||||
import org.apache.commons.cli.CommandLineParser;
|
import org.apache.commons.cli.CommandLineParser;
|
||||||
import org.apache.commons.cli.DefaultParser;
|
import org.apache.commons.cli.DefaultParser;
|
||||||
|
@ -26,11 +28,38 @@ public class Main {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// User issues '-h', so just show help text and exit.
|
// User issues '-h', so just show help text and exit right now.
|
||||||
if (arguments.hasOption(Arguments.HELP)) {
|
if (arguments.hasOption(Arguments.HELP)) {
|
||||||
printHelp(options);
|
printHelp(options);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse arguments
|
||||||
|
String studyNumber;
|
||||||
|
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++) {
|
||||||
|
System.out.format("%s%04d%n", studyNumber + sampleType, i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue