1 | |
package com.lexicalscope.jewel.cli; |
2 | |
|
3 | |
import static com.lexicalscope.jewel.cli.parser.DefaultArgumentParserFactory.createDefaultArgumentParser; |
4 | |
import static com.lexicalscope.jewel.cli.validation.DefaultValidatorFactory.createDefaultValidator; |
5 | |
|
6 | |
import com.lexicalscope.fluentreflection.FluentClass; |
7 | |
import com.lexicalscope.jewel.cli.specification.CliSpecification; |
8 | |
import com.lexicalscope.jewel.cli.specification.OptionsSpecification; |
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
abstract class AbstractCliImpl<O> implements Cli<O> { |
27 | |
private final FluentClass<O> klass; |
28 | |
private final OptionsSpecification<O> optionsSpecification; |
29 | |
|
30 | |
public AbstractCliImpl( |
31 | |
final FluentClass<O> klass, |
32 | 226 | final OptionsSpecification<O> optionsSpecification) { |
33 | 226 | this.klass = klass; |
34 | 226 | this.optionsSpecification = optionsSpecification; |
35 | 226 | } |
36 | |
|
37 | |
@Override public O parseArguments(final String... arguments) throws ArgumentValidationException { |
38 | 208 | final ArgumentCollectionBuilder parsedArguments = new ArgumentCollectionBuilder(); |
39 | |
|
40 | 208 | createDefaultArgumentParser().parseArguments(parsedArguments, arguments); |
41 | |
|
42 | 204 | return argumentPresenter(klass, optionsSpecification).presentArguments(parsedArguments.processArguments(createDefaultValidator(optionsSpecification))); |
43 | |
} |
44 | |
|
45 | |
protected abstract ArgumentPresenterImpl<O> argumentPresenter( |
46 | |
FluentClass<O> klass, |
47 | |
OptionsSpecification<O> specification); |
48 | |
|
49 | |
@Override public String getHelpMessage() { |
50 | 18 | return optionsSpecification.toString(); |
51 | |
} |
52 | |
|
53 | |
CliSpecification getSpecification() { |
54 | 2 | return optionsSpecification; |
55 | |
} |
56 | |
|
57 | |
@Override public void describeTo(final HelpMessage helpMessage) { |
58 | 0 | optionsSpecification.describeTo(helpMessage); |
59 | 0 | } |
60 | |
} |