jasm.util
Class OptArg

java.lang.Object
  extended by jasm.util.OptArg

public final class OptArg
extends java.lang.Object

A small utility for parsing command-line options. It helps to take some of the hassle out of building the front-end of a Whiley compiler.

Author:
David J. Pearce

Field Summary
 jasm.util.OptArg.Kind argument
          The kind of argument accepted by this option (if any).
 java.lang.Object defaultValue
          A default value for the option (assuming it accepts an argument).
 java.lang.String description
          A description of the option.
static jasm.util.OptArg.FILE FILE
           
static jasm.util.OptArg.FILEDIR FILEDIR
           
static jasm.util.OptArg.FILELIST FILELIST
           
static jasm.util.OptArg.INT INT
           
 java.lang.String option
          The long form of the option.
 java.lang.String shortForm
          The short form of the option.
static jasm.util.OptArg.STRING STRING
           
 
Constructor Summary
OptArg(java.lang.String option, jasm.util.OptArg.Kind argument, java.lang.String description)
          Construct an option object which accepts an argument.
OptArg(java.lang.String option, jasm.util.OptArg.Kind argument, java.lang.String description, java.lang.Object defaultValue)
          Construct an option object which accepts an argument and has a default value.
OptArg(java.lang.String option, java.lang.String description)
          Construct an option object which does not accept an argument.
OptArg(java.lang.String option, java.lang.String shortForm, jasm.util.OptArg.Kind argument, java.lang.String description)
          Construct an option object with a short form which accepts an argument.
OptArg(java.lang.String option, java.lang.String shortForm, jasm.util.OptArg.Kind argument, java.lang.String description, java.lang.Object defaultValue)
          Construct an option object with a short form which accepts an argument and has a default value.
OptArg(java.lang.String option, java.lang.String shortForm, java.lang.String description)
          Construct an option object with a short form which does not accept an argument.
 
Method Summary
static java.util.Map<java.lang.String,java.lang.Object> parseOptions(java.util.List<java.lang.String> args, OptArg... options)
          Parse options from the list of arguments, removing those which are recognised.
static void usage(java.io.PrintStream output, OptArg... options)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

option

public final java.lang.String option
The long form of the option. (e.g. for "-version", the long form is "version")


shortForm

public final java.lang.String shortForm
The short form of the option. (e.g. for "-version", the short form might be "v" as in "-v")


argument

public final jasm.util.OptArg.Kind argument
The kind of argument accepted by this option (if any).


description

public final java.lang.String description
A description of the option. This is used when printing out "usage" information.


defaultValue

public final java.lang.Object defaultValue
A default value for the option (assuming it accepts an argument). This may be null if there is no default value.


STRING

public static final jasm.util.OptArg.STRING STRING

INT

public static final jasm.util.OptArg.INT INT

FILE

public static final jasm.util.OptArg.FILE FILE

FILEDIR

public static final jasm.util.OptArg.FILEDIR FILEDIR

FILELIST

public static final jasm.util.OptArg.FILELIST FILELIST
Constructor Detail

OptArg

public OptArg(java.lang.String option,
              java.lang.String description)
Construct an option object which does not accept an argument.

Parameters:
option -
argument -
description -
defaultValue -

OptArg

public OptArg(java.lang.String option,
              java.lang.String shortForm,
              java.lang.String description)
Construct an option object with a short form which does not accept an argument.

Parameters:
option -
shortForm -
argument -
description -
defaultValue -

OptArg

public OptArg(java.lang.String option,
              jasm.util.OptArg.Kind argument,
              java.lang.String description)
Construct an option object which accepts an argument.

Parameters:
option -
argument -
description -
defaultValue -

OptArg

public OptArg(java.lang.String option,
              java.lang.String shortForm,
              jasm.util.OptArg.Kind argument,
              java.lang.String description)
Construct an option object with a short form which accepts an argument.

Parameters:
option -
shortForm -
argument -
description -
defaultValue -

OptArg

public OptArg(java.lang.String option,
              jasm.util.OptArg.Kind argument,
              java.lang.String description,
              java.lang.Object defaultValue)
Construct an option object which accepts an argument and has a default value.

Parameters:
option -
argument -
description -
defaultValue -

OptArg

public OptArg(java.lang.String option,
              java.lang.String shortForm,
              jasm.util.OptArg.Kind argument,
              java.lang.String description,
              java.lang.Object defaultValue)
Construct an option object with a short form which accepts an argument and has a default value.

Parameters:
option -
argument -
description -
defaultValue -
Method Detail

parseOptions

public static java.util.Map<java.lang.String,java.lang.Object> parseOptions(java.util.List<java.lang.String> args,
                                                                            OptArg... options)
Parse options from the list of arguments, removing those which are recognised. Anything which is not recognised is left as is.

Parameters:
args - --- the list of argument strings. This is modified by removing those which are processed.
options - --- the list of OptArg defining which options should be processed
Throws:
--- - a RuntimeException if an unrecognised option is encountered (that is, a token starting with '-')..

usage

public static void usage(java.io.PrintStream output,
                         OptArg... options)


Copyright © 2013 David J. Pearce. All Rights Reserved.