1 /** 2 * Copyright (C) 2010 the original author or authors. 3 * See the notice.md file distributed with this work for additional 4 * information regarding copyright ownership. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package com.beust.jcommander; 20 21 import static java.lang.annotation.ElementType.FIELD; 22 import static java.lang.annotation.ElementType.METHOD; 23 24 import com.beust.jcommander.converters.CommaParameterSplitter; 25 import com.beust.jcommander.converters.IParameterSplitter; 26 import com.beust.jcommander.converters.NoConverter; 27 import com.beust.jcommander.validators.NoValidator; 28 import com.beust.jcommander.validators.NoValueValidator; 29 30 import java.lang.annotation.Retention; 31 import java.lang.annotation.Target; 32 33 @Retention(java.lang.annotation.RetentionPolicy.RUNTIME) 34 @Target({ FIELD, METHOD }) 35 public @interface Parameter { 36 37 /** 38 * An array of allowed command line parameters (e.g. "-d", "--outputdir", etc...). 39 * If this attribute is omitted, the field it's annotating will receive all the 40 * unparsed options. There can only be at most one such annotation. 41 */ names()42 String[] names() default {}; 43 44 /** 45 * A description of this option. 46 */ description()47 String description() default ""; 48 49 /** 50 * Whether this option is required. 51 */ required()52 boolean required() default false; 53 54 /** 55 * The key used to find the string in the message bundle. 56 */ descriptionKey()57 String descriptionKey() default ""; 58 59 /** 60 * How many parameter values this parameter will consume. For example, 61 * an arity of 2 will allow "-pair value1 value2". 62 */ arity()63 int arity() default -1; 64 65 /** 66 * If true, this parameter is a password and it will be prompted on the console 67 * (if available). 68 */ password()69 boolean password() default false; 70 71 /** 72 * The string converter to use for this field. If the field is of type <tt>List</tt> 73 * and not <tt>listConverter</tt> attribute was specified, JCommander will split 74 * the input in individual values and convert each of them separately. 75 */ converter()76 Class<? extends IStringConverter<?>> converter() default NoConverter.class; 77 78 /** 79 * The list string converter to use for this field. If it's specified, the 80 * field has to be of type <tt>List</tt> and the converter needs to return 81 * a List that's compatible with that type. 82 */ listConverter()83 Class<? extends IStringConverter<?>> listConverter() default NoConverter.class; 84 85 /** 86 * If true, this parameter won't appear in the usage(). 87 */ hidden()88 boolean hidden() default false; 89 90 /** 91 * Validate the parameter found on the command line. 92 */ validateWith()93 Class<? extends IParameterValidator> validateWith() default NoValidator.class; 94 95 /** 96 * Validate the value for this parameter. 97 */ validateValueWith()98 Class<? extends IValueValidator> validateValueWith() default NoValueValidator.class; 99 100 /** 101 * @return true if this parameter has a variable arity. See @{IVariableArity} 102 */ variableArity()103 boolean variableArity() default false; 104 105 /** 106 * What splitter to use (applicable only on fields of type <tt>List</tt>). By default, 107 * a comma separated splitter will be used. 108 */ splitter()109 Class<? extends IParameterSplitter> splitter() default CommaParameterSplitter.class; 110 111 /** 112 * If true, console will not echo typed input 113 * Used in conjunction with password = true 114 */ echoInput()115 boolean echoInput() default false; 116 117 /** 118 * If true, this parameter is for help. If such a parameter is specified, 119 * required parameters are no longer checked for their presence. 120 */ help()121 boolean help() default false; 122 123 /** 124 * If true, this parameter can be overwritten through a file or another appearance of the parameter 125 * @return 126 */ forceNonOverwritable()127 boolean forceNonOverwritable() default false; 128 129 130 } 131