edu.mssm.crover.cli
Class CLI

java.lang.Object
  |
  +--edu.mssm.crover.cli.CLI

public class CLI
extends java.lang.Object

Provides general services needed by Command Line Interface programs. These services include: configuration of the environment through a property file, methods to parse options from the command line.

Author:
F. Campagne

Field Summary
static boolean DEBUG
           
 
Method Summary
 boolean fileExists(java.lang.String filename)
           
static double getDoubleOption(java.lang.String[] args, java.lang.String keyword, double default_value)
          Extracts a double parameter from the command line arguments.
static float getFloatOption(java.lang.String[] args, java.lang.String keyword, float default_value)
          Extracts a float parameter from the command line arguments.
static CLI getInstance()
          Returns the singleton instance of CLI.
 java.lang.String getInstanceProperty(java.lang.String propertyName)
          Returns the value of a property.
static int getIntOption(java.lang.String[] args, java.lang.String keyword, int default_value)
          Extracts an integer parameter from the command line arguments.
static long getLongOption(java.lang.String[] args, java.lang.String keyword, long default_value)
          Extracts a long parameter from the command line arguments.
static java.lang.String getOption(java.lang.String[] args, java.lang.String option_keywork, java.lang.String default_value)
          Extracts an option parameter from the command line arguments.
static java.lang.String[] getOptions(java.lang.String[] args, java.lang.String keyword)
          Returns an array of all the options given for a given keyword.
static java.lang.String[] getOptions(java.lang.String[] args, java.lang.String keyword, java.lang.String[] default_value)
          Returns an array of all the options given for a given keyword.
static java.lang.String[] getOrderedOptions(java.lang.String[] args, java.lang.String keyword)
          Returns an array of all the options given for a given keyword in the order the are given on the command line.
static java.lang.String getProperty(java.lang.String propertyName)
          Returns the value of a property.
static java.lang.String getProperty(java.lang.String propertyName, java.lang.String default_value)
          Returns the value of a property.
static java.lang.String[] getTwoPartOptions(java.lang.String[] args, java.lang.String keyword)
          Returns an array of all the options given for a given keyword.
static boolean isKeywordGiven(java.lang.String[] args, java.lang.String option_keyword)
          Extracts a boolean keyword from the command line arguments.
static boolean isKeywordGiven(java.lang.String[] args, java.lang.String option_keyword, boolean default_value)
          Extracts a boolean keyword from the command line arguments.
 void loadProperties()
           
static void main(java.lang.String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static boolean DEBUG
Method Detail

getInstance

public static CLI getInstance()
Returns the singleton instance of CLI. Properties are read now. The location of the file from were to load them is one of these, whichever comes first: - given by the system property "edu.mssm.crover.properties" - in the home directory of the user, and named crover.prp - in the current working directory of the user, and named crover.prp


loadProperties

public void loadProperties()

fileExists

public boolean fileExists(java.lang.String filename)

getInstanceProperty

public final java.lang.String getInstanceProperty(java.lang.String propertyName)
Returns the value of a property. The system properties are searched first. If the property is found, its value is returned, otherwise the crover properties are searched.


getProperty

public static java.lang.String getProperty(java.lang.String propertyName)
Returns the value of a property. This method can be called without an explicit instance.


getProperty

public static java.lang.String getProperty(java.lang.String propertyName,
                                           java.lang.String default_value)
Returns the value of a property. This method can be called without an explicit instance.

Returns:
The property value, or the default value when the former is null.

getOption

public static java.lang.String getOption(java.lang.String[] args,
                                         java.lang.String option_keywork,
                                         java.lang.String default_value)
Extracts an option parameter from the command line arguments. For boolean attributes, see isKeywordGiven.


isKeywordGiven

public static boolean isKeywordGiven(java.lang.String[] args,
                                     java.lang.String option_keyword,
                                     boolean default_value)
Extracts a boolean keyword from the command line arguments.

Returns:
true if a keyword (also called flag) is given on the command line. Flase otherwise.

isKeywordGiven

public static boolean isKeywordGiven(java.lang.String[] args,
                                     java.lang.String option_keyword)
Extracts a boolean keyword from the command line arguments. Assumes false default values.


getLongOption

public static long getLongOption(java.lang.String[] args,
                                 java.lang.String keyword,
                                 long default_value)
Extracts a long parameter from the command line arguments.


getIntOption

public static int getIntOption(java.lang.String[] args,
                               java.lang.String keyword,
                               int default_value)
Extracts an integer parameter from the command line arguments.


getDoubleOption

public static double getDoubleOption(java.lang.String[] args,
                                     java.lang.String keyword,
                                     double default_value)
Extracts a double parameter from the command line arguments.


getFloatOption

public static float getFloatOption(java.lang.String[] args,
                                   java.lang.String keyword,
                                   float default_value)
Extracts a float parameter from the command line arguments.


getOptions

public static java.lang.String[] getOptions(java.lang.String[] args,
                                            java.lang.String keyword)
Returns an array of all the options given for a given keyword.


getOrderedOptions

public static java.lang.String[] getOrderedOptions(java.lang.String[] args,
                                                   java.lang.String keyword)
Returns an array of all the options given for a given keyword in the order the are given on the command line.


getTwoPartOptions

public static java.lang.String[] getTwoPartOptions(java.lang.String[] args,
                                                   java.lang.String keyword)
                                            throws WrongArgumentTypeException
Returns an array of all the options given for a given keyword. Options are defined by being two words long.

WrongArgumentTypeException

getOptions

public static java.lang.String[] getOptions(java.lang.String[] args,
                                            java.lang.String keyword,
                                            java.lang.String[] default_value)
Returns an array of all the options given for a given keyword. Returns null if no keyword found.


main

public static void main(java.lang.String[] args)


Copyright @ 2003 Mount Sinai School of Medicine. All Rights Reserved.