Re: [CLI] - new FormatHelper produces poorly formatted option groups
Gary Gregory <[email protected]> Wed, 5 Nov 2025 07:34:51 -0500
| Newsgroups | gmane.comp.jakarta.commons.user |
|---|---|
| Message-ID | <CACZkXPybZCXFP49ot-p0EH8o5rLmiuYN2rSvHwcUTbAs5pV2CA@mail.gmail.com> |
Hello Damien and all, This issue has been fixed with Claude's PR https://github.com/apache/commons-cli/pull/411 Thank you, Claude! Damien: Would you please test with a local git master build or a snapshot dependency from https://repository.apache.org/content/repositories/snapshots/ ? Thank you, Gary On Thu, Oct 30, 2025 at 3:22=E2=80=AFPM Damien Carbonne <[email protected]> wrote: > > I think that the issue is here, in > org.apache.commons.cli.help.AbstractHelpFormatter: > > public final void printHelp(final String cmdLineSyntax, final String > header, final Options options, final String footer, final boolean > autoUsage) throws IOException { > printHelp(cmdLineSyntax, header, options.getOptions(), footer, > autoUsage); // Here groups are lost > } > > Options contains groups, but Iterable<Option> (returned by > options.getOptions()) does not. > Therefore, the called printHelp is unable to format options correctly. > > One could construct Options from Iterable<Option> and revert the calls. > > > Le 30/10/2025 =C3=A0 16:05, Claude Warren a =C3=A9crit : > > I was on my phone when I first read this. But now I wonder how this is > > wrong. > > > > The example adds 2 options o1 and o2 and a group comprising the 2 and t= he > > expected output contains o1, o2, and o3. Where did o3 get its name? I > > assume o3 is intended to be the group of 01 and 02, but I don't think t= hose > > were ever delineated in the output. Am I missing something? > > > > > > > > On Thu, Oct 30, 2025 at 12:47=E2=80=AFPM Claude Warren <[email protected]= rg> wrote: > > > >> Looks likeregression. I will take a look later today. > >> > >> Claude > >> > >> LinkedIn: http://www.linkedin.com/in/claudewarren > >> > >> On Thu 30 Oct 2025, 12:12 Gary Gregory, <[email protected]> wrote= : > >> > >>> Claude, any thoughts here? I was just about to push a release candida= te... > >>> > >>> Gary > >>> > >>> On Sun, Oct 26, 2025 at 10:38=E2=80=AFAM Damien Carbonne > >>> <[email protected]> wrote: > >>>> Hi, > >>>> > >>>> When using the new HelpFormatter (commons-cli-1.10.0), option groups= are > >>>> poorly formatted. > >>>> > >>>> This looks like a regression. > >>>> The following code shows the difference between the new HelpFormatte= r > >>>> and the deprecated one: > >>>> ------------------------------------- > >>>> import java.io.IOException; > >>>> > >>>> import org.apache.commons.cli.Option; > >>>> import org.apache.commons.cli.OptionGroup; > >>>> import org.apache.commons.cli.Options; > >>>> > >>>> public class CliTest { > >>>> public static void main(String[] args) throws IOException { > >>>> // create options and groups > >>>> final Option o1 =3D new Option("o1", "Descr"); > >>>> final Option o2 =3D new Option("o2", "Descr"); > >>>> > >>>> final Options options =3D new Options(); > >>>> options.addOption(o1); > >>>> options.addOption(o2); > >>>> > >>>> final OptionGroup group =3D new OptionGroup(); > >>>> group.addOption(o1); > >>>> group.addOption(o2); > >>>> options.addOptionGroup(group); > >>>> > >>>> //format options with new formatter > >>>> final org.apache.commons.cli.help.HelpFormatter newFormatt= er =3D > >>>> > >>> org.apache.commons.cli.help.HelpFormatter.builder().setShowSince(fals= e).get(); > >>>> newFormatter.printHelp("Command", null, options, null, tru= e); > >>>> > >>>> // format options with old formatter > >>>> final org.apache.commons.cli.HelpFormatter oldFormatter = =3D > >>>> new org.apache.commons.cli.HelpFormatter(); > >>>> oldFormatter.printHelp("Command", null, options, null, tru= e); > >>>> } > >>>> } > >>>> ------------------------------------- > >>>> > >>>> The output is: > >>>> ------------------------------------- > >>>> usage: Command [-o1] [-o2] > >>>> Options Description > >>>> -o1 Descr > >>>> -o2 Descr > >>>> > >>>> > >>>> usage: Command [-o1 | -o2] > >>>> -o1 Descr > >>>> -o2 Descr > >>>> ------------------------------------- > >>>> > >>>> Groups are not shown any more. > >>>> I would expect the new formatter output to look like this: > >>>> ------------------------------------- > >>>> usage: Command [-o1 | -o2] > >>>> Options Description > >>>> -o1 Descr > >>>> -o2 Descr > >>>> -o3 Descr > >>>> ------------------------------------- > >>>> > >>>> Regards, > >>>> Damien Carbonne > >>>> > >>>> --------------------------------------------------------------------= - > >>>> To unsubscribe, e-mail: [email protected] > >>>> For additional commands, e-mail: [email protected] > >>>> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] >