public class CommandLineParser extends Object
Command line parser that parses arguments to the command line. Written as a replacement for Commons CLI because it doesn't support unknown arguments and requires all arguments to be declared up front. It also doesn't support command options with hyphens. This class gets around those problems.
Type Params | Return Type | Name and description |
---|---|---|
|
public void |
addOption(String name, String description) Adds a declared option |
|
protected DefaultCommandLine |
createCommandLine() |
|
public static CommandLine |
getCurrentCommandLine() |
|
public String |
getOptionsHelpMessage() |
|
public CommandLine |
parse(String args) Parses the given list of command line arguments. |
|
public CommandLine |
parse(DefaultCommandLine cl, String[] args) |
|
public CommandLine |
parseString(String string) Parses a string of all the command line options converting them into an array of arguments to pass to #parse(String..args) |
|
public CommandLine |
parseString(String commandName, String args) Parses a string of all the command line options converting them into an array of arguments to pass to #parse(String..args) |
|
protected String |
processOption(DefaultCommandLine cl, String arg) |
|
protected void |
processSystemArg(DefaultCommandLine cl, String arg) |
|
public static String[] |
translateCommandline(String toProcess) Crack a command line. |
Adds a declared option
name
- The name of the optiondescription
- The descriptionParses the given list of command line arguments. Arguments starting with -D become system properties, arguments starting with -- or - become either declared or undeclared options. All other arguments are put into a list of remaining arguments
args
- The argumentsParses a string of all the command line options converting them into an array of arguments to pass to #parse(String..args)
string
- The stringParses a string of all the command line options converting them into an array of arguments to pass to #parse(String..args)
commandName
- The command nameargs
- The string