org.deegree.commons.tools
Class CommandUtils

java.lang.Object
  extended by org.deegree.commons.tools.CommandUtils

public class CommandUtils
extends Object

This class contains some static convenience methods for commandline tools.

Version:
$Revision: 28843 $, $Date: 2010-12-16 16:22:59 +0100 (Thu, 16 Dec 2010) $
Author:
Oliver Tonnhofer, last edited by: $Author: aschmitz $

Field Summary
static int HELP_TEXT_WIDTH
          The width of the help text, for automatic text wrap.
static String OPT_VERBOSE
           
 
Constructor Summary
CommandUtils()
           
 
Method Summary
static void addDefaultOptions(org.apache.commons.cli.Options options)
           
static float getFloatOption(org.apache.commons.cli.CommandLine line, String optName, float defaultValue)
          Parse a command line argument as float.
static int getIntOption(org.apache.commons.cli.CommandLine line, String optName, int defaultValue)
          Parse a command line argument as integer.
static void printHelp(org.apache.commons.cli.Options options, String toolName, String helpMsg, String otherUsageInfo)
          Prints a help message for a apache commons-cli based command line tool and terminates the programm.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HELP_TEXT_WIDTH

public static int HELP_TEXT_WIDTH
The width of the help text, for automatic text wrap.


OPT_VERBOSE

public static final String OPT_VERBOSE
See Also:
Constant Field Values
Constructor Detail

CommandUtils

public CommandUtils()
Method Detail

printHelp

public static void printHelp(org.apache.commons.cli.Options options,
                             String toolName,
                             String helpMsg,
                             String otherUsageInfo)
Prints a help message for a apache commons-cli based command line tool and terminates the programm.

Parameters:
options - the options to generate help/usage information for
toolName - the name of the command line tool
helpMsg - some further information
otherUsageInfo - an optional string to append to the usage information (e.g. for additional arguments like input files)

getIntOption

public static int getIntOption(org.apache.commons.cli.CommandLine line,
                               String optName,
                               int defaultValue)
                        throws org.apache.commons.cli.ParseException
Parse a command line argument as integer.

Parameters:
line - the parsed command line
optName - the option name
defaultValue - the default value
Returns:
the parsed integer argument or defaulValue, if the argument is missing
Throws:
org.apache.commons.cli.ParseException - if the argument is not a number

getFloatOption

public static float getFloatOption(org.apache.commons.cli.CommandLine line,
                                   String optName,
                                   float defaultValue)
                            throws org.apache.commons.cli.ParseException
Parse a command line argument as float.

Parameters:
line - the parsed command line
optName - the option name
defaultValue - the default value
Returns:
the parsed float argument or defaulValue, if the argument is missing
Throws:
org.apache.commons.cli.ParseException - if the argument is not a number

addDefaultOptions

public static void addDefaultOptions(org.apache.commons.cli.Options options)
Parameters:
options -


Copyright © 2011. All Rights Reserved.