Added an option to print out the version string

@argument (-)-version
(should this be @hidden?)

Prints out the version to System.out and quit(0)
No tests. (any ideas on how to test this would be happily accepted)
This commit is contained in:
Yossi Farjoun 2013-02-15 12:38:29 -05:00
parent bbfbe1bc26
commit aa99a5f47c
1 changed files with 28 additions and 0 deletions

View File

@ -62,6 +62,11 @@ public abstract class CommandLineProgram {
@Argument(fullName = "help", shortName = "h", doc = "Generate this help message", required = false)
public Boolean help = false;
/** This is used to indicate if they've asked for the version information */
@Argument(fullName = "version", shortName = "version", doc ="Output version information", required = false)
public Boolean version = false;
/** our logging output patterns */
private static final String patternString = "%-5p %d{HH:mm:ss,SSS} %C{1} - %m %n";
@ -199,6 +204,9 @@ public abstract class CommandLineProgram {
parser.addArgumentSource(clp.getArgumentSourceName(argumentSource), argumentSource);
parsedArgs = parser.parse(args);
if (isVersionPresent(parser))
printVersionAndExit();
if (isHelpPresent(parser))
printHelpAndExit(clp, parser);
@ -315,6 +323,26 @@ public abstract class CommandLineProgram {
System.exit(0);
}
/**
* Do a cursory search for the argument "version".
*
* @param parser Parser
*
* @return True if version is present; false otherwise.
*/
private static boolean isVersionPresent(ParsingEngine parser) {
return parser.isArgumentPresent("version");
}
/**
* Print help and exit.
*/
private static void printVersionAndExit() {
System.out.println(CommandLineGATK.getVersionNumber().toString());
System.exit(0);
}
private static void errorPrintf(String format, Object... s) {
String formatted = String.format(format, s);