char next = '?';
List<NamedOptionDef> booleans = new ArrayList<NamedOptionDef>();
for (@SuppressWarnings("rawtypes") OptionHandler handler : parser.options) {
if (handler.option instanceof NamedOptionDef) {
NamedOptionDef n = (NamedOptionDef) handler.option;
if (handler instanceof BooleanOptionHandler) {
booleans.add(n);
continue;
}
if (!n.required()) {
out.write('[');
}
out.write(next);
next = '&';
if (n.name().startsWith("--")) {
out.write(n.name().substring(2));
} else if (n.name().startsWith("-")) {
out.write(n.name().substring(1));
} else {
out.write(n.name());
}
out.write('=');
String var = handler.getDefaultMetaVariable();
if (handler instanceof EnumOptionHandler) {
var = var.substring(1, var.length() - 1);
var = var.replaceAll(" ", "");
}
out.write(var);
if (!n.required()) {
out.write(']');
}
if (n.isMultiValued()) {
out.write('*');
}
}
}
for (NamedOptionDef n : booleans) {
if (!n.required()) {
out.write('[');
}
out.write(next);
next = '&';
if (n.name().startsWith("--")) {
out.write(n.name().substring(2));
} else if (n.name().startsWith("-")) {
out.write(n.name().substring(1));
} else {
out.write(n.name());
}
if (!n.required()) {
out.write(']');
}
}
}