org.globus.gridshib.common.cli
Class BaseCLI

java.lang.Object
  extended by org.globus.gridshib.common.cli.BaseCLI
All Implemented Interfaces:
BaseLogging, Testable

public abstract class BaseCLI
extends Object
implements BaseLogging, Testable

A basic command-line interface with common options used by all GridShib tools and clients. This abstract class should be extended by a concrete CLI implementation that may add command-line options of its own.

The subclass must fulfill the following contract:

After all the options have been added, the subclass must call the parse() method of this class. The validate() method should be overridden so that any newly added options are validated as well.

Note: Some members of this class go all the way back to GridShib SAML Tools v0.1.0. See the User Guide for details.

Since:
0.5.0
See Also:
BaseLogging, Testable

Field Summary
protected static org.apache.commons.cli.Option DEBUG
          The --debug option.
protected static org.apache.commons.cli.Option HELP
          The --help option.
protected static org.apache.commons.cli.Option INPUT
          The --infile option.
protected static String INPUT_DESCRIPTION
          Description of the --infile option.
protected static org.apache.commons.cli.Option OUTPUT
          The --outfile option.
protected static String OUTPUT_DESCRIPTION
          Description of the --outfile option.
protected static org.apache.commons.cli.Option QUIET
          The --quiet option.
 
Fields inherited from interface org.globus.gridshib.common.cli.Testable
APPLICATION_ERROR, COMMAND_LINE_ERROR, CONFIG_FILE_ERROR, SECURITY_ERROR, SUCCESS_CODE
 
Constructor Summary
protected BaseCLI(String[] args)
          A subclass MUST invoke this constructor.
 
Method Summary
protected abstract  void displayUsage()
          A concrete subclass MUST implement this method.
 String[] getArgs()
          Gets the command-line arguments used to invoke the application.
 org.apache.commons.cli.CommandLine getCommandLine()
           
 int getExitCode()
          If this method is called before calling the setExitCode(int) method, this method returns Testable.SECURITY_ERROR.
 int getExitCode(boolean forceRun)
          This method is equivalent to
protected  File getInfile()
          Deprecated. as of 0.5.0, use getInputPath() instead
protected  String getInputPath()
           
protected  org.apache.commons.cli.Options getOptions()
           
protected  File getOutfile()
          Deprecated. as of 0.5.0, use getOutputPath() instead
protected  String getOutputPath()
           
protected  boolean isDebug()
           
protected  void parse()
          A subclass MUST call this method.
abstract  void run()
          Execute the command-line application.
 void setExitCode(int exitCode)
          Sets the exit code of the application.
protected  void validate()
          If a subclass adds its own command-line options, this method will most likely be overridden.
protected  boolean wantQuiet()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.globus.gridshib.common.BaseLogging
configureLogger, getLogConfigPath, setDebugLogLevel
 

Field Detail

INPUT_DESCRIPTION

protected static String INPUT_DESCRIPTION
Description of the --infile option.


OUTPUT_DESCRIPTION

protected static String OUTPUT_DESCRIPTION
Description of the --outfile option.


INPUT

protected static org.apache.commons.cli.Option INPUT
The --infile option.

This option was introduced in GS-ST v0.3.0.


OUTPUT

protected static org.apache.commons.cli.Option OUTPUT
The --outfile option.

This option was introduced in GS-ST v0.1.0.


DEBUG

protected static org.apache.commons.cli.Option DEBUG
The --debug option.

This option was introduced in GS-ST v0.1.0.


QUIET

protected static org.apache.commons.cli.Option QUIET
The --quiet option.

This option was introduced in GS-ST v0.1.0.


HELP

protected static org.apache.commons.cli.Option HELP
The --help option.

This option was introduced in GS-ST v0.1.0.

Constructor Detail

BaseCLI

protected BaseCLI(String[] args)
A subclass MUST invoke this constructor.

Parameters:
args - an array of command-line arguments
Method Detail

getInputPath

protected String getInputPath()

getOutputPath

protected String getOutputPath()

isDebug

protected boolean isDebug()

wantQuiet

protected boolean wantQuiet()

getInfile

protected File getInfile()
Deprecated. as of 0.5.0, use getInputPath() instead


getOutfile

protected File getOutfile()
Deprecated. as of 0.5.0, use getOutputPath() instead


getOptions

protected org.apache.commons.cli.Options getOptions()

getCommandLine

public org.apache.commons.cli.CommandLine getCommandLine()

getArgs

public String[] getArgs()
Description copied from interface: Testable
Gets the command-line arguments used to invoke the application.

Specified by:
getArgs in interface Testable
Returns:
an array of command-line arguments

run

public abstract void run()
                  throws ApplicationRuntimeException
Description copied from interface: Testable
Execute the command-line application. This method MUST call Testable.setExitCode(int) but MUST NOT call System.exit(int).

Specified by:
run in interface Testable
Throws:
ApplicationRuntimeException - if execution of the application fails

getExitCode

public int getExitCode()
If this method is called before calling the setExitCode(int) method, this method returns Testable.SECURITY_ERROR. This helps prevent unintended exit codes.

Specified by:
getExitCode in interface Testable
Returns:
the exit code

getExitCode

public int getExitCode(boolean forceRun)
This method is equivalent to
this.run();
 int exitCode = this.getExitCode();
If the run() method throws an exception, this method logs an error message and returns the exit code. For this reason, this method is mainly useful in unit tests.

Specified by:
getExitCode in interface Testable
Returns:
the exit code

setExitCode

public void setExitCode(int exitCode)
Description copied from interface: Testable
Sets the exit code of the application.

Specified by:
setExitCode in interface Testable
Parameters:
exitCode - the exit code

parse

protected final void parse()
                    throws Exception
A subclass MUST call this method.

Throws:
Exception - If command-line parsing fails

validate

protected void validate()
                 throws Exception
If a subclass adds its own command-line options, this method will most likely be overridden.

Throws:
Exception - If validation fails

displayUsage

protected abstract void displayUsage()
A concrete subclass MUST implement this method.



Copyright © 2007-2008 University of Illinois. All Rights Reserved.