/** * Gets a detailed description for a given argument group. * * @param argumentDefinitionGroup The group of argument definitions to render. * @return A string giving detailed info about the contents of this group. */ private String getDetailForGroup(ArgumentDefinitionGroup argumentDefinitionGroup) { if (argumentDefinitionGroup.allHidden()) return ""; StringBuilder builder = new StringBuilder(); Formatter formatter = new Formatter(builder); if (argumentDefinitionGroup.groupName != null && argumentDefinitionGroup.argumentDefinitions.size() != 0) builder.append(String.format("%nArguments for %s:%n", argumentDefinitionGroup.groupName)); List<ArgumentDefinition> argumentDefinitions = new ArrayList<ArgumentDefinition>(); for (ArgumentDefinition argumentDefinition : argumentDefinitionGroup.argumentDefinitions) { if (!argumentDefinition.isHidden) argumentDefinitions.add(argumentDefinition); } // Try to fit the entire argument definition across the screen, but impose an arbitrary cap of // 3/4 * // LINE_WIDTH in case the length of the arguments gets out of control. int argWidth = Math.min( findLongestArgumentCallingInfo(argumentDefinitions), (TextFormattingUtils.DEFAULT_LINE_WIDTH * 3) / 4 - FIELD_SEPARATION_WIDTH); int docWidth = TextFormattingUtils.DEFAULT_LINE_WIDTH - argWidth - FIELD_SEPARATION_WIDTH; for (ArgumentDefinition argumentDefinition : argumentDefinitions) { Iterator<String> wordWrappedArgs = TextFormattingUtils.wordWrap(getArgumentCallingInfo(argumentDefinition), argWidth) .iterator(); Iterator<String> wordWrappedDoc = TextFormattingUtils.wordWrap(getArgumentDoc(argumentDefinition), docWidth).iterator(); while (wordWrappedArgs.hasNext() || wordWrappedDoc.hasNext()) { String arg = wordWrappedArgs.hasNext() ? wordWrappedArgs.next() : ""; String doc = wordWrappedDoc.hasNext() ? wordWrappedDoc.next() : ""; String formatString = "%-" + argWidth + "s%" + FIELD_SEPARATION_WIDTH + "s%s%n"; formatter.format(formatString, arg, "", doc); } } return builder.toString(); }
/** * Creates a program record (@PG) tag * * @param toolkit the engine * @param walker the walker object (so we can extract the command line) * @param PROGRAM_RECORD_NAME the name for the PG tag * @return a program record for the tool */ public static SAMProgramRecord createProgramRecord( GenomeAnalysisEngine toolkit, Object walker, String PROGRAM_RECORD_NAME) { final SAMProgramRecord programRecord = new SAMProgramRecord(PROGRAM_RECORD_NAME); final ResourceBundle headerInfo = TextFormattingUtils.loadResourceBundle("StingText"); try { final String version = headerInfo.getString("org.broadinstitute.sting.gatk.version"); programRecord.setProgramVersion(version); } catch (MissingResourceException e) { // couldn't care less if the resource is missing... } programRecord.setCommandLine( toolkit.createApproximateCommandLineArgumentString(toolkit, walker)); return programRecord; }
/** * Gets the synopsis: the actual command to run. * * @param runningInstructions Instructions on how to run hte application. * @param argumentGroups Program arguments sorted in order of definition group displays. * @return A synopsis line. */ private String getSynopsis( String runningInstructions, List<ArgumentDefinitionGroup> argumentGroups) { // Build out the synopsis all as one long line. StringBuilder lineBuilder = new StringBuilder(); Formatter lineFormatter = new Formatter(lineBuilder); lineFormatter.format("java %s", runningInstructions); for (ArgumentDefinitionGroup argumentGroup : argumentGroups) { for (ArgumentDefinition argumentDefinition : argumentGroup.argumentDefinitions) { if (argumentDefinition.isHidden) continue; lineFormatter.format(" "); if (!argumentDefinition.required) lineFormatter.format("["); if (argumentDefinition.shortName != null) lineFormatter.format("-%s", argumentDefinition.shortName); else lineFormatter.format("--%s", argumentDefinition.fullName); if (!argumentDefinition.isFlag) lineFormatter.format(" <%s>", argumentDefinition.fullName); if (!argumentDefinition.required) lineFormatter.format("]"); } } // Word wrap the synopsis. List<String> wrappedSynopsis = TextFormattingUtils.wordWrap( lineBuilder.toString(), TextFormattingUtils.DEFAULT_LINE_WIDTH); String header = "usage: "; int headerLength = header.length(); StringBuilder synopsisBuilder = new StringBuilder(); Formatter synopsisFormatter = new Formatter(synopsisBuilder); for (String synopsisLine : wrappedSynopsis) { synopsisFormatter.format("%" + headerLength + "s%s%n", header, synopsisLine); header = ""; } return synopsisBuilder.toString(); }