Qizx/Open v0.4

net.xfra.qizxopen.util
Class CmdLine

java.lang.Object
  |
  +--net.xfra.qizxopen.util.CmdLine

public class CmdLine
extends java.lang.Object

Command line option analyzer.

Options are defined. When an option is recognized by the parse method, either a field of a target application object can be set, or a method of this object can be invoked.


Nested Class Summary
static class CmdLine.Error
           
 
Constructor Summary
CmdLine(java.lang.String appName)
          Creation with an application name.
 
Method Summary
 void define(java.lang.String keyDef, java.lang.String argLabel, java.lang.String actionDef, java.lang.String help)
          Defines an option.
 void parse(java.lang.String[] args, java.lang.Object appli)
          Parses the command line.
 void printHelp(java.io.PrintStream out)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CmdLine

public CmdLine(java.lang.String appName)
Creation with an application name.

Options must then be defined by define().

Parameters:
appName - name of the application
Method Detail

define

public void define(java.lang.String keyDef,
                   java.lang.String argLabel,
                   java.lang.String actionDef,
                   java.lang.String help)
Defines an option.

Parameters:
keyDef - appearance of the option switch. A null key means stray argument.

The last character defines how an argument of this switch is processed (the argument value can be assigned to a field or passed to a method, according to parameter actionDef):

  • Dot '.' or ARG_SET: no following argument, pass a Boolean.TRUE value.
  • Dash '-' or ARG_RESET: no following argument, pass a Boolean.FALSE value.
  • Underscore '_' or ARG_NEXT: argument follows after a space, pass its value.
  • Colon ':' or ARG_STUCK: argument is stuck to this option switch.
  • Star '*' or ARG_ALL: get all following command-line arguments into a String array value.
argLabel - A description of the argument.
actionDef - name of a Java field or a method of the application object. The first character defines the action: '!' calls a method, '=' sets a field, '?' prints the help.
help - option help description.

parse

public void parse(java.lang.String[] args,
                  java.lang.Object appli)
           throws java.lang.Exception
Parses the command line.

Option switches can either set the value of a member of object 'appli', or call a method of this object.

java.lang.Exception

printHelp

public void printHelp(java.io.PrintStream out)

 Copyright Xavier FRANC 2003-2004