Package com.yahoo.system
Class CommandLineParser
java.lang.Object
com.yahoo.system.CommandLineParser
Simple command line parser, handling multiple arguments and multiple unary and binary switches starting with -.
Terms used:
progname -binaryswitch foo -unaryswitch argument1 argument2
- Author:
- vegardh
-
Constructor Summary
ConstructorDescriptionCommandLineParser
(String[] cmds) CommandLineParser
(String progname, String[] cmds) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a legal binary switch without explanationvoid
addLegalBinarySwitch
(String s, String explanation) Add a legal binary switch such as "-f /foo/bar"void
void
addLegalUnarySwitch
(String s, String explanation) Add a legal unary switch such as "-d"void
addRequiredBinarySwitch
(String s, String explanation) Adds a required binary switchvoid
addRequiredUnarySwitch
(String s, String explanation) Adds a required switch, such as -pAll non-switch strings that were given on the command lineThe binary switches that were given on the command lineThe unary switches that were given on the command lineboolean
void
parse()
Parses the command linevoid
setArgumentExplanation
(String argumentExplanation) Sets the argument explanation used in printing method, i.e.void
setExtendedHelpText
(String text) void
setMaxArguments
(int maxArguments) Sets the maximum number of allowed argumentsvoid
setMinArguments
(int minArguments) Sets minimum number of required arguments
-
Constructor Details
-
CommandLineParser
-
CommandLineParser
-
-
Method Details
-
parse
public void parse()Parses the command line- Throws:
IllegalArgumentException
- if a parse error occured
-
addLegalUnarySwitch
Add a legal unary switch such as "-d" -
addLegalUnarySwitch
-
addRequiredUnarySwitch
Adds a required switch, such as -p -
addLegalBinarySwitch
Add a legal binary switch such as "-f /foo/bar" -
addLegalBinarySwitch
Adds a legal binary switch without explanation -
addRequiredBinarySwitch
Adds a required binary switch -
getUnarySwitches
The unary switches that were given on the command line -
getBinarySwitches
The binary switches that were given on the command line -
getArguments
All non-switch strings that were given on the command line -
setArgumentExplanation
Sets the argument explanation used in printing method, i.e. "names,..." -
setExtendedHelpText
-
getHelpText
-
setMinArguments
public void setMinArguments(int minArguments) Sets minimum number of required arguments -
setMaxArguments
public void setMaxArguments(int maxArguments) Sets the maximum number of allowed arguments -
helpSwitchUsed
public boolean helpSwitchUsed()
-