1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.wrapper.cli;
20
21 import java.util.HashSet;
22 import java.util.List;
23 import java.util.Set;
24
25
26
27
28 public class CommandLineOption {
29 private final Set<String> options = new HashSet<>();
30
31 private Class<?> argumentType = Void.TYPE;
32
33 private String description;
34
35 private String subcommand;
36
37 private String deprecationWarning;
38
39 private boolean incubating;
40
41 public CommandLineOption(Iterable<String> options) {
42 for (String option : options) {
43 this.options.add(option);
44 }
45 }
46
47 public Set<String> getOptions() {
48 return options;
49 }
50
51 public CommandLineOption hasArgument() {
52 argumentType = String.class;
53 return this;
54 }
55
56 public CommandLineOption hasArguments() {
57 argumentType = List.class;
58 return this;
59 }
60
61 public String getSubcommand() {
62 return subcommand;
63 }
64
65 public CommandLineOption mapsToSubcommand(String command) {
66 this.subcommand = command;
67 return this;
68 }
69
70 public String getDescription() {
71 StringBuilder result = new StringBuilder();
72 if (description != null) {
73 result.append(description);
74 }
75 if (deprecationWarning != null) {
76 if (result.length() > 0) {
77 result.append(' ');
78 }
79 result.append("[deprecated - ");
80 result.append(deprecationWarning);
81 result.append("]");
82 }
83 if (incubating) {
84 if (result.length() > 0) {
85 result.append(' ');
86 }
87 result.append("[incubating]");
88 }
89 return result.toString();
90 }
91
92 public CommandLineOption hasDescription(String description) {
93 this.description = description;
94 return this;
95 }
96
97 public boolean getAllowsArguments() {
98 return argumentType != Void.TYPE;
99 }
100
101 public boolean getAllowsMultipleArguments() {
102 return argumentType == List.class;
103 }
104
105 public CommandLineOption deprecated(String deprecationWarning) {
106 this.deprecationWarning = deprecationWarning;
107 return this;
108 }
109
110 public CommandLineOption incubating() {
111 incubating = true;
112 return this;
113 }
114
115 public String getDeprecationWarning() {
116 return deprecationWarning;
117 }
118 }