You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I saw that the default behavior of the setUsageHelpLongOptionsMaxWidth method is to trigger an exception if the width of the terminal is small. However, I think that makes sense to set the width of options when possible (mid/big screen) but just skip it when it is not possible, instead of failure with this exception:
Exception in thread "main" picocli.CommandLine$InitializationException: Invalid usage long options max width 50. Value must not exceed width(55) - 20
at picocli.CommandLine$Model$UsageMessageSpec.longOptionsMaxWidth(CommandLine.java:7687)
at picocli.CommandLine.setUsageHelpLongOptionsMaxWidth(CommandLine.java:3376)
at com.MyApp.main(MyApp.java:110)
For example, letting the behavior with an exception makes me do a workaround that works because I am using setUsageHelpAutoWidth(true). I think that other people will potentially do a similar thing to avoid the failure (or try-catch it).
CommandLine cmd = new CommandLine(new MyApp())
.setUnmatchedArgumentsAllowed(false)
.setSubcommandsCaseInsensitive(true)
.setOptionsCaseInsensitive(true)
.setUsageHelpAutoWidth(true);
int width = cmd.getUsageHelpWidth();
int defaultLongOptionsWidth = 50;
// This is a workaround to avoid setUsageHelpLongOptionsMaxWidth, which needs the defaultLongOptionsWidth
// to be bigger than terminal screen plus 20, otherwise it will failure with picocli.CommandLine$InitializationException
if(width - defaultLongOptionsWidth > 20) {
cmd.setUsageHelpLongOptionsMaxWidth(defaultLongOptionsWidth);
}
Is that possible to change the behavior to avoid the exception by just ignoring the value passed to setUsageHelpLongOptionsMaxWidth when the terminal width is too small?
The text was updated successfully, but these errors were encountered:
I miss-clicked and accidentally merged before reviewing. 😅
I won’t be able to review it for a few more days; I hope you’re okay with the delayed feedback. (But I’m sure it’ll be solid stuff anyway.) 😄
Thanks again 🙏
Hi, I saw that the default behavior of the
setUsageHelpLongOptionsMaxWidth
method is to trigger an exception if the width of the terminal is small. However, I think that makes sense to set the width of options when possible (mid/big screen) but just skip it when it is not possible, instead of failure with this exception:For example, letting the behavior with an exception makes me do a workaround that works because I am using
setUsageHelpAutoWidth(true)
. I think that other people will potentially do a similar thing to avoid the failure (or try-catch it).Is that possible to change the behavior to avoid the exception by just ignoring the value passed to
setUsageHelpLongOptionsMaxWidth
when the terminal width is too small?The text was updated successfully, but these errors were encountered: