jcmdline
Class PosixCmdLineParser

java.lang.Object
  extended by jcmdline.PosixCmdLineParser
All Implemented Interfaces:
CmdLineParser

public class PosixCmdLineParser
extends java.lang.Object
implements CmdLineParser

Used to parse the parameters associated with an executable's command line.

The following semantics are used throughout the documentation for this class. A command line parameter refers to either a command line option, or a command line argument.

A command line option is preceded by either a '-', or a '--', and may, optionally, have an associated value separated from the option "tag" by a space or an '='. Command line options end with the first parameter (that has not already been parsed as an option or option value) that does not start with a '-' or a '--', or when a '--' appears by itself as a parameter. A '--' must be specified alone to signal the end of options when the first command line argument starts with a '-'.

Command line arguments are what are left on the command line after all options have been processed.

This class is used as in the following example of a 'cat' facsimile in java:

Command Line Parsing

The parse() method parses option tags in a case insensitive manner. It will accept truncated option tags as long as the tag remains un-ambiguous, execpt for hidden options. The tag for hidden options must be fully specified. An option's value may be separated from its' tag by a space or an '='. A BooleanParam may be specified either without a value (in which case it is set to true), or with an '=' followed by its value. If a BooleanParam is specified more than once, the final specification takes precedence.

The following command lines are all equivalent:

 java Concat -delete -out myoutfile infile1 infile2
 java Concat -d -o myoutfile infile1 infile2
 java Concat -delete=true -o myoutfile infile1 infile2
 java Concat -d=true -o=myoutfile infile1 infile2
 java Concat -Delete -OUT myoutfile infile1 infile2
 
Any problem found while parse() processes the command line will cause a CmdLineException to be thrown.

Information on using CmdLineParsers can be found in the jcmdline User Guide.

Version:
jcmdline Rel. 2.0.0 $Id: PosixCmdLineParser.java,v 1.2 2002/12/07 14:22:06 lglawrence Exp $
Author:
Lynne Lawrence
See Also:
Parameter

Constructor Summary
PosixCmdLineParser()
          constructor
 
Method Summary
 UsageFormatter getUsageFormatter()
          Gets a usage formatter suitable for this CmdLineParser's format.
 void parse(java.lang.String[] clargs, java.util.Map<java.lang.String,Parameter<?>> opts, java.util.List<Parameter<?>> args)
          Parse the specified command line arguments.
 void setUsageFormatter(UsageFormatter usageFormatter)
          Sets a usage formatter suitable for this CmdLineParser's format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PosixCmdLineParser

public PosixCmdLineParser()
constructor

Method Detail

getUsageFormatter

public UsageFormatter getUsageFormatter()
Gets a usage formatter suitable for this CmdLineParser's format.

Specified by:
getUsageFormatter in interface CmdLineParser
Returns:
a usage formatter suitable for this CmdLineParser's format
See Also:
setUsageFormatter()

parse

public void parse(java.lang.String[] clargs,
                  java.util.Map<java.lang.String,Parameter<?>> opts,
                  java.util.List<Parameter<?>> args)
           throws CmdLineException
Parse the specified command line arguments.

This method will exit, rather than returning, if one of the following conditions is met:

Specified by:
parse in interface CmdLineParser
Parameters:
clargs - command line arguments passed to the main() method of CmdLineParser's creating class.
opts - the options this command supports
args - the arguments this command supports
Throws:
CmdLineException - in case of any parse error.

setUsageFormatter

public void setUsageFormatter(UsageFormatter usageFormatter)
Sets a usage formatter suitable for this CmdLineParser's format.

Specified by:
setUsageFormatter in interface CmdLineParser
Parameters:
usageFormatter - a usage formatter suitable for this CmdLineParser's format
See Also:
getUsageFormatter()