Griffon 1.2.0

org.codehaus.griffon.cli.parsing
[Java] Class CommandLineParser

java.lang.Object
  org.codehaus.griffon.cli.parsing.CommandLineParser

public class CommandLineParser

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.

Authors:
Graeme Rocher (Grails 2.0)


Field Summary
static Map DEFAULT_ENVS

private static String DEFAULT_PADDING

static Map ENV_ARGS

private Map declaredOptions

private int longestOptionNameLength

 
Constructor Summary
CommandLineParser()

 
Method Summary
void addOption(String name, String description)

Adds a declared option

protected DefaultCommandLine createCommandLine()

static String getDefaultEnvironmentForScript(String scriptName)

static String getExtendedEnvironmnentName(String env)

String getHelpMessage()

CommandLine parse(String... args)

Parses the given list of command line arguments.

private void parseInternal(DefaultCommandLine cl, String[] args, boolean firstArgumentIsCommand)

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)

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 void processOption(DefaultCommandLine cl, String arg)

protected void processSystemArg(DefaultCommandLine cl, String arg)

private void validateOptionName(String name)

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

DEFAULT_ENVS

static Map DEFAULT_ENVS


DEFAULT_PADDING

private static final String DEFAULT_PADDING


ENV_ARGS

static Map ENV_ARGS


declaredOptions

private Map declaredOptions


longestOptionNameLength

private int longestOptionNameLength


 
Constructor Detail

CommandLineParser

CommandLineParser()


 
Method Detail

addOption

public void addOption(String name, String description)
Adds a declared option
Parameters:
name - The name of the option
description - The description


createCommandLine

protected DefaultCommandLine createCommandLine()


getDefaultEnvironmentForScript

public static String getDefaultEnvironmentForScript(String scriptName)


getExtendedEnvironmnentName

public static String getExtendedEnvironmnentName(String env)


getHelpMessage

public String getHelpMessage()


parse

public CommandLine parse(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


parseInternal

private void parseInternal(DefaultCommandLine cl, String[] args, boolean firstArgumentIsCommand)


parseString

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)
Parameters:
string - The string
Returns:
The command line


parseString

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)
Parameters:
commandName - The command name
args - The string
Returns:
The command line


processOption

protected void processOption(DefaultCommandLine cl, String arg)


processSystemArg

protected void processSystemArg(DefaultCommandLine cl, String arg)


validateOptionName

private void validateOptionName(String name)


 

Groovy Documentation