1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
package com.lexicalscope.jewel.cli.validation; |
6 | |
|
7 | |
import com.lexicalscope.jewel.cli.ValidationErrorBuilder; |
8 | |
import com.lexicalscope.jewel.cli.specification.OptionsSpecification; |
9 | |
|
10 | |
import org.hamcrest.Description; |
11 | |
import org.hamcrest.TypeSafeMatcher; |
12 | |
|
13 | 240 | public class KnownOptions extends TypeSafeMatcher<RawOption> |
14 | |
{ |
15 | |
private final OptionsSpecification<?> specification; |
16 | |
private final ValidationErrorBuilder validationErrorBuilder; |
17 | |
|
18 | |
public KnownOptions(final OptionsSpecification<?> specification, final ValidationErrorBuilder validationErrorBuilder) |
19 | 226 | { |
20 | 226 | this.specification = specification; |
21 | 226 | this.validationErrorBuilder = validationErrorBuilder; |
22 | 226 | } |
23 | |
|
24 | |
@Override |
25 | |
public void describeTo(final Description description) |
26 | |
{ |
27 | 0 | description.appendText("option that is part of specification ").appendValue(specification); |
28 | 0 | } |
29 | |
|
30 | |
@Override |
31 | |
protected boolean matchesSafely(final RawOption item) |
32 | |
{ |
33 | 240 | if(!specification.isSpecified(item.stringValue())) { |
34 | 8 | validationErrorBuilder.unexpectedOption(item.stringValue()); |
35 | 8 | return false; |
36 | |
} |
37 | 232 | return true; |
38 | |
} |
39 | |
} |