com.uc4.ara.collabnet.JArgs
Class CmdLineParser

java.lang.Object
  extended by com.uc4.ara.collabnet.JArgs.CmdLineParser

public class CmdLineParser
extends java.lang.Object


Nested Class Summary
static class CmdLineParser.IllegalOptionValueException
          Thrown when an illegal or missing value is given by the user for an option that takes a value.
static class CmdLineParser.NotFlagException
          Thrown when the parsed commandline contains multiple concatenated short options, such as -abcd, where one or more requires a value.
static class CmdLineParser.Option<T>
          Representation of a command-line option
static class CmdLineParser.OptionException
          Base class for exceptions that may be thrown when options are parsed
static class CmdLineParser.UnknownOptionException
          Thrown when the parsed command-line contains an option that is not recognised.
static class CmdLineParser.UnknownSuboptionException
          Thrown when the parsed commandline contains multiple concatenated short options, such as -abcd, where one is unknown.
 
Constructor Summary
CmdLineParser()
           
 
Method Summary
 CmdLineParser.Option<java.lang.Boolean> addBooleanOption(java.lang.String longForm, boolean required)
          Convenience method for adding a boolean option.
 CmdLineParser.Option<java.lang.Boolean> addBooleanOption(java.lang.String shortForm, java.lang.String longForm, boolean required)
          Convenience method for adding a boolean option.
 CmdLineParser.Option<java.lang.Double> addDoubleOption(java.lang.String longForm, boolean required)
          Convenience method for adding a double option.
 CmdLineParser.Option<java.lang.Double> addDoubleOption(java.lang.String shortForm, java.lang.String longForm, boolean required)
          Convenience method for adding a double option.
<T> CmdLineParser.Option<T>
addHelp(CmdLineParser.Option<T> option, java.lang.String helpString)
           
 CmdLineParser.Option<java.lang.Integer> addIntegerOption(java.lang.String longForm, boolean required)
          Convenience method for adding an integer option.
 CmdLineParser.Option<java.lang.Integer> addIntegerOption(java.lang.String shortForm, java.lang.String longForm, boolean required)
          Convenience method for adding an integer option.
 CmdLineParser.Option<java.lang.Long> addLongOption(java.lang.String longForm, boolean required)
          Convenience method for adding a long integer option.
 CmdLineParser.Option<java.lang.Long> addLongOption(java.lang.String shortForm, java.lang.String longForm, boolean required)
          Convenience method for adding a long integer option.
<T> CmdLineParser.Option<T>
addOption(CmdLineParser.Option<T> opt)
          Add the specified Option to the list of accepted options
 CmdLineParser.Option<java.lang.String> addStringOption(java.lang.String longForm, boolean required)
          Convenience method for adding a string option.
 CmdLineParser.Option<java.lang.String> addStringOption(java.lang.String shortForm, java.lang.String longForm, boolean required)
          Convenience method for adding a string option.
<T> T
getOptionValue(CmdLineParser.Option<T> o)
          Equivalent to getOptionValue(o, null).
<T> T
getOptionValue(CmdLineParser.Option<T> o, T def)
           
<T> java.util.Collection<T>
getOptionValues(CmdLineParser.Option<T> option)
           
 java.lang.String[] getRemainingArgs()
           
 void parse(java.lang.String[] argv)
          Extract the options and non-option arguments from the given list of command-line arguments.
 void parse(java.lang.String[] argv, java.util.Locale locale)
          Extract the options and non-option arguments from the given list of command-line arguments.
 void printUsage(java.lang.String feature)
           
 void setExamples(java.lang.String examples)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CmdLineParser

public CmdLineParser()
Method Detail

addOption

public final <T> CmdLineParser.Option<T> addOption(CmdLineParser.Option<T> opt)
Add the specified Option to the list of accepted options


addStringOption

public final CmdLineParser.Option<java.lang.String> addStringOption(java.lang.String shortForm,
                                                                    java.lang.String longForm,
                                                                    boolean required)
Convenience method for adding a string option.

Returns:
the new Option

addStringOption

public final CmdLineParser.Option<java.lang.String> addStringOption(java.lang.String longForm,
                                                                    boolean required)
Convenience method for adding a string option.

Returns:
the new Option

addIntegerOption

public final CmdLineParser.Option<java.lang.Integer> addIntegerOption(java.lang.String shortForm,
                                                                      java.lang.String longForm,
                                                                      boolean required)
Convenience method for adding an integer option.

Returns:
the new Option

addIntegerOption

public final CmdLineParser.Option<java.lang.Integer> addIntegerOption(java.lang.String longForm,
                                                                      boolean required)
Convenience method for adding an integer option.

Returns:
the new Option

addLongOption

public final CmdLineParser.Option<java.lang.Long> addLongOption(java.lang.String shortForm,
                                                                java.lang.String longForm,
                                                                boolean required)
Convenience method for adding a long integer option.

Returns:
the new Option

addLongOption

public final CmdLineParser.Option<java.lang.Long> addLongOption(java.lang.String longForm,
                                                                boolean required)
Convenience method for adding a long integer option.

Returns:
the new Option

addDoubleOption

public final CmdLineParser.Option<java.lang.Double> addDoubleOption(java.lang.String shortForm,
                                                                    java.lang.String longForm,
                                                                    boolean required)
Convenience method for adding a double option.

Returns:
the new Option

addDoubleOption

public final CmdLineParser.Option<java.lang.Double> addDoubleOption(java.lang.String longForm,
                                                                    boolean required)
Convenience method for adding a double option.

Returns:
the new Option

addBooleanOption

public final CmdLineParser.Option<java.lang.Boolean> addBooleanOption(java.lang.String shortForm,
                                                                      java.lang.String longForm,
                                                                      boolean required)
Convenience method for adding a boolean option.

Returns:
the new Option

addBooleanOption

public final CmdLineParser.Option<java.lang.Boolean> addBooleanOption(java.lang.String longForm,
                                                                      boolean required)
Convenience method for adding a boolean option.

Returns:
the new Option

getOptionValue

public final <T> T getOptionValue(CmdLineParser.Option<T> o)
                       throws java.lang.Exception
Equivalent to getOptionValue(o, null).

Throws:
CmdLineParser.OptionException
java.lang.Exception

getOptionValue

public final <T> T getOptionValue(CmdLineParser.Option<T> o,
                                  T def)
                       throws java.lang.Exception
Returns:
the parsed value of the given Option, or the given default 'def' if the option was not set
Throws:
CmdLineParser.OptionException
java.lang.Exception

getOptionValues

public final <T> java.util.Collection<T> getOptionValues(CmdLineParser.Option<T> option)
                                              throws java.lang.Exception
Returns:
A Collection giving the parsed values of all the occurrences of the given Option, or an empty Collection if the option was not set.
Throws:
CmdLineParser.OptionException
java.lang.Exception

getRemainingArgs

public final java.lang.String[] getRemainingArgs()
Returns:
the non-option arguments

parse

public final void parse(java.lang.String[] argv)
                 throws CmdLineParser.OptionException
Extract the options and non-option arguments from the given list of command-line arguments. The default locale is used for parsing options whose values might be locale-specific.

Throws:
CmdLineParser.OptionException

parse

public final void parse(java.lang.String[] argv,
                        java.util.Locale locale)
                 throws CmdLineParser.OptionException
Extract the options and non-option arguments from the given list of command-line arguments. The specified locale is used for parsing options whose values might be locale-specific.

Throws:
CmdLineParser.OptionException

addHelp

public <T> CmdLineParser.Option<T> addHelp(CmdLineParser.Option<T> option,
                                           java.lang.String helpString)

setExamples

public void setExamples(java.lang.String examples)

printUsage

public void printUsage(java.lang.String feature)


Copyright © 2004-2013. All Rights Reserved.