Throw exception if illegal --mode pattern was passed in

This commit is contained in:
Reinhard Pointner 2018-03-15 09:50:54 +07:00
parent 73ad2c7267
commit 640db994b3
1 changed files with 8 additions and 1 deletions

View File

@ -328,7 +328,14 @@ public class ArgumentBean {
// only selected panels
return optional(mode).map(m -> {
Pattern pattern = Pattern.compile(mode, Pattern.CASE_INSENSITIVE);
return stream(PanelBuilder.defaultSequence()).filter(p -> pattern.matcher(p.getName()).matches()).toArray(PanelBuilder[]::new);
PanelBuilder[] panel = stream(PanelBuilder.defaultSequence()).filter(p -> pattern.matcher(p.getName()).matches()).toArray(PanelBuilder[]::new);
// throw exception if illegal pattern was passed in
if (panel.length == 0) {
return null;
}
return panel;
}).orElseThrow(error("Illegal mode", mode));
}