edu.toronto.cs.util
Class Clapi.OptSpec

java.lang.Object
  extended by edu.toronto.cs.util.Clapi.OptSpec
Enclosing class:
Clapi

public static class Clapi.OptSpec
extends java.lang.Object

An option specifier provides a builder API for specifying the features of an option.


Constructor Summary
Clapi.OptSpec(Clapi.OptParser _parser)
           
 
Method Summary
 Clapi.OptSpec argumentArity(int v)
          Specifies the number of arguments this parameter should receive.
 Clapi.BooleanOpt asBoolean()
          Wraps this specification as a Boolean option, adds it to the parser, and returns the Boolean option.
 Clapi.FileNameOpt asFileName()
          Wraps this specification as a FileName option, adds it to the parser, and returns the FileName option.
 Clapi.HelpOpt asHelp()
          Wraps this specification as a Help option, adds it to the parser, and returns the Help option.
 Clapi.IntOpt asInt()
          Wraps this specification as a Int option, adds it to the parser, and returns the Int option.
 Clapi.StringOpt asString()
          Wraps this specification as a String option, adds it to the parser, and returns the String option.
 Clapi.OptSpec description(java.lang.String v)
          Specifies this option's description: used in usage information.
 Clapi.OptSpec equals(java.lang.String v)
          Adds a equals specifier to this option spec.
 int getArgumentArity()
           
 java.lang.String getDescription()
           
 java.util.List getEqualses()
           
 java.util.List getGroups()
          Return the list of groups this option is a member of.
 java.util.List getLongNames()
           
 int getMaxArity()
           
 int getMinArity()
           
 boolean getNameless()
           
 java.util.List getPrefixes()
           
 boolean getRequired()
           
 java.util.List getShortNames()
           
 java.util.List getSuffixes()
           
 Clapi.OptSpec group(java.lang.String groupName)
          Specifies this option's string group name.
 boolean isList()
          Return true if this option may be specified more than once.
 boolean isRequired()
          Return true if this option must be specified.
 Clapi.OptSpec list()
          alias for maxArity (-1)
 Clapi.OptSpec longName(java.lang.String v)
          Adds a long name to this option spec.
 Clapi.OptSpec maxArity(int v)
          Specifies this option's maximum arity.
 Clapi.OptSpec minArity(int v)
          Specifies this option's minimum arity.
 Clapi.OptSpec nameless()
          Specifies that this option will be nameless.
 Clapi.OptSpec optional()
          alias for minArity (0)
 Clapi.OptSpec prefix(java.lang.String v)
          Adds a prefix specifier to this option spec.
 Clapi.OptSpec required()
          alias for minArity (1)
 Clapi.OptSpec shortName(char v)
          Adds a short name to this option spec.
 Clapi.OptSpec suffix(java.lang.String v)
          Adds a suffix specifier to this option spec.
 Clapi.OptSpec terminal()
          Specifies that this option should end the parsing of the tokens, and swallow all remaining tokens whole as its option value list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Clapi.OptSpec

public Clapi.OptSpec(Clapi.OptParser _parser)
Method Detail

asHelp

public Clapi.HelpOpt asHelp()
Wraps this specification as a Help option, adds it to the parser, and returns the Help option.


asBoolean

public Clapi.BooleanOpt asBoolean()
Wraps this specification as a Boolean option, adds it to the parser, and returns the Boolean option.


asString

public Clapi.StringOpt asString()
Wraps this specification as a String option, adds it to the parser, and returns the String option.


asInt

public Clapi.IntOpt asInt()
Wraps this specification as a Int option, adds it to the parser, and returns the Int option.


asFileName

public Clapi.FileNameOpt asFileName()
Wraps this specification as a FileName option, adds it to the parser, and returns the FileName option.


longName

public Clapi.OptSpec longName(java.lang.String v)
Adds a long name to this option spec.


shortName

public Clapi.OptSpec shortName(char v)
Adds a short name to this option spec.


equals

public Clapi.OptSpec equals(java.lang.String v)

Adds a equals specifier to this option spec.

An equals specifier says that if a particular string is found on the command line, it is to be processed by a particular option.


prefix

public Clapi.OptSpec prefix(java.lang.String v)

Adds a prefix specifier to this option spec.

An prefix specifier says that if a string with a particular prefix is found on the command line, it is to be processed by a particular option.


suffix

public Clapi.OptSpec suffix(java.lang.String v)

Adds a suffix specifier to this option spec.

An suffix specifier says that if a string with a particular suffix is found on the command line, it is to be processed by a particular option.


nameless

public Clapi.OptSpec nameless()

Specifies that this option will be nameless.

There may only be one nameless option. If an option is encountered which has no name (no short name or long name), and does not match any of the suffix, prefix, or equals rules), then it is processed by the nameless option, if it is available. Nameless options are often used for utilities which process a number of filenames, which may be arbitrary strings.


terminal

public Clapi.OptSpec terminal()

Specifies that this option should end the parsing of the tokens, and swallow all remaining tokens whole as its option value list.


minArity

public Clapi.OptSpec minArity(int v)

Specifies this option's minimum arity. It is a parse error for the option opt to be specified fewer than opt.getMinArity() times.

Some min arities of note are 0 (which means that the option is optional), and 1 (which means that the option is required).

The default minArity of any option is 0, meaning that it is optional.

See Also:
required, optional()

maxArity

public Clapi.OptSpec maxArity(int v)

Specifies this option's maximum arity. It is a parse error for the option opt to be specified more than opt.getMaxArity() times.

There is also special handling for values less than 0. If the maximuum arity is -1 or lower, then the option may be specified as many times as the user likes, and there will be no error.

Some min arities of note are 0 (which means that the option cannot be specified -- this is a stupid thing to set max arity to), 1 (which means that the option can only be specified once -- it is a singleton), and -1 (which means that the option can be specified as many times as the user would like.)

The default maxArity of any option is 1, meaning that it cannot be specified more than once.

See Also:
list()

argumentArity

public Clapi.OptSpec argumentArity(int v)

Specifies the number of arguments this parameter should receive.

If 0 arguments are specified,


description

public Clapi.OptSpec description(java.lang.String v)
Specifies this option's description: used in usage information.


group

public Clapi.OptSpec group(java.lang.String groupName)
Specifies this option's string group name. When usage information is printed out, options are grouped into these groups, and the group names are used as headers.


optional

public Clapi.OptSpec optional()
alias for minArity (0)


required

public Clapi.OptSpec required()
alias for minArity (1)


list

public Clapi.OptSpec list()
alias for maxArity (-1)


getLongNames

public java.util.List getLongNames()

getShortNames

public java.util.List getShortNames()

getEqualses

public java.util.List getEqualses()

getPrefixes

public java.util.List getPrefixes()

getSuffixes

public java.util.List getSuffixes()

getNameless

public boolean getNameless()

getDescription

public java.lang.String getDescription()

getRequired

public boolean getRequired()

getMinArity

public int getMinArity()

getMaxArity

public int getMaxArity()

getArgumentArity

public int getArgumentArity()

isRequired

public boolean isRequired()
Return true if this option must be specified.


isList

public boolean isList()
Return true if this option may be specified more than once.


getGroups

public java.util.List getGroups()
Return the list of groups this option is a member of.