On 13/01/2022 00:13, Remko Popma wrote:
With Commons Cli you will have to write a custom HelpFormatter to provide
end users with more detail about the positional parameters.
Strange. It's almost as if the software was left unfinished, and yet it
is still maintained. The actual program parameters are treated almost as
if they are of slight importance ;)
You may be interested inhttps://picocli.info/ which provides this
functionality
At first sight, that looks highly professional and well documented.
Congratulations. I shall certainly be looking at it for the next time.
I've gone too far with the current program now, but fwiw, the nasty
kludge I used (which involved replacing a private method) is as follows:
new HelpFormatter() {
private Appendable renderWrappedTextBlock(final StringBuffer sb,
final int width, final int nextLineTabStop,
final String text) {
try {
final BufferedReader in = new BufferedReader(new
StringReader(text));
String line;
boolean firstLine = true;
while ((line = in.readLine()) != null) {
if (!firstLine) {
sb.append(getNewLine());
} else {
firstLine = false;
}
renderWrappedText(sb, width, nextLineTabStop, line);
}
} catch (final IOException e) { // NOPMD
// cannot happen
}
return sb;
}
@Override
public void printWrapped(final java.io.PrintWriter pw, final int
width, final int nextLineTabStop,
final String text) {
final StringBuffer sb = new StringBuffer(text.length());
renderWrappedTextBlock(sb, width, nextLineTabStop, text);
sb.append(" ").append("<start path (file or directory)>");
pw.println(sb.toString());
}
}.printHelp("FileRenamer", "", options, null, true);