com.martiansoftware.jsap
Class SimpleJSAP

java.lang.Object
  extended bycom.martiansoftware.jsap.JSAP
      extended bycom.martiansoftware.jsap.SimpleJSAP

public class SimpleJSAP
extends JSAP

A simple interface to JSAP that handles directly help, explanation and an array of parameters.

More precisely, instances of this class behave exactly like those of JSAP, but additionally require a command name, an explanation (a wordy description) and an array of parameters (which will be registered automatically). A switch activated by --help is always registered under the ID help.

A message will be automatically printed upon invocation of the parse() methods if an error occurs, or if the help switch is detected. In this case, messagePrinted() will return true, and the caller may check this condition to stop its actions.

The screen width used to format the help text may be set using setScreenWidth(int). The formatter will preserve newlines. Note: as of 2.0a non-breaking spaces are temporarily disabled until some console encoding issues have been worked out. - ML

Author:
Sebastiano Vigna

Field Summary
 
Fields inherited from class com.martiansoftware.jsap.JSAP
BIGDECIMAL_PARSER, BIGINTEGER_PARSER, BOOLEAN_PARSER, BYTE_PARSER, CHARACTER_PARSER, CLASS_PARSER, COLOR_PARSER, DEFAULT_LISTSEPARATOR, DEFAULT_PARAM_HELP_SEPARATOR, DEFAULT_SCREENWIDTH, DOUBLE_PARSER, FLOAT_PARSER, GREEDY, INETADDRESS_PARSER, INTEGER_PARSER, INTSIZE_PARSER, LIST, LONG_PARSER, LONGSIZE_PARSER, MULTIPLEDECLARATIONS, NO_DEFAULT, NO_HELP, NO_LONGFLAG, NO_MULTIPLEDECLARATIONS, NO_SHORTFLAG, NOT_GREEDY, NOT_LIST, NOT_REQUIRED, PACKAGE_PARSER, REQUIRED, SHORT_PARSER, STRING_PARSER, URL_PARSER
 
Constructor Summary
SimpleJSAP(String name)
          Creates a new simple JSAP with a help switch, no explanation and default screen width.
SimpleJSAP(String name, String explanation)
          Creates a new simple JSAP with default screen width.
SimpleJSAP(String name, String explanation, Parameter[] parameter)
          Creates a new simple JSAP with default screen width.
 
Method Summary
 int getScreenWidth()
          Returns the current screen width.
 boolean messagePrinted()
          Returns true if the last parsing caused the a message to be printed.
 JSAPResult parse(String arg)
          Parses the specified command line.
 JSAPResult parse(String[] arg)
          Parses the specified command line array.
 SimpleJSAP setScreenWidth(int screenWidth)
          Sets the screen width.
 
Methods inherited from class com.martiansoftware.jsap.JSAP
finalize, getByID, getByLongFlag, getByShortFlag, getByShortFlag, getHelp, getHelp, getHelp, getIDMap, getUnflaggedOptionsIterator, getUsage, registerDefaultSource, registerParameter, setHelp, setUsage, toString, unregisterDefaultSource, unregisterParameter
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleJSAP

public SimpleJSAP(String name,
                  String explanation,
                  Parameter[] parameter)
           throws JSAPException
Creates a new simple JSAP with default screen width.

Parameters:
name - the name of the command for which help will be printed.
explanation - a wordy explanation of the command, or null for no explanation.
parameter - an array of parameters, which will be registered for you, or null.

SimpleJSAP

public SimpleJSAP(String name,
                  String explanation)
           throws JSAPException
Creates a new simple JSAP with default screen width.

Parameters:
name - the name of the command for which help will be printed.
explanation - a wordy explanation of the command, or null for no explanation.

SimpleJSAP

public SimpleJSAP(String name)
           throws JSAPException
Creates a new simple JSAP with a help switch, no explanation and default screen width.

Parameters:
name - the name of the command for which help will be printed.
Method Detail

parse

public JSAPResult parse(String arg)
Description copied from class: JSAP
Parses the specified command line. The specified command line is first parsed into an array, much like the operating system does for the JVM prior to calling your application's main class' main() method. If no Exception is thrown, the entire command line has been parsed successfully, and its results have been successfully instantiated.

Overrides:
parse in class JSAP
Parameters:
arg - An array of command line arguments to parse. This array is typically provided in the application's main class' main() method.
Returns:
a JSAPResult containing the resulting Objects.

parse

public JSAPResult parse(String[] arg)
Description copied from class: JSAP
Parses the specified command line array. If no Exception is thrown, the entire command line has been parsed successfully, and its results have been successfully instantiated.

Overrides:
parse in class JSAP
Parameters:
arg - An array of command line arguments to parse. This array is typically provided in the application's main class' main() method.
Returns:
a JSAPResult containing the resulting Objects.

getScreenWidth

public int getScreenWidth()
Returns the current screen width.

This value will be passed to JSAP.getHelp(int), and used to format the explanation.

Returns:
the current screen width.

setScreenWidth

public SimpleJSAP setScreenWidth(int screenWidth)
Sets the screen width.

Parameters:
screenWidth - the new screen width.
Returns:
this simple JSAP.

messagePrinted

public boolean messagePrinted()
Returns true if the last parsing caused the a message to be printed.

Returns:
true if the last parsing caused a message to be printed.


Copyright © 2002-2006, Martian Software, Inc.. All Rights Reserved.
For the latest version and documentation, please visit http://www.martiansoftware.com/jsap