FreeHEP API
Version current

Package org.freehep.util.commandline

CommandLine parses a command line for parameters and options.

See:
          Description

Class Summary
CommandLine CommandLine parses a command line for parameters and options.
CommandLine.Option Keeps option names and types.
CommandLine.Parameter Keeps mandatory and optional parameter names.
 

Exception Summary
CommandLineException Superclass of all Command Line exceptions.
MissingArgumentException Too few arguments were provided.
NoSuchOptionException Option does not exist, or an ampty option is provided.
NoSuchQualifierException Qualifier does not exist.
TooManyArgumentsException Too many arguments were provided.
 

Package org.freehep.util.commandline Description

CommandLine parses a command line for parameters and options.

It allows the user to set up a command line for a command, and specify what options can be used, what these options mean, what parameters can be specified and what they mean, the minimum number of needed parameters, and if the parameter list is variable. * The CommandLine is created with the name and description of the command:

CommandLine cl = new CommandLine("java", "Java Virtual Machine (version 1.2)");

Possible options are added by calling one of the following methods:

The following methods are available to access the definitions of the command line:

To parse a commandline call: cl.parse(args); which returns true if parsing was ok, throws a CommandLineException if something went wrong, and returns false, if a BailOut option was provided. BailOut options allow the program to give feedback to the user for for instance -help or -version options.

The exception can also be retrieved by calling: getException()

The method getHelp() returns a multi-line string describing the full command and its options.

Once parsing succeeds the following methods can be used to see if options were set and to retrieve the parameters:

See the table below to find out what each of these methods returns:

FLAGS
-version         : hasOption("version")              -> true
-x-y             : hasOption("x")                    -> true 
                   hasOption("y")                    -> true
                   hasOption("notSetFlag")           -> false
                   hasOption("unknown")              -> NoSuchOptionException
 *
QUALIFIED FLAGS
-verbose         : hasOption("verbose")              -> true
                 : getOption("verbose")              -> ""
-verbose:gc      : hasOption("verbose")              -> true
                 : getOption("verbose")              -> "gc"
                 : getOption("notSetQualifiedFlag")  -> null
                 : getOption("unknown")              -> NoSuchOptionException
 *
OPTIONS
-cp classpath    : getOption("cp")                   -> "classpath"
-startup=now     : getOption("startup")              -> "now"
                 : getOption("notSetOption")         -> null
                 : getOption("unknown")              -> NoSuchOptionException
* lookups of flags will return the boolean value of that flag

lookups of options will return the value of that option. If this value cannot be found, then if the flag is set to true an empty string will be returned. If not found at all, null will be returned.

Status:
Stable


FreeHEP API
Version current

Copyright © 2000-2004 FreeHEP, All Rights Reserved.