View Javadoc

1   /*
2    * Copyright 2006 Tim Wood
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7    *
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS,
10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   * See the License for the specific language governing permissions and
12   * limitations under the License.
13   */
14  
15  package com.lexicalscope.jewel.cli;
16  
17  import java.lang.annotation.ElementType;
18  import java.lang.annotation.Retention;
19  import java.lang.annotation.RetentionPolicy;
20  import java.lang.annotation.Target;
21  
22  /**
23   * Tags a method as an option
24   *
25   * @author Tim Wood
26   */
27  @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Option
28  {
29      static final String stringToMarkNoDefault = "7acb394c-4c4f-4414-89df-28a62e785507?39858";
30  
31      /**
32       * The long name of this option
33       *
34       * @return The long name of this option
35       */
36      String[] longName() default {};
37  
38      /**
39       * The short name of this option
40       *
41       * @return The short name of this option
42       */
43      String[] shortName() default "";
44  
45      /**
46       * The regexp that the values of this option must match
47       *
48       * @return The regexp that the values of this option must match
49       */
50      String pattern() default ".*";
51  
52      /**
53       * A description of this option
54       *
55       * @return A description of this option
56       */
57      String description() default "";
58  
59      /**
60       * The default value if none is specified
61       *
62       * @return The value to present if none is specified
63       */
64      String[] defaultValue() default { stringToMarkNoDefault };
65  
66      /**
67       * The default value is null. Java does not allow null values in
68       * annotations. Setting this attribute to true will default the value of the
69       * option to null.
70       *
71       * @return true iff the default value of the option should be null
72       */
73      boolean defaultToNull() default false;
74  
75      /**
76       * Should help be displayed if this option is present.
77       *
78       * @return True if this option is a help option
79       */
80      boolean helpRequest() default false;
81  
82      /**
83       * Option is not displayed in help messages. Probably best not to use this with mandatory options.
84       *
85       * @return the option is not displayed in any help messages
86       */
87      boolean hidden() default false;
88  
89      /**
90       * Multivalued option must have at least this many values
91       *
92       * @return Multivalued option must have at least this many values
93       */
94      int minimum() default -1;
95  
96      /**
97       * Multivalued option must have exactly this many values
98       *
99       * @return Multivalued option must have exactly this many values
100      */
101     int exactly() default -1;
102 
103     /**
104      * Multivalued option can have at most this many values
105      *
106      * @return Multivalued option can have at most this many values
107      */
108     int maximum() default Integer.MAX_VALUE;
109 }