org.datanucleus.util
Class CommandLine

java.lang.Object
  extended by org.datanucleus.util.CommandLine

public class CommandLine
extends java.lang.Object

Command line option parser. Used by command line applications such as Enhancer and SchemaTool to process command line arguments.


Nested Class Summary
protected static class CommandLine.NoArgOption
          No argument option class.
protected static class CommandLine.Option
          CommandLine option base class
protected static class CommandLine.WithArgOption
          Use argment option class.
 
Field Summary
protected  java.lang.String[] defaultArg
          Default arguments
protected  boolean displaysDash
          displays dash
protected  java.util.ArrayList optionList
          Appended options
protected  java.util.HashMap options
          Appended options
protected  java.lang.String originalArguments
           
protected  java.util.HashMap valueOptions
          Appended options
 
Constructor Summary
CommandLine()
          Default constructor
CommandLine(boolean displaysDash)
          Default constructor
 
Method Summary
 void addOption(java.lang.String shortName, java.lang.String longName, java.lang.String argName, java.lang.String desc)
          Add new Option.
 java.lang.String[] getDefaultArgs()
          Return default arguments.
 java.lang.String getOptionArg(java.lang.String name)
          Return option argument.
 java.lang.String getOriginalArguments()
          Return original arguments.
 boolean hasOption(java.lang.String name)
          Check option selected
 void parse(java.lang.String[] args)
          Parse command line argments.
 java.lang.String toString()
          Return string like useage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

options

protected java.util.HashMap options
Appended options


valueOptions

protected java.util.HashMap valueOptions
Appended options


optionList

protected java.util.ArrayList optionList
Appended options


defaultArg

protected java.lang.String[] defaultArg
Default arguments


originalArguments

protected java.lang.String originalArguments

displaysDash

protected boolean displaysDash
displays dash

Constructor Detail

CommandLine

public CommandLine()
Default constructor


CommandLine

public CommandLine(boolean displaysDash)
Default constructor

Parameters:
displaysDash - whether to display a dash in the short name
Method Detail

addOption

public void addOption(java.lang.String shortName,
                      java.lang.String longName,
                      java.lang.String argName,
                      java.lang.String desc)
Add new Option.
If argName is null, set this option no-arg option.

Parameters:
shortName - Short name option eg "d"
longName - Long name option eg "directory"
argName - Argment name. No argment option if this param is null.
desc - Desription this option.

parse

public void parse(java.lang.String[] args)
Parse command line argments.

Parameters:
args - Command line argments

hasOption

public boolean hasOption(java.lang.String name)
Check option selected

Parameters:
name - Option name (both short name and long name ok)
Returns:
Return true, if option selected.

getOptionArg

public java.lang.String getOptionArg(java.lang.String name)
Return option argument.

Parameters:
name - Option name (both short name and long name ok)
Returns:
option Argument
Throws:
java.lang.IllegalArgumentException - If unmanaged name recieved.

toString

public java.lang.String toString()
Return string like useage.

Overrides:
toString in class java.lang.Object
Returns:
Useage string

getDefaultArgs

public java.lang.String[] getDefaultArgs()
Return default arguments.

Returns:
Default arguments

getOriginalArguments

public java.lang.String getOriginalArguments()
Return original arguments.

Returns:
Original arguments


Copyright © 2011. All Rights Reserved.