Beefed up command-line usage string.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@629 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
5a6892900e
commit
c241d386a7
|
|
@ -1,6 +1,8 @@
|
|||
package org.broadinstitute.sting.utils.cmdLine;
|
||||
|
||||
import org.apache.log4j.*;
|
||||
import org.broadinstitute.sting.utils.JVMUtils;
|
||||
import org.broadinstitute.sting.utils.StingException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
|
|
@ -73,12 +75,43 @@ public abstract class CommandLineProgram {
|
|||
required=false)
|
||||
protected Boolean debugMode = false;
|
||||
|
||||
/**
|
||||
* this is used to indicate if they've asked for help
|
||||
*/
|
||||
@Argument(fullName="help",shortName="h",doc="Generate this help message",required=false)
|
||||
public Boolean help = false;
|
||||
|
||||
/**
|
||||
* our logging output patterns
|
||||
*/
|
||||
private static String patternString = "%p %m %n";
|
||||
private static String debugPatternString = "%n[level] %p%n[date]\t\t %d{dd MMM yyyy HH:mm:ss,SSS} %n[class]\t\t %C %n[location]\t %l %n[line number]\t %L %n[message]\t %m %n";
|
||||
|
||||
/**
|
||||
* Retrieves text from the application regarding what parameters to put on the
|
||||
* JVM command line to run this application.
|
||||
* @return helpful instructions on the class / jar to run.
|
||||
*/
|
||||
protected String getRunningInstructions() {
|
||||
// Default implementation to find a command line that makes sense.
|
||||
// If the user is running from a jar, return '-jar <jarname>'; otherwise
|
||||
// return the full class name.
|
||||
String runningInstructions = null;
|
||||
try {
|
||||
runningInstructions = JVMUtils.getLocationFor( getClass() ).getName();
|
||||
}
|
||||
catch( IOException ex ) {
|
||||
throw new StingException("Unable to determine running instructions", ex);
|
||||
}
|
||||
|
||||
if( runningInstructions.endsWith(".jar") )
|
||||
runningInstructions = String.format("-jar %s", runningInstructions);
|
||||
else
|
||||
runningInstructions = getClass().getName();
|
||||
|
||||
return runningInstructions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Will this application want to vary its argument list dynamically?
|
||||
* If so, parse the command-line options and then prompt the subclass to return
|
||||
|
|
@ -109,12 +142,6 @@ public abstract class CommandLineProgram {
|
|||
protected abstract int execute();
|
||||
|
||||
|
||||
/**
|
||||
* this is used to indicate if they've asked for help
|
||||
*/
|
||||
@Argument(fullName="help",shortName="h",doc="Generate this help message",required=false)
|
||||
public Boolean help = false;
|
||||
|
||||
/**
|
||||
* This function is called to start processing the command line, and kick
|
||||
* off the execute message of the program.
|
||||
|
|
@ -177,7 +204,7 @@ public abstract class CommandLineProgram {
|
|||
|
||||
// they asked for help, give it to them
|
||||
if (clp.help) {
|
||||
parser.printHelp();
|
||||
parser.printHelp( clp.getRunningInstructions() );
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
|
|
@ -206,7 +233,7 @@ public abstract class CommandLineProgram {
|
|||
}
|
||||
catch (ParseException e) {
|
||||
logger.fatal("Unable to pass command line arguments: " + e.getMessage() );
|
||||
clp.parser.printHelp();
|
||||
clp.parser.printHelp( clp.getRunningInstructions() );
|
||||
}
|
||||
catch (Exception e) {
|
||||
// we catch all exceptions here. if it makes it to this level, we're in trouble. Let's bail!
|
||||
|
|
|
|||
|
|
@ -42,12 +42,12 @@ public class HelpFormatter {
|
|||
* Prints the help, given a collection of argument definitions.
|
||||
* @param argumentDefinitions Argument definitions for which help should be printed.
|
||||
*/
|
||||
public void printHelp( ArgumentDefinitions argumentDefinitions ) {
|
||||
public void printHelp( String runningInstructions, ArgumentDefinitions argumentDefinitions ) {
|
||||
SortedSet<ArgumentDefinition> mainArguments = getMainArguments( argumentDefinitions );
|
||||
Map<String,SortedSet<ArgumentDefinition>> pluginsByGroup = getPluginArguments( argumentDefinitions );
|
||||
|
||||
System.out.printf("%s%s%n",
|
||||
getSynopsis(mainArguments,pluginsByGroup),
|
||||
getSynopsis(runningInstructions,mainArguments,pluginsByGroup),
|
||||
getDetailed(mainArguments,pluginsByGroup) );
|
||||
}
|
||||
|
||||
|
|
@ -89,15 +89,18 @@ public class HelpFormatter {
|
|||
/**
|
||||
* Gets the synopsis: the actual command to run.
|
||||
* @param mainArguments Main program arguments.
|
||||
* @praam pluginArgumentGroups Groups of plugin arguments
|
||||
* @param runningInstructions Instructions on how to run hte application.
|
||||
* @param pluginArgumentGroups Groups of plugin arguments
|
||||
* @return A synopsis line.
|
||||
*/
|
||||
private String getSynopsis( SortedSet<ArgumentDefinition> mainArguments, Map<String,SortedSet<ArgumentDefinition>> pluginArgumentGroups ) {
|
||||
private String getSynopsis( String runningInstructions,
|
||||
SortedSet<ArgumentDefinition> mainArguments,
|
||||
Map<String,SortedSet<ArgumentDefinition>> pluginArgumentGroups ) {
|
||||
// Build out the synopsis all as one long line.
|
||||
StringBuilder lineBuilder = new StringBuilder();
|
||||
Formatter lineFormatter = new Formatter( lineBuilder );
|
||||
|
||||
lineFormatter.format("java -jar dist/GenomeAnalysisTK.jar");
|
||||
lineFormatter.format("java %s", runningInstructions);
|
||||
|
||||
List<ArgumentDefinition> argumentDefinitions = new ArrayList<ArgumentDefinition>();
|
||||
argumentDefinitions.addAll( mainArguments );
|
||||
|
|
|
|||
|
|
@ -218,8 +218,8 @@ public class ParsingEngine {
|
|||
/**
|
||||
* Prints out the help associated with these command-line argument definitions.
|
||||
*/
|
||||
public void printHelp() {
|
||||
new HelpFormatter().printHelp(argumentDefinitions);
|
||||
public void printHelp( String runningInstructions ) {
|
||||
new HelpFormatter().printHelp(runningInstructions,argumentDefinitions);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue