Package org.apache.uima.internal.util
Class CommandLineParser
java.lang.Object
org.apache.uima.internal.util.CommandLineParser
Simple command line parsing utility.
The parser can only handle parameters that take 0 or 1 arguments. That is, you can parse command lines like
doit -f -i file1 -o file2 --dir file3 /h file4 file5 file6
The syntax of parameters is left to the user, no common prefix is assumed or enforced. Parameter
names can be arbitrarily long. You can define aliases for parameters: -h
,
/H
and --help
can all mean the same parameter if so configured.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Add an alias for an already defined parameter.boolean
addParameter
(String paramName) Add a new switch.boolean
addParameter
(String paramName, boolean hasArg) Add a new parameter name.getParamArgument
(String paramName) Get the argument to a parameter, if it exists.String[]
Get the rest of the args, i.e., args that follow the last know parameter.boolean
isInArgsList
(String paramName) Check if the parameter was used on the command line.boolean
isKnownParameter
(String paramName) Check if the given parameter name is known to this parser.void
parseCmdLine
(String[] args) Parse the command line.
-
Constructor Details
-
CommandLineParser
public CommandLineParser()Create a new command line parser.
-
-
Method Details
-
addParameter
Add a new parameter name.- Parameters:
paramName
- The name of the parameter.hasArg
- If the command line argument following this parameter should be interpreted as an argument to the parameter.- Returns:
false
iffparamName
already exists.
-
addParameter
Add a new switch. This is the same as callingaddParameter(name, false)
.- Parameters:
paramName
- The name of the parameter.- Returns:
false
iffparamName
already exists.
-
addAlias
Add an alias for an already defined parameter.- Parameters:
param
- A known parameter.alias
- The alias.- Returns:
false
iff the parameter does not exist or the alias is already known.
-
parseCmdLine
Parse the command line.- Parameters:
args
- The command line args as passed tomain()
.- Throws:
Exception
- If a parameter that requires an argument does not have one (i.e., is the last parameter in the list).
-
getRestArgs
Get the rest of the args, i.e., args that follow the last know parameter.- Returns:
- The tail end of the args list, usually file name arguments.
-
isKnownParameter
Check if the given parameter name is known to this parser.- Parameters:
paramName
- The name of the parameter.- Returns:
true
iff the name was added withaddParameter()
oraddAlias()
.
-
isInArgsList
Check if the parameter was used on the command line.- Parameters:
paramName
- The name of the parameter.- Returns:
true
iff the name is known and was used as a command line argument.
-
getParamArgument
Get the argument to a parameter, if it exists.- Parameters:
paramName
- The name of the parameter.- Returns:
- The argument to the parameter if the parameter was used and takes an argument;
null
, else.
-