Package com.yahoo.system
Class CommandLineParser
- java.lang.Object
-
- com.yahoo.system.CommandLineParser
-
public class CommandLineParser extends Object
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
Constructors Constructor Description CommandLineParser(String[] cmds)
CommandLineParser(String progname, String[] cmds)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addLegalBinarySwitch(String s)
Adds a legal binary switch without explanationvoid
addLegalBinarySwitch(String s, String explanation)
Add a legal binary switch such as "-f /foo/bar"void
addLegalUnarySwitch(String s)
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 -pList<String>
getArguments()
All non-switch strings that were given on the command lineMap<String,String>
getBinarySwitches()
The binary switches that were given on the command lineString
getHelpText()
List<String>
getUnarySwitches()
The unary switches that were given on the command lineboolean
helpSwitchUsed()
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
-
-
-
Method Detail
-
parse
public void parse()
Parses the command line- Throws:
IllegalArgumentException
- if a parse error occured
-
addLegalUnarySwitch
public void addLegalUnarySwitch(String s, String explanation)
Add a legal unary switch such as "-d"
-
addLegalUnarySwitch
public void addLegalUnarySwitch(String s)
-
addRequiredUnarySwitch
public void addRequiredUnarySwitch(String s, String explanation)
Adds a required switch, such as -p
-
addLegalBinarySwitch
public void addLegalBinarySwitch(String s, String explanation)
Add a legal binary switch such as "-f /foo/bar"
-
addLegalBinarySwitch
public void addLegalBinarySwitch(String s)
Adds a legal binary switch without explanation
-
addRequiredBinarySwitch
public void addRequiredBinarySwitch(String s, String explanation)
Adds a required binary switch
-
getUnarySwitches
public List<String> getUnarySwitches()
The unary switches that were given on the command line
-
getBinarySwitches
public Map<String,String> getBinarySwitches()
The binary switches that were given on the command line
-
getArguments
public List<String> getArguments()
All non-switch strings that were given on the command line
-
setArgumentExplanation
public void setArgumentExplanation(String argumentExplanation)
Sets the argument explanation used in printing method, i.e. "names,..."
-
setExtendedHelpText
public void setExtendedHelpText(String text)
-
getHelpText
public String 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()
-
-