From aa99a5f47c471a9a72396d9a98c7f6edea3a2987 Mon Sep 17 00:00:00 2001 From: Yossi Farjoun Date: Fri, 15 Feb 2013 12:38:29 -0500 Subject: [PATCH] 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) --- .../sting/commandline/CommandLineProgram.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/public/java/src/org/broadinstitute/sting/commandline/CommandLineProgram.java b/public/java/src/org/broadinstitute/sting/commandline/CommandLineProgram.java index e2444f38a..08aa5f8b3 100644 --- a/public/java/src/org/broadinstitute/sting/commandline/CommandLineProgram.java +++ b/public/java/src/org/broadinstitute/sting/commandline/CommandLineProgram.java @@ -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);