2010-04-20 07:00:08 +08:00
|
|
|
/*
|
2013-01-11 06:04:08 +08:00
|
|
|
* Copyright (c) 2012 The Broad Institute
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
|
* restriction, including without limitation the rights to use,
|
|
|
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following
|
|
|
|
|
* conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
|
|
|
|
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
2010-04-20 07:00:08 +08:00
|
|
|
|
2009-05-11 10:07:20 +08:00
|
|
|
package org.broadinstitute.sting.gatk;
|
|
|
|
|
|
2012-01-25 04:30:04 +08:00
|
|
|
import net.sf.picard.PicardException;
|
|
|
|
|
import net.sf.samtools.SAMException;
|
2010-10-22 23:22:17 +08:00
|
|
|
import org.broad.tribble.TribbleException;
|
2011-07-18 08:29:58 +08:00
|
|
|
import org.broadinstitute.sting.commandline.Argument;
|
|
|
|
|
import org.broadinstitute.sting.commandline.ArgumentCollection;
|
|
|
|
|
import org.broadinstitute.sting.commandline.CommandLineProgram;
|
2010-01-15 08:14:35 +08:00
|
|
|
import org.broadinstitute.sting.gatk.arguments.GATKArgumentCollection;
|
2011-08-18 22:31:32 +08:00
|
|
|
import org.broadinstitute.sting.gatk.refdata.tracks.FeatureManager;
|
2010-10-02 02:31:19 +08:00
|
|
|
import org.broadinstitute.sting.gatk.walkers.Attribution;
|
2011-07-18 08:29:58 +08:00
|
|
|
import org.broadinstitute.sting.gatk.walkers.Walker;
|
2010-09-12 22:02:43 +08:00
|
|
|
import org.broadinstitute.sting.utils.exceptions.UserException;
|
2013-01-07 03:30:45 +08:00
|
|
|
import org.broadinstitute.sting.utils.help.*;
|
2011-07-18 08:29:58 +08:00
|
|
|
import org.broadinstitute.sting.utils.text.TextFormattingUtils;
|
2009-05-11 10:07:20 +08:00
|
|
|
|
2009-07-22 06:23:28 +08:00
|
|
|
import java.util.*;
|
2009-05-16 05:02:12 +08:00
|
|
|
|
2009-05-11 10:07:20 +08:00
|
|
|
/**
|
2012-07-26 05:23:02 +08:00
|
|
|
* All command line parameters accepted by all tools in the GATK.
|
|
|
|
|
*
|
2013-12-11 02:19:53 +08:00
|
|
|
* <h3>Info for general users</h3>
|
2011-07-24 10:07:30 +08:00
|
|
|
*
|
2013-12-11 02:19:53 +08:00
|
|
|
* <p>This is a list of options and parameters that are generally available to all tools in the GATK.</p>
|
|
|
|
|
*
|
|
|
|
|
* <p>There may be a few restrictions, which are indicated in individual argument descriptions. For example the -BQSR
|
|
|
|
|
* argument is only meant to be used with a subset of tools, and the -pedigree argument will only be effectively used
|
|
|
|
|
* by a subset of tools as well. Some arguments conflict with others, and some conversely are dependent on others. This
|
|
|
|
|
* is all indicated in the detailed argument descriptions, so be sure to read those in their entirety rather than just
|
|
|
|
|
* skimming the one-line summaey in the table.</p>
|
|
|
|
|
*
|
|
|
|
|
* <h3>Info for developers</h3>
|
|
|
|
|
*
|
|
|
|
|
* <p>This class is the GATK engine itself, which manages map/reduce data access and runs walkers.</p>
|
|
|
|
|
*
|
|
|
|
|
* <p>We run command line GATK programs using this class. It gets the command line args, parses them, and hands the
|
|
|
|
|
* gatk all the parsed out information. Pretty much anything dealing with the underlying system should go here;
|
|
|
|
|
* the GATK engine should deal with any data related information.</p>
|
2009-05-11 10:07:20 +08:00
|
|
|
*/
|
2013-02-13 05:27:18 +08:00
|
|
|
@DocumentedGATKFeature(groupName = HelpConstants.DOCS_CAT_ENGINE)
|
2009-07-17 06:02:21 +08:00
|
|
|
public class CommandLineGATK extends CommandLineExecutable {
|
2013-12-11 02:19:53 +08:00
|
|
|
/**
|
|
|
|
|
* A complete list of tools (sometimes also called walkers because they "walk" through the data to perform analyses)
|
|
|
|
|
* is available in the online documentation.
|
|
|
|
|
*/
|
|
|
|
|
@Argument(fullName = "analysis_type", shortName = "T", doc = "Name of the tool to run")
|
2009-07-17 06:48:44 +08:00
|
|
|
private String analysisName = null;
|
|
|
|
|
|
2009-07-17 06:02:21 +08:00
|
|
|
// our argument collection, the collection of command line args we accept
|
|
|
|
|
@ArgumentCollection
|
2009-10-29 03:56:05 +08:00
|
|
|
private GATKArgumentCollection argCollection = new GATKArgumentCollection();
|
2009-05-11 10:07:20 +08:00
|
|
|
|
2009-07-14 05:56:41 +08:00
|
|
|
/**
|
|
|
|
|
* Get pleasing info about the GATK.
|
2009-10-29 03:56:05 +08:00
|
|
|
*
|
2009-07-17 06:02:21 +08:00
|
|
|
* @return A list of Strings that contain pleasant info about the GATK.
|
2009-07-14 05:56:41 +08:00
|
|
|
*/
|
|
|
|
|
@Override
|
2009-07-22 06:23:28 +08:00
|
|
|
protected ApplicationDetails getApplicationDetails() {
|
2009-10-29 03:56:05 +08:00
|
|
|
return new ApplicationDetails(createApplicationHeader(),
|
2010-10-02 02:31:19 +08:00
|
|
|
getAttribution(),
|
2009-10-29 03:56:05 +08:00
|
|
|
ApplicationDetails.createDefaultRunningInstructions(getClass()),
|
|
|
|
|
getAdditionalHelp());
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-11 10:07:20 +08:00
|
|
|
@Override
|
2010-09-22 23:27:58 +08:00
|
|
|
public String getAnalysisName() {
|
2009-07-17 06:02:21 +08:00
|
|
|
return analysisName;
|
2009-05-11 10:07:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2009-07-17 06:02:21 +08:00
|
|
|
protected GATKArgumentCollection getArgumentCollection() {
|
2009-05-11 10:07:20 +08:00
|
|
|
return argCollection;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-29 03:56:05 +08:00
|
|
|
/**
|
|
|
|
|
* Required main method implementation.
|
|
|
|
|
*/
|
2009-07-17 06:02:21 +08:00
|
|
|
public static void main(String[] argv) {
|
|
|
|
|
try {
|
|
|
|
|
CommandLineGATK instance = new CommandLineGATK();
|
|
|
|
|
start(instance, argv);
|
2009-09-05 03:13:37 +08:00
|
|
|
System.exit(CommandLineProgram.result); // todo -- this is a painful hack
|
2010-09-12 22:02:43 +08:00
|
|
|
} catch (UserException e) {
|
2010-09-09 19:32:20 +08:00
|
|
|
exitSystemWithUserError(e);
|
2010-10-22 23:22:17 +08:00
|
|
|
} catch (TribbleException e) {
|
|
|
|
|
// We can generate Tribble Exceptions in weird places when e.g. VCF genotype fields are
|
|
|
|
|
// lazy loaded, so they aren't caught elsewhere and made into User Exceptions
|
|
|
|
|
exitSystemWithUserError(e);
|
2012-01-25 04:30:04 +08:00
|
|
|
} catch(PicardException e) {
|
|
|
|
|
// TODO: Should Picard exceptions be, in general, UserExceptions or ReviewedStingExceptions?
|
|
|
|
|
exitSystemWithError(e);
|
2012-04-03 10:46:56 +08:00
|
|
|
} catch (SAMException e) {
|
2012-07-19 01:56:35 +08:00
|
|
|
checkForMaskedUserErrors(e);
|
2011-04-18 11:52:43 +08:00
|
|
|
exitSystemWithSamError(e);
|
2012-04-03 10:46:56 +08:00
|
|
|
} catch (OutOfMemoryError e) {
|
|
|
|
|
exitSystemWithUserError(new UserException.NotEnoughMemory());
|
2011-09-13 22:49:16 +08:00
|
|
|
} catch (Throwable t) {
|
2012-07-19 01:56:35 +08:00
|
|
|
checkForMaskedUserErrors(t);
|
2011-09-13 22:49:16 +08:00
|
|
|
exitSystemWithError(t);
|
2009-05-16 05:02:12 +08:00
|
|
|
}
|
|
|
|
|
}
|
2009-07-22 06:23:28 +08:00
|
|
|
|
2012-09-07 10:03:18 +08:00
|
|
|
public static final String PICARD_TEXT_SAM_FILE_ERROR_1 = "Cannot use index file with textual SAM file";
|
|
|
|
|
public static final String PICARD_TEXT_SAM_FILE_ERROR_2 = "Cannot retrieve file pointers within SAM text files";
|
2012-10-12 21:38:12 +08:00
|
|
|
public static final String NO_SPACE_LEFT_ON_DEVICE_ERROR = "No space left on device";
|
|
|
|
|
public static final String DISK_QUOTA_EXCEEDED_ERROR = "Disk quota exceeded";
|
|
|
|
|
|
2012-07-19 01:56:35 +08:00
|
|
|
private static void checkForMaskedUserErrors(final Throwable t) {
|
2012-11-27 23:26:17 +08:00
|
|
|
// masked out of memory error
|
|
|
|
|
if ( t instanceof OutOfMemoryError )
|
|
|
|
|
exitSystemWithUserError(new UserException.NotEnoughMemory());
|
|
|
|
|
// masked user error
|
|
|
|
|
if ( t instanceof UserException || t instanceof TribbleException )
|
|
|
|
|
exitSystemWithUserError(new UserException(t.getMessage()));
|
|
|
|
|
|
|
|
|
|
// no message means no masked error
|
2012-07-19 01:56:35 +08:00
|
|
|
final String message = t.getMessage();
|
|
|
|
|
if ( message == null )
|
|
|
|
|
return;
|
|
|
|
|
|
2012-11-27 23:26:17 +08:00
|
|
|
// too many open files error
|
2012-09-07 10:03:18 +08:00
|
|
|
if ( message.contains("Too many open files") )
|
2011-11-22 23:50:22 +08:00
|
|
|
exitSystemWithUserError(new UserException.TooManyOpenFiles());
|
2012-07-19 01:56:35 +08:00
|
|
|
|
2012-07-19 03:11:38 +08:00
|
|
|
// malformed BAM looks like a SAM file
|
2012-11-27 23:26:17 +08:00
|
|
|
if ( message.contains(PICARD_TEXT_SAM_FILE_ERROR_1) || message.contains(PICARD_TEXT_SAM_FILE_ERROR_2) )
|
2012-07-19 01:56:35 +08:00
|
|
|
exitSystemWithSamError(t);
|
2012-07-19 03:11:38 +08:00
|
|
|
|
|
|
|
|
// can't close tribble index when writing
|
2012-09-07 10:03:18 +08:00
|
|
|
if ( message.contains("Unable to close index for") )
|
2012-08-01 03:50:32 +08:00
|
|
|
exitSystemWithUserError(new UserException(t.getCause() == null ? message : t.getCause().getMessage()));
|
2012-07-30 23:59:56 +08:00
|
|
|
|
|
|
|
|
// disk is full
|
2012-10-12 21:38:12 +08:00
|
|
|
if ( message.contains(NO_SPACE_LEFT_ON_DEVICE_ERROR) || message.contains(DISK_QUOTA_EXCEEDED_ERROR) )
|
2012-09-07 10:03:18 +08:00
|
|
|
exitSystemWithUserError(new UserException.NoSpaceOnDevice());
|
2012-09-07 23:27:00 +08:00
|
|
|
|
2012-11-27 23:26:17 +08:00
|
|
|
// masked error wrapped in another one
|
|
|
|
|
if ( t.getCause() != null )
|
|
|
|
|
checkForMaskedUserErrors(t.getCause());
|
2011-11-22 23:50:22 +08:00
|
|
|
}
|
|
|
|
|
|
2009-07-22 06:23:28 +08:00
|
|
|
/**
|
|
|
|
|
* Creates the a short blurb about the GATK, copyright info, and where to get documentation.
|
2009-10-29 03:56:05 +08:00
|
|
|
*
|
2009-07-22 06:23:28 +08:00
|
|
|
* @return The application header.
|
|
|
|
|
*/
|
2009-10-29 03:56:05 +08:00
|
|
|
public static List<String> createApplicationHeader() {
|
2009-07-22 06:23:28 +08:00
|
|
|
List<String> header = new ArrayList<String>();
|
2010-08-29 06:53:32 +08:00
|
|
|
header.add(String.format("The Genome Analysis Toolkit (GATK) v%s, Compiled %s",getVersionNumber(), getBuildTime()));
|
2010-10-02 02:31:19 +08:00
|
|
|
header.add("Copyright (c) 2010 The Broad Institute");
|
2013-01-07 03:30:45 +08:00
|
|
|
header.add("For support and documentation go to " + HelpConstants.BASE_GATK_URL);
|
2009-07-22 06:23:28 +08:00
|
|
|
return header;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-29 06:53:32 +08:00
|
|
|
public static String getVersionNumber() {
|
|
|
|
|
ResourceBundle headerInfo = TextFormattingUtils.loadResourceBundle("StingText");
|
|
|
|
|
return headerInfo.containsKey("org.broadinstitute.sting.gatk.version") ? headerInfo.getString("org.broadinstitute.sting.gatk.version") : "<unknown>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String getBuildTime() {
|
|
|
|
|
ResourceBundle headerInfo = TextFormattingUtils.loadResourceBundle("StingText");
|
|
|
|
|
return headerInfo.containsKey("build.timestamp") ? headerInfo.getString("build.timestamp") : "<unknown>";
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-02 02:31:19 +08:00
|
|
|
/**
|
|
|
|
|
* If the user supplied any additional attribution, return it here.
|
|
|
|
|
* @return Additional attribution if supplied by the user. Empty (non-null) list otherwise.
|
|
|
|
|
*/
|
|
|
|
|
private List<String> getAttribution() {
|
|
|
|
|
List<String> attributionLines = new ArrayList<String>();
|
|
|
|
|
|
|
|
|
|
// If no analysis name is present, fill in extra help on the walkers.
|
|
|
|
|
WalkerManager walkerManager = engine.getWalkerManager();
|
|
|
|
|
String analysisName = getAnalysisName();
|
|
|
|
|
if(analysisName != null && walkerManager.exists(analysisName)) {
|
|
|
|
|
Class<? extends Walker> walkerType = walkerManager.getWalkerClassByName(analysisName);
|
|
|
|
|
if(walkerType.isAnnotationPresent(Attribution.class))
|
|
|
|
|
attributionLines.addAll(Arrays.asList(walkerType.getAnnotation(Attribution.class).value()));
|
|
|
|
|
}
|
|
|
|
|
return attributionLines;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-22 06:23:28 +08:00
|
|
|
/**
|
|
|
|
|
* Retrieves additional information about GATK walkers.
|
2009-10-29 03:56:05 +08:00
|
|
|
* the code in HelpFormatter and supply it as a helper to this method.
|
|
|
|
|
*
|
2009-07-22 06:23:28 +08:00
|
|
|
* @return A string summarizing the walkers available in this distribution.
|
|
|
|
|
*/
|
|
|
|
|
private String getAdditionalHelp() {
|
2010-08-10 00:42:48 +08:00
|
|
|
String additionalHelp;
|
2009-07-22 06:23:28 +08:00
|
|
|
|
2009-12-11 00:43:06 +08:00
|
|
|
// If no analysis name is present, fill in extra help on the walkers.
|
2010-09-22 23:27:58 +08:00
|
|
|
WalkerManager walkerManager = engine.getWalkerManager();
|
2009-12-11 00:43:06 +08:00
|
|
|
String analysisName = getAnalysisName();
|
2009-12-12 12:04:37 +08:00
|
|
|
if(analysisName != null && walkerManager.exists(getAnalysisName()))
|
|
|
|
|
additionalHelp = getWalkerHelp(walkerManager.getWalkerClassByName(getAnalysisName()));
|
|
|
|
|
else
|
|
|
|
|
additionalHelp = getAllWalkerHelp();
|
2009-07-22 06:23:28 +08:00
|
|
|
|
2009-12-11 00:43:06 +08:00
|
|
|
return additionalHelp;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-12 12:04:37 +08:00
|
|
|
private static final int PACKAGE_INDENT = 1;
|
|
|
|
|
private static final int WALKER_INDENT = 3;
|
|
|
|
|
private static final String FIELD_SEPARATOR = " ";
|
|
|
|
|
|
2010-08-10 00:42:48 +08:00
|
|
|
private String getWalkerHelp(Class<? extends Walker> walkerType) {
|
2009-12-12 12:04:37 +08:00
|
|
|
// Construct a help string to output details on this walker.
|
|
|
|
|
StringBuilder additionalHelp = new StringBuilder();
|
|
|
|
|
Formatter formatter = new Formatter(additionalHelp);
|
|
|
|
|
|
2011-08-18 22:31:32 +08:00
|
|
|
formatter.format("Available Reference Ordered Data types:%n");
|
|
|
|
|
formatter.format(new FeatureManager().userFriendlyListOfAvailableFeatures());
|
|
|
|
|
formatter.format("%n");
|
|
|
|
|
|
2011-08-08 03:02:46 +08:00
|
|
|
formatter.format("For a full description of this walker, see its GATKdocs at:%n");
|
2011-08-18 23:20:12 +08:00
|
|
|
formatter.format("%s%n", GATKDocUtils.helpLinksToGATKDocs(walkerType));
|
2009-12-12 12:04:37 +08:00
|
|
|
|
|
|
|
|
return additionalHelp.toString();
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-11 00:43:06 +08:00
|
|
|
/**
|
|
|
|
|
* Load in additional help information about all available walkers.
|
|
|
|
|
* @return A string representation of the additional help.
|
|
|
|
|
*/
|
2009-12-12 12:04:37 +08:00
|
|
|
private String getAllWalkerHelp() {
|
2009-12-05 07:24:29 +08:00
|
|
|
// Construct a help string to output available walkers.
|
2009-07-22 06:23:28 +08:00
|
|
|
StringBuilder additionalHelp = new StringBuilder();
|
2009-10-29 03:56:05 +08:00
|
|
|
Formatter formatter = new Formatter(additionalHelp);
|
2009-07-22 06:23:28 +08:00
|
|
|
|
2009-12-05 07:24:29 +08:00
|
|
|
// Get the list of walker names from the walker manager.
|
2010-09-22 23:27:58 +08:00
|
|
|
WalkerManager walkerManager = engine.getWalkerManager();
|
2009-12-05 07:24:29 +08:00
|
|
|
|
2009-12-08 05:33:11 +08:00
|
|
|
// Build a list sorted by walker display name. As this information is collected, keep track of the longest
|
|
|
|
|
// package / walker name for later formatting.
|
|
|
|
|
SortedSet<HelpEntry> helpText = new TreeSet<HelpEntry>(new HelpEntryComparator());
|
|
|
|
|
|
2009-12-05 07:24:29 +08:00
|
|
|
int longestPackageName = 0;
|
|
|
|
|
int longestWalkerName = 0;
|
2010-08-05 10:26:46 +08:00
|
|
|
for(Map.Entry<String,Collection<Class<? extends Walker>>> walkersByPackage: walkerManager.getWalkerNamesByPackage(true).entrySet()) {
|
2009-12-08 05:33:11 +08:00
|
|
|
// Get the display name.
|
|
|
|
|
String packageName = walkersByPackage.getKey();
|
|
|
|
|
String packageDisplayName = walkerManager.getPackageDisplayName(walkersByPackage.getKey());
|
2009-12-12 12:04:37 +08:00
|
|
|
String packageHelpText = walkerManager.getPackageSummaryText(packageName);
|
2009-12-08 05:33:11 +08:00
|
|
|
|
|
|
|
|
// Compute statistics about which names is longest.
|
|
|
|
|
longestPackageName = Math.max(longestPackageName,packageDisplayName.length());
|
|
|
|
|
|
|
|
|
|
SortedSet<HelpEntry> walkersInPackage = new TreeSet<HelpEntry>(new HelpEntryComparator());
|
|
|
|
|
for(Class<? extends Walker> walkerType: walkersByPackage.getValue()) {
|
|
|
|
|
String walkerName = walkerType.getName();
|
|
|
|
|
String walkerDisplayName = walkerManager.getName(walkerType);
|
2009-12-12 12:04:37 +08:00
|
|
|
String walkerHelpText = walkerManager.getWalkerSummaryText(walkerType);
|
2009-12-08 05:33:11 +08:00
|
|
|
|
2009-12-05 07:24:29 +08:00
|
|
|
longestWalkerName = Math.max(longestWalkerName,walkerManager.getName(walkerType).length());
|
2009-12-08 05:33:11 +08:00
|
|
|
|
|
|
|
|
walkersInPackage.add(new HelpEntry(walkerName,walkerDisplayName,walkerHelpText));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Dump the walkers into the sorted set.
|
2009-12-10 03:34:56 +08:00
|
|
|
helpText.add(new HelpEntry(packageName,packageDisplayName,packageHelpText,Collections.unmodifiableSortedSet(walkersInPackage)));
|
2009-07-22 06:23:28 +08:00
|
|
|
}
|
2009-10-29 03:56:05 +08:00
|
|
|
|
2009-12-05 07:24:29 +08:00
|
|
|
final int headerWidth = Math.max(longestPackageName+PACKAGE_INDENT,longestWalkerName+WALKER_INDENT);
|
|
|
|
|
|
|
|
|
|
|
2009-12-08 05:33:11 +08:00
|
|
|
for(HelpEntry packageHelp: helpText) {
|
2009-12-12 12:04:37 +08:00
|
|
|
printDescriptorLine(formatter,PACKAGE_INDENT,packageHelp.displayName,headerWidth,FIELD_SEPARATOR,packageHelp.summary,TextFormattingUtils.DEFAULT_LINE_WIDTH);
|
2009-12-05 07:24:29 +08:00
|
|
|
|
2009-12-08 05:33:11 +08:00
|
|
|
for(HelpEntry walkerHelp: packageHelp.children)
|
2009-12-12 12:04:37 +08:00
|
|
|
printDescriptorLine(formatter,WALKER_INDENT,walkerHelp.displayName,headerWidth,FIELD_SEPARATOR,walkerHelp.summary,TextFormattingUtils.DEFAULT_LINE_WIDTH);
|
2009-12-05 07:24:29 +08:00
|
|
|
|
|
|
|
|
// Print a blank line between sets of walkers.
|
|
|
|
|
printDescriptorLine(formatter,0,"",headerWidth,FIELD_SEPARATOR,"", TextFormattingUtils.DEFAULT_LINE_WIDTH);
|
2009-07-22 06:23:28 +08:00
|
|
|
}
|
|
|
|
|
|
2009-10-29 03:56:05 +08:00
|
|
|
return additionalHelp.toString();
|
2009-07-22 06:23:28 +08:00
|
|
|
}
|
2009-12-05 07:24:29 +08:00
|
|
|
|
|
|
|
|
private void printDescriptorLine(Formatter formatter,
|
|
|
|
|
int headerIndentWidth,
|
|
|
|
|
String header,
|
|
|
|
|
int headerWidth,
|
|
|
|
|
String fieldSeparator,
|
|
|
|
|
String description,
|
|
|
|
|
int lineWidth) {
|
|
|
|
|
final int headerPaddingWidth = headerWidth - header.length() - headerIndentWidth;
|
|
|
|
|
final int descriptionWidth = lineWidth - fieldSeparator.length() - headerWidth;
|
|
|
|
|
List<String> wordWrappedText = TextFormattingUtils.wordWrap(description,descriptionWidth);
|
|
|
|
|
|
|
|
|
|
String headerIndentFormatString = headerIndentWidth > 0 ? "%" + headerIndentWidth + "s" : "%s";
|
|
|
|
|
String headerPaddingFormatString = headerPaddingWidth > 0 ? "%" + headerPaddingWidth + "s" : "%s";
|
|
|
|
|
String headerWidthFormatString = headerWidth > 0 ? "%" + headerWidth + "s" : "%s";
|
|
|
|
|
|
|
|
|
|
// Output description line.
|
|
|
|
|
formatter.format(headerIndentFormatString + "%s" + headerPaddingFormatString + "%s%s%n",
|
|
|
|
|
"", header, "", fieldSeparator, wordWrappedText.size()>0?wordWrappedText.get(0):"");
|
|
|
|
|
for(int i = 1; i < wordWrappedText.size(); i++)
|
|
|
|
|
formatter.format(headerWidthFormatString + "%s%s%n", "", fieldSeparator, wordWrappedText.get(i));
|
|
|
|
|
}
|
2009-12-08 05:33:11 +08:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2009-12-12 12:04:37 +08:00
|
|
|
* Represents a given help entry; contains a display name, a summary and optionally some children.
|
2009-12-08 05:33:11 +08:00
|
|
|
*/
|
|
|
|
|
class HelpEntry {
|
|
|
|
|
public final String uid;
|
|
|
|
|
public final String displayName;
|
2009-12-12 12:04:37 +08:00
|
|
|
public final String summary;
|
2009-12-08 05:33:11 +08:00
|
|
|
public final SortedSet<HelpEntry> children;
|
|
|
|
|
|
|
|
|
|
/**
|
2009-12-12 12:04:37 +08:00
|
|
|
* Create a new help entry with the given display name, summary and children.
|
2009-12-08 05:33:11 +08:00
|
|
|
* @param uid a unique identifier. Usually, the java package.
|
|
|
|
|
* @param displayName display name for this help entry.
|
2009-12-12 12:04:37 +08:00
|
|
|
* @param summary summary for this help entry.
|
2009-12-08 05:33:11 +08:00
|
|
|
* @param children children for this help entry.
|
|
|
|
|
*/
|
2009-12-12 12:04:37 +08:00
|
|
|
public HelpEntry(String uid, String displayName, String summary, SortedSet<HelpEntry> children) {
|
2009-12-08 05:33:11 +08:00
|
|
|
this.uid = uid;
|
|
|
|
|
this.displayName = displayName;
|
2009-12-12 12:04:37 +08:00
|
|
|
this.summary = summary;
|
2009-12-08 05:33:11 +08:00
|
|
|
this.children = children;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2009-12-12 12:04:37 +08:00
|
|
|
* Create a new help entry with the given display name, summary and children.
|
2009-12-08 05:33:11 +08:00
|
|
|
* @param uid a unique identifier. Usually, the java package.
|
|
|
|
|
* @param displayName display name for this help entry.
|
2009-12-12 12:04:37 +08:00
|
|
|
* @param summary summary for this help entry.
|
2009-12-08 05:33:11 +08:00
|
|
|
*/
|
2009-12-12 12:04:37 +08:00
|
|
|
public HelpEntry(String uid, String displayName, String summary) {
|
|
|
|
|
this(uid,displayName,summary,null);
|
2009-12-08 05:33:11 +08:00
|
|
|
}
|
|
|
|
|
|
2009-05-11 10:07:20 +08:00
|
|
|
}
|
2009-12-08 05:33:11 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Compare two help entries by display name.
|
|
|
|
|
*/
|
|
|
|
|
class HelpEntryComparator implements Comparator<HelpEntry> {
|
|
|
|
|
private static TextFormattingUtils.CaseInsensitiveComparator textComparator = new TextFormattingUtils.CaseInsensitiveComparator();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Compares the order of lhs to rhs, not taking case into account.
|
|
|
|
|
* @param lhs First object to compare.
|
|
|
|
|
* @param rhs Second object to compare.
|
|
|
|
|
* @return 0 if objects are identical; -1 if lhs is before rhs, 1 if rhs is before lhs. Nulls are treated as after everything else.
|
|
|
|
|
*/
|
|
|
|
|
public int compare(HelpEntry lhs, HelpEntry rhs) {
|
|
|
|
|
if(lhs == null && rhs == null) return 0;
|
2009-12-10 03:34:56 +08:00
|
|
|
if(lhs == null || lhs.displayName.equals("")) return 1;
|
|
|
|
|
if(rhs == null || rhs.displayName.equals("")) return -1;
|
|
|
|
|
return lhs.displayName.equals(rhs.displayName) ? textComparator.compare(lhs.uid,rhs.uid) : textComparator.compare(lhs.displayName,rhs.displayName);
|
2009-12-08 05:33:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|