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