1 | |
package com.lexicalscope.jewel.cli; |
2 | |
|
3 | |
import static java.util.Arrays.asList; |
4 | |
|
5 | |
import java.util.ArrayList; |
6 | |
import java.util.List; |
7 | |
|
8 | |
import com.lexicalscope.fluentreflection.FluentClass; |
9 | |
import com.lexicalscope.fluentreflection.FluentMethod; |
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
class OptionAnnotationAdapter extends AbstractOptionAdapter { |
28 | |
private final Option option; |
29 | |
|
30 | |
OptionAnnotationAdapter( |
31 | |
final FluentClass<?> klass, |
32 | |
final FluentMethod method) { |
33 | 514 | super(klass, method); |
34 | 514 | this.option = method.annotation(Option.class); |
35 | 514 | } |
36 | |
|
37 | |
@Override public String description() { |
38 | 246 | return option.description().trim(); |
39 | |
} |
40 | |
|
41 | |
@Override public String pattern() { |
42 | 324 | return option.pattern(); |
43 | |
} |
44 | |
|
45 | |
@Override public boolean defaultToNull() { |
46 | 2082 | return option.defaultToNull(); |
47 | |
} |
48 | |
|
49 | |
@Override public String[] defaultValue() { |
50 | 1034 | return option.defaultValue(); |
51 | |
} |
52 | |
|
53 | |
public List<String> shortName() { |
54 | 620 | final List<String> shortNames = new ArrayList<String>(); |
55 | 1262 | for (final String element : option.shortName()) { |
56 | 642 | final String shortName = element.trim(); |
57 | 642 | if (shortName.length() > 0) { |
58 | 132 | shortNames.add(element.substring(0, 1)); |
59 | |
} |
60 | |
} |
61 | 620 | return shortNames; |
62 | |
} |
63 | |
|
64 | |
public List<String> longName() { |
65 | 1138 | return option.longName().length == 0 |
66 | |
? asList(method.property()) |
67 | |
: asList(option.longName()); |
68 | |
} |
69 | |
|
70 | |
public boolean helpRequest() { |
71 | 232 | return option.helpRequest(); |
72 | |
} |
73 | |
|
74 | |
@Override public boolean isHidden() { |
75 | 92 | return option.hidden(); |
76 | |
} |
77 | |
|
78 | |
@Override public int minimum() { |
79 | 582 | return option.minimum(); |
80 | |
} |
81 | |
|
82 | |
@Override public int exactly() { |
83 | 1136 | return option.exactly(); |
84 | |
} |
85 | |
|
86 | |
@Override public int maximum() { |
87 | 1600 | return option.maximum(); |
88 | |
} |
89 | |
} |