![JAR search and dependency download from the Maven repository](/logo.png)
org.jruby.util.cli.Option Maven / Gradle / Ivy
The newest version!
/*
**** BEGIN LICENSE BLOCK *****
* Version: EPL 1.0/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Eclipse Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.eclipse.org/legal/epl-v10.html
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Copyright (C) 2001-2011 The JRuby Community (and contribs)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the EPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the EPL, the GPL or the LGPL.
***** END LICENSE BLOCK *****/
package org.jruby.util.cli;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* Represents a single option, with a category, name, value type,
* options, default value, and description.
*
* This type should be subclassed for specific types of values.
*
* @param the type of value associated with the option
*/
public abstract class Option {
/**
* Create a new option with the given values.
*
* @param an enumeration type
* @param prefix the prefix used for loading this option from properties
* @param name the rest of the property name
* @param type the value type of the option
* @param category the category to which this option belongs
* @param options a list of supported for the option, or null if the set is
* not applicable
* @param defval the default value for the option
* @param description a description for the option
*/
public Option(String prefix, String name, Class type, Enum category, T[] options, T defval, String description) {
this.category = category;
this.prefix = prefix;
this.name = name;
this.longName = prefix + "." + name;
this.displayName = name;
this.type = type;
this.options = options == null ? new String[]{type.getSimpleName()} : options;
this.defval = defval;
this.description = description;
this.specified = false;
}
/**
* Create a new option with the given values.
*
* @param an enumeration type
* @param longName the property name
* @param type the value type of the option
* @param category the category to which this option belongs
* @param options a list of supported for the option, or null if the set is
* not applicable
* @param defval the default value for the option
* @param description a description for the option
*/
public Option(String longName, Class type, Enum category, T[] options, T defval, String description) {
this.category = category;
this.prefix = null;
this.name = null;
this.longName = longName;
this.displayName = longName;
this.type = type;
this.options = options == null ? new String[]{type.getSimpleName()} : options;
this.defval = defval;
this.description = description;
this.specified = false;
}
public static Option string(String prefix, String name, Enum category, String description) {
return new StringOption(prefix, name, category, null, null, description);
}
public static Option string(String longName, Enum category, String description) {
return new StringOption(longName, category, null, null, description);
}
public static Option string(String prefix, String name, Enum category, String defval, String description) {
return new StringOption(prefix, name, category, null, defval, description);
}
public static Option string(String longName, Enum category, String defval, String description) {
return new StringOption(longName, category, null, defval, description);
}
public static Option string(String prefix, String name, Enum category, String[] options, String description) {
return new StringOption(prefix, name, category, options, null, description);
}
public static Option string(String longName, Enum category, String[] options, String description) {
return new StringOption(longName, category, options, null, description);
}
public static Option string(String prefix, String name, Enum category, String[] options, String defval, String description) {
return new StringOption(prefix, name, category, options, defval, description);
}
public static Option string(String longName, Enum category, String[] options, String defval, String description) {
return new StringOption(longName, category, options, defval, description);
}
public static Option bool(String prefix, String name, Enum category, String description) {
return new BooleanOption(prefix, name, category, null, description);
}
public static Option bool(String longName, Enum category, String description) {
return new BooleanOption(longName, category, null, description);
}
public static Option bool(String prefix, String name, Enum category, Boolean defval, String description) {
return new BooleanOption(prefix, name, category, defval, description);
}
public static Option bool(String longName, Enum category, Boolean defval, String description) {
return new BooleanOption(longName, category, defval, description);
}
public static Option integer(String prefix, String name, Enum category, String description) {
return new IntegerOption(prefix, name, category, null, description);
}
public static Option integer(String longName, Enum category, String description) {
return new IntegerOption(longName, category, null, description);
}
public static Option integer(String prefix, String name, Enum category, Integer defval, String description) {
return new IntegerOption(prefix, name, category, defval, description);
}
public static Option integer(String longName, Enum category, Integer defval, String description) {
return new IntegerOption(longName, category, defval, description);
}
public static Option integer(String prefix, String name, Enum category, Integer[] options, Integer defval, String description) {
return new IntegerOption(prefix, name, category, options, defval, description);
}
public static Option integer(String longName, Enum category, Integer[] options, Integer defval, String description) {
return new IntegerOption(longName, category, options, defval, description);
}
public static > Option enumeration(String prefix, String name, Enum category, Class enumClass, String description) {
return new EnumerationOption(prefix, name, category, enumClass, null, description);
}
public static > Option enumeration(String longName, Enum category, Class enumClass, String description) {
return new EnumerationOption(longName, category, enumClass, null, description);
}
public static > Option enumeration(String prefix, String name, Enum category, Class enumClass, T defval, String description) {
return new EnumerationOption(prefix, name, category, enumClass, defval, description);
}
public static > Option enumeration(String longName, Enum category, Class enumClass, T defval, String description) {
return new EnumerationOption(longName, category, enumClass, defval, description);
}
public static String formatValues(Collection
© 2015 - 2025 Weber Informatics LLC | Privacy Policy