fortify / fcli

fcli is a command-line utility for interacting with various Fortify products
https://fortify.github.io/fcli/
Other
31 stars 17 forks source link

Check whether picocli can be customized to automatically convert `_` to `-` in enum values #306

Closed rsenden closed 1 month ago

rsenden commented 1 year ago

For consistency, enum values passed on the command line should use - as word separator, however enum values cannot contain a - character. We have various Converter and Iterable implementations to convert - to _ and vice versa, for example:

We should check whether there's any way to have picocli automatically handle the _ to/from - conversion when processing option values and generating completion candidates.

rsenden commented 1 year ago

See https://github.com/remkop/picocli/issues/2025

rsenden commented 1 month ago

We've now identified a much easier way to handle this; enum's can simply provide a toString() method like the following:

        @Override
        public String toString() {
            // Show and accept dashes instead of underscores when this
            // enum is used in picocli options.
            return name().replace('_', '-');
        }

Picocli will display the toString() value as completion candidates, and also properly resolve enum values when specified with dashes on the command line.