View Javadoc
1   package org.apache.maven.wrapper.cli;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.HashSet;
23  import java.util.List;
24  import java.util.Set;
25  
26  /**
27   * Command line option. 
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 }