picocli icon indicating copy to clipboard operation
picocli copied to clipboard

Clearer error messages for ArgGroups

Open scottjasso opened this issue 5 years ago • 1 comments

See #870.

  • If num groups > max(multiplicity) (whether the args are optional or required), it's currently:

    Error: expected only one match but got (--group=<name> [--opt1=<opt>])={--group=foo --opt1=1} and (--group=<name> [--opt1=<opt>])={--opt1=1}

    I like that this shows you the matched groups, but (1) it always says "expected only one match", even if the minimum multiplicity > 1, and (2) it seems unnecessary to repeat the group spec.

    If num groups < min(multiplicity), it's currently:

    Error: Group: (--group=<name> [--opt1=<opt>]) must be specified 2 times but was matched 1 times

    For consistency, I think both cases should be something like:

    Error: (--group=<name> [--opt1=<opt>]) must be specified [X / at least X / at most X] time(s) but was matched 2 times: {--group=foo --opt1=1}, {--opt1=2}

    This makes it clear how the groups are, well, grouped :)

  • If missing a required option for a group, it's currently:

    Error: Missing required argument(s): --group=<name>

    IMO something like

    Error: --group=<name> is required in (--group=<name> [--opt1=<opt>]), got: {--opt1=1}

    This clarifies that --group=<name> is only needed when specifying --opt1. This also applies for mutually dependent args:

    Error: --req-arg1=<foo>, --req-arg2=<bar> are all required in (--req-arg1=<foo>, --req-arg2=<bar> [--opt1=<opt>]), got: {--req-arg1=foo}

Also highly relevant to #871 -- there are some questions raised there that may shape how the errors are printed / validation is done.

scottjasso avatar Nov 20 '19 06:11 scottjasso

Please note the previous discussion on this topic (#744) which led to a code change to address the issue. I agree that there is still room for improvement, though.

deining avatar Nov 20 '19 07:11 deining