Package com.ibm.icu.dev.tool.shared
Class UOption
- java.lang.Object
-
- com.ibm.icu.dev.tool.shared.UOption
-
public class UOption extends java.lang.Object
A command-line option. A UOption specifies the name of an option and whether or not it takes an argument. It is a mutable object that later contains the option argument, if any, and a boolean flag stating whether the option was seen or not. The static method parseArgs() takes an array of command-line arguments and an array of UOptions and parses the command-line arguments. This deliberately resembles the icu4c file uoption.[ch].
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
UOption.Fn
-
Field Summary
Fields Modifier and Type Field Description java.lang.Object
context
boolean
doesOccur
int
hasArg
java.lang.String
longName
static int
NO_ARG
static int
OPTIONAL_ARG
UOption.Fn
optionFn
static int
REQUIRES_ARG
char
shortName
java.lang.String
value
-
Constructor Summary
Constructors Modifier Constructor Description private
UOption(java.lang.String aLongName, char aShortName, int hasArgument)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static UOption
BUNDLE_NAME()
static UOption
COPYRIGHT()
static UOption
create(java.lang.String aLongName, char aShortName, int hasArgument)
Create a UOption with the given attributes.static UOption
DEF(java.lang.String aLongName, char aShortName, int hasArgument)
Create a UOption with the given attributes.static UOption
DESTDIR()
static UOption
ENCODING()
static UOption
HELP_H()
static UOption
HELP_QUESTION_MARK()
static UOption
ICUDATADIR()
static UOption
PACKAGE_NAME()
static int
parseArgs(java.lang.String[] argv, int start, UOption[] options)
Java Command line argument parser.static int
parseArgs(java.lang.String[] argv, UOption[] options)
Convenient method.static UOption
QUIET()
UOption
setDefault(java.lang.String s)
Allows the default to be set in an option list.static UOption
SOURCEDIR()
private static void
syntaxError(java.lang.String message)
Throw an exception indicating a syntax error.static UOption
VERBOSE()
static UOption
VERSION()
-
-
-
Field Detail
-
longName
public java.lang.String longName
-
value
public java.lang.String value
-
optionFn
public UOption.Fn optionFn
-
context
public java.lang.Object context
-
shortName
public char shortName
-
hasArg
public int hasArg
-
doesOccur
public boolean doesOccur
-
NO_ARG
public static final int NO_ARG
- See Also:
- Constant Field Values
-
REQUIRES_ARG
public static final int REQUIRES_ARG
- See Also:
- Constant Field Values
-
OPTIONAL_ARG
public static final int OPTIONAL_ARG
- See Also:
- Constant Field Values
-
-
Method Detail
-
create
public static UOption create(java.lang.String aLongName, char aShortName, int hasArgument)
Create a UOption with the given attributes.
-
DEF
public static UOption DEF(java.lang.String aLongName, char aShortName, int hasArgument)
Create a UOption with the given attributes. Synonym for create(), for C compatibility.
-
HELP_H
public static UOption HELP_H()
-
HELP_QUESTION_MARK
public static UOption HELP_QUESTION_MARK()
-
VERBOSE
public static UOption VERBOSE()
-
QUIET
public static UOption QUIET()
-
VERSION
public static UOption VERSION()
-
COPYRIGHT
public static UOption COPYRIGHT()
-
DESTDIR
public static UOption DESTDIR()
-
SOURCEDIR
public static UOption SOURCEDIR()
-
ENCODING
public static UOption ENCODING()
-
ICUDATADIR
public static UOption ICUDATADIR()
-
PACKAGE_NAME
public static UOption PACKAGE_NAME()
-
BUNDLE_NAME
public static UOption BUNDLE_NAME()
-
parseArgs
public static int parseArgs(java.lang.String[] argv, int start, UOption[] options)
Java Command line argument parser. This function takes the argv[] command line and a description of the program's options in form of an array of UOption structures. Each UOption defines a long and a short name (a string and a character) for options like "--foo" and "-f". Each option is marked with whether it does not take an argument, requires one, or optionally takes one. The argument may follow in the same argv[] entry for short options, or it may always follow in the next argv[] entry. An argument is in the next argv[] entry for both long and short name options, except it is taken from directly behind the short name in its own argv[] entry if there are characters following the option letter. An argument in its own argv[] entry must not begin with a '-' unless it is only the '-' itself. There is no restriction of the argument format if it is part of the short name options's argv[] entry. The argument is stored in the value field of the corresponding UOption entry, and the doesOccur field is set to 1 if the option is found at all. Short name options without arguments can be collapsed into a single argv[] entry. After an option letter takes an argument, following letters will be taken as its argument. If the same option is found several times, then the last argument value will be stored in the value field. For each option, a function can be called. This could be used for options that occur multiple times and all arguments are to be collected. All options are removed from the argv[] array itself. If the parser is successful, then it returns the number of remaining non-option strings. (Unlike C, the Java argv[] array does NOT contain the program name in argv[0].) An option "--" ends option processing; everything after this remains in the argv[] array. An option string "-" alone is treated as a non-option. If an option is not recognized or an argument missing, then the parser returns with the negative index of the argv[] entry where the error was detected.- Parameters:
argv
- this parameter is modifiedstart
- the first argument in argv[] to examine. Must be 0..argv.length-1. Arguments from 0..start-1 are ignored.options
- this parameter is modified- Returns:
- the number of unprocessed arguments in argv[], including arguments 0..start-1.
-
setDefault
public UOption setDefault(java.lang.String s)
Allows the default to be set in an option list.- Parameters:
s
-- Returns:
- this
-
parseArgs
public static int parseArgs(java.lang.String[] argv, UOption[] options)
Convenient method.
-
syntaxError
private static void syntaxError(java.lang.String message)
Throw an exception indicating a syntax error.
-
-