-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBooleanCLIOption.java
More file actions
27 lines (22 loc) · 843 Bytes
/
BooleanCLIOption.java
File metadata and controls
27 lines (22 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package net.marcellperger.mathexpr.cli.minicli;
import org.jetbrains.annotations.NotNull;
import java.util.List;
class BooleanCLIOption extends CLIOption<Boolean> {
public BooleanCLIOption(List<String> optionNames) {
super(Boolean.class, optionNames);
setDefault(false);
setDefaultIfNoValue(true);
}
@Override
protected void _setValueFromString(@NotNull String s) {
setValue(switch (s.strip().toLowerCase()) {
case "0", "no", "false" -> false;
case "1", "yes", "true" -> true;
case String s2 -> throw fmtNewParseExcWithName("Bad boolean value '%s' for %%s".formatted(s2));
});
}
@Override
public boolean supportsSeparateValueAfterShortForm() {
return false; // cannot have `foo -r no` (use `-r=no` / `--long-form=no`
}
}