bkirwi / decline

A composable command-line parser for Scala.
http://monovore.com/decline/
Apache License 2.0
647 stars 71 forks source link

Handle the empty-optional case correctly #476

Closed bkirwi closed 1 year ago

bkirwi commented 1 year ago

The Usage rendering code tries to find groups of options that can be rendered using the [--foo | --bar] syntax -- effectively, a Sum that contains at least one empty Prod. However, if it contains only empty Prods, it will render as [], which is nonstandard and not useful.

Previously, this would never arise in practise -- you'd need to write some weird opts instances like Opts("foo").withDefault("bar") to trigger it. However, as pointed out in #475, now that we have Opts.env this can arise with the much more reasonable Opts.env(...).withDefault(...).

The proposed fix is to just filter out cases where the list of alternatives in the braces is empty. I'll want to do a little more testing before I'm confident in it, though.

bkirwi commented 1 year ago

I was right to be suspicious - my first take was filtering out too much. Happier with the code and tests now.

Fixes #475 .