You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Charles Johnson <ce...@gmail.com> on 2022/01/12 23:50:11 UTC

[cli]

Given the standard format of

progam [options] <argument>

I am confused how Commons Cli treats the last above. Obviously 
CommandLine.getArgList will get that argument. But that doesn't help me 
when it comes to HelpFomatter. That seems only to know about Options. Am 
I to understand that the Option class has to be used for arguments too, 
if I want to tell the user about <argument>?

TIA


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [cli]

Posted by Charles Johnson <ce...@gmail.com>.
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);

Re: [cli]

Posted by Remko Popma <re...@gmail.com>.
You are correct.
With Commons Cli you will have to write a custom HelpFormatter to provide
end users with more detail about the positional parameters.

You may be interested in https://picocli.info/ which provides this
functionality out of the box, along with colored help, autocomplete and
support for easily turning your CLIs into native binaries.
(Disclaimer: I wrote it.) Enjoy!


On Thu, Jan 13, 2022 at 8:50 AM Charles Johnson <ce...@gmail.com>
wrote:

> Given the standard format of
>
> progam [options] <argument>
>
> I am confused how Commons Cli treats the last above. Obviously
> CommandLine.getArgList will get that argument. But that doesn't help me
> when it comes to HelpFomatter. That seems only to know about Options. Am
> I to understand that the Option class has to be used for arguments too,
> if I want to tell the user about <argument>?
>
> TIA
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>