Class SimpleJSAP
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
ConstructorsConstructorDescriptionSimpleJSAP
(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
Modifier and TypeMethodDescriptionint
Returns the current screen width.boolean
Returns true if the last parsing caused the a message to be printed.Parses the specified command line.Parses the specified command line array.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
-
Constructor Details
-
SimpleJSAP
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, ornull
for no explanation.parameter
- an array of parameters, which will be registered for you, ornull
.- Throws:
JSAPException
-
SimpleJSAP
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, ornull
for no explanation.- Throws:
JSAPException
-
SimpleJSAP
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.- Throws:
JSAPException
-
-
Method Details
-
parse
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. -
parse
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. -
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
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.
-