Package org.grails.build.parsing
Class CommandLineParser
- java.lang.Object
-
- org.grails.build.parsing.CommandLineParser
-
public class CommandLineParser extends java.lang.ObjectCommand 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.- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description CommandLineParser()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddOption(java.lang.String name, java.lang.String description)Adds a declared optionprotected DefaultCommandLinecreateCommandLine()static CommandLinegetCurrentCommandLine()java.lang.StringgetOptionsHelpMessage()CommandLineparse(java.lang.String... args)Parses the given list of command line arguments.CommandLineparse(DefaultCommandLine cl, java.lang.String[] args)CommandLineparseString(java.lang.String string)Parses a string of all the command line options converting them into an array of arguments to pass to #parse(String..args)CommandLineparseString(java.lang.String commandName, java.lang.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 java.lang.StringprocessOption(DefaultCommandLine cl, java.lang.String arg)protected voidprocessSystemArg(DefaultCommandLine cl, java.lang.String arg)static java.lang.String[]translateCommandline(java.lang.String toProcess)Crack a command line.
-
-
-
Method Detail
-
getCurrentCommandLine
public static CommandLine getCurrentCommandLine()
-
addOption
public void addOption(java.lang.String name, java.lang.String description)Adds a declared option- Parameters:
name- The name of the optiondescription- The description
-
parseString
public CommandLine parseString(java.lang.String string)
Parses a string of all the command line options converting them into an array of arguments to pass to #parse(String..args)- Parameters:
string- The string- Returns:
- The command line
-
translateCommandline
public static java.lang.String[] translateCommandline(java.lang.String toProcess)
Crack a command line.- Parameters:
toProcess- the command line to process.- Returns:
- the command line broken into strings. An empty or null toProcess parameter results in a zero sized array.
-
parseString
public CommandLine parseString(java.lang.String commandName, java.lang.String args)
Parses a string of all the command line options converting them into an array of arguments to pass to #parse(String..args)- Parameters:
commandName- The command nameargs- The string- Returns:
- The command line
-
parse
public CommandLine parse(java.lang.String... args)
Parses 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- Parameters:
args- The arguments- Returns:
- The command line state
-
parse
public CommandLine parse(DefaultCommandLine cl, java.lang.String[] args)
-
getOptionsHelpMessage
public java.lang.String getOptionsHelpMessage()
-
createCommandLine
protected DefaultCommandLine createCommandLine()
-
processOption
protected java.lang.String processOption(DefaultCommandLine cl, java.lang.String arg)
-
processSystemArg
protected void processSystemArg(DefaultCommandLine cl, java.lang.String arg)
-
-