Allow rules to declare they only accept a set of options (#1560)
This commit is contained in:
1 parent
b798d76d10
commit
635fb586c4
3 files changed
+20
-3
No files matched your search
@@ -85,6 +85,18 @@ public interface CarpetRule<T> {
|
||||
*/
|
||||
T defaultValue();
|
||||
|
||||
/**
|
||||
* <p>Returns whether this rule is strict.</p>
|
||||
*
|
||||
* <p>A rule being strict means that it will only accept the suggestions returned by {@link #suggestions()} as valid values.</p>
|
||||
*
|
||||
* <p>Note that a rule implementation may return {@code false} in this method but still not accept options other than those
|
||||
* returned in {@link #suggestions()}, only the opposite is guaranteed.</p>
|
||||
*/
|
||||
default boolean strict() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Sets this rule's value to the provided {@link String}, after first converting the {@link String} into a suitable type.</p>
|
||||
*
|
||||
|
||||
@@ -533,7 +533,7 @@ public class SettingsManager {
|
||||
ps.println("* Type: `" + rule.type().getSimpleName() + "` ");
|
||||
ps.println("* Default value: `" + RuleHelper.toRuleString(rule.defaultValue()) + "` ");
|
||||
String options = rule.suggestions().stream().map(s -> "`" + s + "`").collect(Collectors.joining(", "));
|
||||
if (!options.isEmpty()) ps.println((rule instanceof ParsedRule<?> pr && pr.isStrict?"* Required":"* Suggested")+" options: " + options + " ");
|
||||
if (!options.isEmpty()) ps.println((rule.strict() ? "* Required" : "* Suggested") + " options: " + options + " ");
|
||||
ps.println("* Categories: " + rule.categories().stream().map(s -> "`" + s.toUpperCase(Locale.ROOT) + "`").collect(Collectors.joining(", ")) + " ");
|
||||
if (rule instanceof ParsedRule<?>)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user