creadur-rat icon indicating copy to clipboard operation
creadur-rat copied to clipboard

RAT-442: Update to commons-cli 1.11.0 and use new functionality of this release

Open ottlinger opened this issue 3 months ago • 1 comments

https://github.com/apache/creadur-rat/pull/508 contais the plain dependabot update, but the new version brings:

  • deprecations of HelpFormatter
  • has to replace build() by get()

TODO

  • [ ] fix test failures
  • [ ] rework help display (add since as well)
  • [ ] getParsedOptionValues from Arg
  • [ ] do not use deprecated CLI methods anymore

ottlinger avatar Nov 08 '25 23:11 ottlinger

To fix this PR the following actions should be taken.

Change from org.apache.commons.cli.HelpFormatter to org.apache.commons.cli.help.HelpFormatter

And then understand that the new help formatter is intended to be built just before use.

The AbstractHelp class

  • get rid of AbstractHelp.RatHelpFormatter class.
  • should add a HelpFormatter.Builder protected final instance variable
  • the HelpFormatter.Builder should setShowSince to true
  • the HelpFormatter.Builder should setComparator to OptionCollection.OPTION_COMPARATOR
  • he HelpFormatter.Builder should setOptionFormatBuilder to a instance of OptionFormatBuilder that has setDeprecatedFormatFunction set to DEPRECATED_MSG.

In the rat.Help class printUsage method

  • A TextAppendable should be created that wraps the current writer.
  • The TextAppendable should have the max width set to the current HELP_WIDTH
  • set the HelpFormatter.Builder.setHelpAppendable to the TextAppendable;
  • call `HelpFormatter.Builder.get().printHelp(syntax, "", opts, "", true);

That will get us most of the way there for the basic help.

For the formatting of additional info use the TextHelpAppendable.printWrapped(), or create a table and use TextHelpAppendable.appendTable()

Claudenw avatar Nov 10 '25 13:11 Claudenw

@Claudenw I also stumbled upon the rat.Licenses class, that showed me how much time I didn't spend in the sources ;)

ottlinger avatar Nov 22 '25 20:11 ottlinger