SYNC.addDefaultFeatureValue("thread", PrimitiveFeature.THREAD_ANALYSIS);
SYNC.addDefaultFeatureValue("sync", PrimitiveFeature.SYNC_ANALYSIS);
+
+ // Add description of default options
+ for (TracingFeatureArgument featureArg : values())
+ if (featureArg.getOption().hasArgs())
+ featureArg.addDefaulFeaturestDescription();
}
private final Option option;
* @param longName long name of CLI option
*/
private TracingFeatureArgument(String name, String longName) {
+ String desc = "select " + longName.replace("-", " ") + " tracing\n"
+ + "Possible arguments: ";
this.option = Option.builder(name).longOpt(longName).hasArgs()
.valueSeparator(',').optionalArg(true)
- .desc("select " + longName.replace("-", " ") + " tracing")
- .build();
+ .desc(desc).build();
+ }
+
+ /**
+ * Update option description with information of features selected by default
+ */
+ private void addDefaulFeaturestDescription() {
+ String desc = option.getDescription();
+ String defDesc = "If no arguments provided - '";
+ // Check if default are all
+ if (defFeatures.size() == availFeatures.size())
+ defDesc += ALL_NAME;
+ else {
+ StringBuffer defArgsString = new StringBuffer();
+ for (Map.Entry<String, PrimitiveFeature> feature : availFeatures
+ .entrySet()) {
+ if (defFeatures.contains(feature.getValue()))
+ defArgsString.append(feature.getKey() + ",");
+ }
+ defDesc += defArgsString.toString();
+ // remove last ',' symbol
+ defDesc = defDesc.substring(0, defDesc.length()-1);
+ }
+ option.setDescription(desc + "\n" + defDesc + "' is selected");
}
/**
private TracingFeatureArgument(String name, PrimitiveFeature feature) {
this.option = Option.builder(name)
.longOpt(feature.getName().toLowerCase().replace(' ', '-'))
- .desc("select " + feature.getName().toLowerCase() + " tracing")
+ .desc("Select " + feature.getName().toLowerCase() + " tracing")
.build();
defFeatures.add(feature);
}
*/
private void addFeatureValue(String name, PrimitiveFeature feature) {
availFeatures.put(name, feature);
+ updateArgsDescription(name);
+ }
+
+ /**
+ * Update option's description according to added feature value
+ * @param name name of added feature value
+ */
+ private void updateArgsDescription(String name) {
+ String desc = option.getDescription();
+ desc = desc.replace(ALL_NAME, "");
+ option.setDescription(desc + name + ", " + ALL_NAME);
}
/**
import org.apache.commons.cli.Options;
public class Help {
+
+ /**
+ * Width of help message
+ */
+ private static int width = 100;
+
/**
* Prints command's help message to given <code>PrintStream</code>.
* @param commandDesc <code>String</code> with command description
public static void printHelp(String commandDesc, Options opts, PrintStream ps) throws IOException {
PrintWriter pw = new PrintWriter(ps, true);
HelpFormatter formatter = new HelpFormatter();
+ // Print in the order options were defined
+ formatter.setOptionComparator(null);
- formatter.printWrapped(pw, 80, 30, commandDesc);
- formatter.printOptions(pw, 80, opts, 4, 4);
+ formatter.printWrapped(pw, width, 30, commandDesc);
+ formatter.printOptions(pw, width, opts, 4, 4);
pw.println();
}
}