|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.xerial.util.cui.OptionParser<OptionID>
public class OptionParser<OptionID extends Comparable>
OptionParser parses command line arguments
public static void main(String[] args)
{
enum Opt { HELP, OUTDIR }
OptionParser<Opt> p = new OptionParser<Opt>();
p.addOption(Opt.HELP, "h", "help", "display help message");
// adds an option with an argument whose default value is "."
p.addOptionWithArgument(Opt.OUTDIR, "o", "outdir", "DIR", "specify output direcotry", ".");
p.parse(args);
if(p.isSet(Opt.HELP))
{
// print help message
System.out.println(p.helpMessage());
return;
}
if(p.isSet(Opt.OUTDIR))
{
String outDir = p.getValue(Opt.OUTDIR);
}
}
| Constructor Summary | |
|---|---|
OptionParser()
A constructor |
|
| Method Summary | |
|---|---|
void |
addOption(Option<OptionID> option)
Deprecated. use addOption(Comparable, String, String, String, OptionHandler)
instead. |
void |
addOption(OptionID optionID,
String shortOptionName,
String longOptionName,
String description)
Adds an option to detect |
void |
addOption(OptionID optionID,
String shortOptionName,
String longOptionName,
String description,
boolean presetValue)
Adds an option with the default argument (set or not set) |
void |
addOption(OptionID optionID,
String shortOptionName,
String longOptionName,
String description,
OptionHandler handler)
Adds an option to detect |
void |
addOptionGroup(OptionGroup<OptionID> optionGroup)
Adds an option group |
void |
addOptionWithArgument(OptionID optionID,
String shortOptionName,
String longOptionName,
String argumentName,
String description)
Adds an option that takes an argument value |
void |
addOptionWithArgument(OptionID optionID,
String shortOptionName,
String longOptionName,
String argumentName,
String description,
OptionHandler<OptionID> handler)
Adds an option that takes an argument value |
void |
addOptionWithArgument(OptionID optionID,
String shortOptionName,
String longOptionName,
String argumentName,
String description,
String defaultValue)
Adds an option that takes an argument value |
void |
addOptionWithArgument(OptionID optionID,
String shortOptionName,
String longOptionName,
String argumentName,
String description,
String defaultValue,
OptionHandler<OptionID> handler)
Adds an option that takes an argument value |
List<String> |
getArgument()
オプション関連以外のコマンドラインの引数のリストを得る |
String |
getArgument(int index)
index番目のコマンドライン引数(オプション以外) |
int |
getArgumentLength()
オプション以外のコマンドライン引数の数を返す |
double |
getDoubleValue(OptionID optionID)
option引数の double値 |
float |
getFloatValue(OptionID optionID)
option引数のfloat値 |
int |
getIntValue(OptionID optionID)
option引数(例:--width=100 の100) のint value |
String |
getValue(OptionID optionID)
Gets the option argument value as a String |
String |
getValue(OptionID optionID,
String defaultValue)
Gets the option argument value as a String |
String |
helpMessage()
Generates the help message for this option parser |
boolean |
isSet(OptionID optionID)
特定のoptionがセットされているか調べる |
void |
parse(String[] args)
Parses the command line arguments. |
void |
setIgnoreUnknownOption(boolean ignore)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public OptionParser()
| Method Detail |
|---|
public void addOption(OptionID optionID,
String shortOptionName,
String longOptionName,
String description)
optionID - the option IDshortOptionName - the short option name, e.g. "h", which corresponds to "-h" in
the command line arguments.longOptionName - the long option name, e.g. "help", which corresponds to
"--help" in the command line arguments.description - the description of the option, which is used to generate the
help message of this option
public void addOption(OptionID optionID,
String shortOptionName,
String longOptionName,
String description,
OptionHandler handler)
optionID - the option IDshortOptionName - the short option name, e.g. "h", which corresponds to "-h" in
the command line arguments.longOptionName - the long option name, e.g. "help", which corresponds to
"--help" in the command line arguments.description - the description of the option, which is used to generate the
help message of this optionhandler - the option argument handler invoked when the option is setpublic void addOption(Option<OptionID> option)
addOption(Comparable, String, String, String, OptionHandler)
instead.
option -
public void addOption(OptionID optionID,
String shortOptionName,
String longOptionName,
String description,
boolean presetValue)
optionID - the option IDshortOptionName - the short option name, e.g. "h", which corresponds to "-h" in
the command line arguments.longOptionName - the long option name, e.g. "help", which corresponds to
"--help" in the command line arguments.description - the description of the option, which is used to generate the
help message of this optionpresetValue - when true, the option is assumed to be set in default,
otherwise false
public void addOptionWithArgument(OptionID optionID,
String shortOptionName,
String longOptionName,
String argumentName,
String description)
optionID - the option IDshortOptionName - the short option name, e.g. "h", which corresponds to "-h" in
the command line arguments.longOptionName - the long option name, e.g. "help", which corresponds to
"--help" in the command line arguments.description - the description of the option, which is used to generate the
help message of this option
public void addOptionWithArgument(OptionID optionID,
String shortOptionName,
String longOptionName,
String argumentName,
String description,
OptionHandler<OptionID> handler)
optionID - the option IDshortOptionName - the short option name, e.g. "h", which corresponds to "-h" in
the command line arguments.longOptionName - the long option name, e.g. "help", which corresponds to
"--help" in the command line arguments.description - the description of the option, which is used to generate the
help message of this optionhandler - the option argument handler invoked when the option is set
public void addOptionWithArgument(OptionID optionID,
String shortOptionName,
String longOptionName,
String argumentName,
String description,
String defaultValue)
optionID - the option IDshortOptionName - the short option name, e.g. "h", which corresponds to "-h" in
the command line arguments.longOptionName - the long option name, e.g. "help", which corresponds to
"--help" in the command line arguments.description - the description of the option, which is used to generate the
help message of this optiondefaultValue - the default value of the option
public void addOptionWithArgument(OptionID optionID,
String shortOptionName,
String longOptionName,
String argumentName,
String description,
String defaultValue,
OptionHandler<OptionID> handler)
optionID - the option IDshortOptionName - the short option name, e.g. "h", which corresponds to "-h" in
the command line arguments.longOptionName - the long option name, e.g. "help", which corresponds to
"--help" in the command line arguments.description - the description of the option, which is used to generate the
help message of this optiondefaultValue - the default value of the optionhandler - the option argument handler invoked when the option is setpublic void addOptionGroup(OptionGroup<OptionID> optionGroup)
optionGroup - the option group
public void parse(String[] args)
throws OptionParserException
isSet(Comparable) or
getValue(Comparable) methods, etc.
args - the command line arguments, which is given by the
main(String[] args) method
OptionParserException - when the given command line has invalid syntax or when
incompatible options are set at the same time.public List<String> getArgument()
public String getArgument(int index)
index -
public int getArgumentLength()
public boolean isSet(OptionID optionID)
throws OptionParserException
optionID -
OptionParserException - optionIDに該当するオプションが設定されていない場合
public int getIntValue(OptionID optionID)
throws OptionParserException
optionID -
OptionParserException - 該当するoptionIDはない、あるいは引数がintに変換できない場合、あるいは引数を取れないオプションの場合
public double getDoubleValue(OptionID optionID)
throws OptionParserException
optionID -
OptionParserException - 該当するoptionIDはない、あるいは引数がdoubleに変換できない場合、あるいは引数を取れないオプションの場合
public float getFloatValue(OptionID optionID)
throws OptionParserException
optionID -
OptionParserException - 該当するoptionIDはない、あるいは引数がfloatに変換できない場合、あるいは引数を取れないオプションの場合
public String getValue(OptionID optionID)
throws OptionParserException
String
optionID - the target option that takes argument value
OptionParserException - if the specified option ID is not found or if the option
cannot take arguments
public String getValue(OptionID optionID,
String defaultValue)
throws OptionParserException
String
optionID - the target option that takes argument valuedefaultValue - the default value to be returned when this option is not
present in the command line arguments
OptionParserException - if the specified option ID is not found or if the option
cannot take argumentspublic String helpMessage()
public void setIgnoreUnknownOption(boolean ignore)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
