Package org.geotools.console
Class CommandLine
- Object
-
- CommandLine
-
public class CommandLine extends Object
Base class for command line tools. Subclasses define fields annotated withOption, while will be initialized automatically by the constructor. The following options are automatically recognized by this class:-encodingSet the input and output encoding. -helpPrint the help summary. -localeSet the locale for string, number and date formatting. - Since:
- 2.5
- Author:
- Martin Desruisseaux, Cédric Briançon
-
-
Field Summary
Fields Modifier and Type Field Description static intABORT_EXIT_CODEThe code given toSystem.exit(int)when the program aborted at user request.protected String[]argumentsThe remaining arguments after all option values have been assigned to the fields.static intBAD_CONTENT_EXIT_CODEThe code given toSystem.exit(int)when the program failed because of bad content in a file.protected PrintWritererrError stream to the console.static intILLEGAL_ARGUMENT_EXIT_CODEThe code given toSystem.exit(int)when the program failed because of an illegal user argument.static intIO_EXCEPTION_EXIT_CODEThe code given toSystem.exit(int)when the program failed because of anIOException.protected LocalelocaleThe locale inferred from the"-locale"option.protected PrintWriteroutOutput stream to the console.static intSQL_EXCEPTION_EXIT_CODEThe code given toSystem.exit(int)when the program failed because of aSQLException.
-
Constructor Summary
Constructors Modifier Constructor Description protectedCommandLine(String... args)Creates a newCommandLineinstance from the given arguments.protectedCommandLine(String[] args, int maximumRemaining)Creates a newCommandLineinstance from the given arguments.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidhelp()Prints a description of all arguments to the standard output.protected <T> Tparse(Class<T> type, String value)Parses the given string as a value of the given type.
-
-
-
Field Detail
-
ILLEGAL_ARGUMENT_EXIT_CODE
public static final int ILLEGAL_ARGUMENT_EXIT_CODE
The code given toSystem.exit(int)when the program failed because of an illegal user argument.- See Also:
- Constant Field Values
-
ABORT_EXIT_CODE
public static final int ABORT_EXIT_CODE
The code given toSystem.exit(int)when the program aborted at user request.- See Also:
- Constant Field Values
-
BAD_CONTENT_EXIT_CODE
public static final int BAD_CONTENT_EXIT_CODE
The code given toSystem.exit(int)when the program failed because of bad content in a file.- See Also:
- Constant Field Values
-
IO_EXCEPTION_EXIT_CODE
public static final int IO_EXCEPTION_EXIT_CODE
The code given toSystem.exit(int)when the program failed because of anIOException.- See Also:
- Constant Field Values
-
SQL_EXCEPTION_EXIT_CODE
public static final int SQL_EXCEPTION_EXIT_CODE
The code given toSystem.exit(int)when the program failed because of aSQLException.- See Also:
- Constant Field Values
-
out
protected final PrintWriter out
Output stream to the console. This output stream may use the encoding specified by the"-encoding"argument, if presents.
-
err
protected final PrintWriter err
Error stream to the console.
-
locale
protected final Locale locale
The locale inferred from the"-locale"option. If no such option was provided, then this field is set to the default locale.
-
arguments
protected final String[] arguments
The remaining arguments after all option values have been assigned to the fields.
-
-
Constructor Detail
-
CommandLine
protected CommandLine(String... args)
Creates a newCommandLineinstance from the given arguments. This constructor expects no additional argument after the one annoted as Option.- Parameters:
args- The command-line arguments.
-
CommandLine
protected CommandLine(String[] args, int maximumRemaining)
Creates a newCommandLineinstance from the given arguments. If this constructor fails because of a programming error (for example a type not handled byparsemethod), then an exception is thrown like usual. If this constructor fails because of some user error (e.g. if a mandatory argument is not provided) or some other external conditions (e.g. anIOException), then it prints a short error message and invokesSystem.exit(int)with one theEXIT_CODEconstants.- Parameters:
args- The command-line arguments.maximumRemaining- The maximum number of arguments that may remain after processing of annotated fields. This is the maximum length of theargumentsarray. The default value is 0.
-
-
Method Detail
-
parse
protected <T> T parse(Class<T> type, String value) throws UnsupportedOperationException
Parses the given string as a value of the given type. This method is invoked automatically for values that are not of one of the pre-defined types. The default implementation thrown an exception in all cases.- Type Parameters:
T- The field type.- Parameters:
type- The field type.value- The value given on the command line.- Returns:
- The value for the given string to parse.
- Throws:
UnsupportedOperationException- if the value can't be parsed.
-
help
protected void help()
Prints a description of all arguments to the standard output. This method is invoked automatically if the user provided the--helpargument on the command line. Subclasses can override this method in order to prints a summary before the option list.
-
-