com.dtolabs.rundeck.core.cli
Class BaseTool

java.lang.Object
  extended by com.dtolabs.rundeck.core.cli.BaseTool
All Implemented Interfaces:
CLITool, CLIToolLogger, BaseLogger
Direct Known Subclasses:
JobsTool, QueueTool, RunTool

public abstract class BaseTool
extends java.lang.Object
implements CLITool

BaseTool provides a base lifecyle for a commandline tool, and allows CLIToolOptions objects to be used for modular options processing.


Constructor Summary
protected BaseTool()
           
 
Method Summary
protected  void addToolOptions(CLIToolOptions option)
          Add a new CLIToolOptions object to the options used by this tool.
 void exit(int exitcode)
          Calls the exit method
protected  org.apache.commons.cli.CommandLine getCommandLine()
           
abstract  java.lang.String getHelpString()
          Return the help string used when -h option is specified.
protected  org.apache.commons.cli.Options getOptions()
           
protected abstract  void go()
          Perform the actions for the tool
 void help()
          Writes help message .
protected  void initOptions()
          initialize any options, will apply this for each CLIToolOptions added to the tool.
protected abstract  boolean isUseHelpOption()
          Return true if the -h/--help option should be added to the options automatically.
 org.apache.commons.cli.CommandLine parseArgs(java.lang.String[] args)
          Parse the options, will apply this for each CLIToolOptions added to the tool.
 void run(java.lang.String[] args)
          Run the tool's lifecycle given the input arguments.
protected  void setShouldExit(boolean shouldExit)
          Set whether the exit(int) method should call System.exit.
 void validateOptions(org.apache.commons.cli.CommandLine cli, java.lang.String[] args)
          Validate the values parsed by the options, will apply this for each CLIToolOptions added to the tool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.dtolabs.rundeck.core.execution.BaseLogger
debug, error, log, verbose, warn
 

Constructor Detail

BaseTool

protected BaseTool()
Method Detail

addToolOptions

protected void addToolOptions(CLIToolOptions option)
Add a new CLIToolOptions object to the options used by this tool.

Parameters:
option -

isUseHelpOption

protected abstract boolean isUseHelpOption()
Return true if the -h/--help option should be added to the options automatically.

Returns:

initOptions

protected void initOptions()
initialize any options, will apply this for each CLIToolOptions added to the tool. subclasses may override this but should call super


getOptions

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

run

public void run(java.lang.String[] args)
         throws CLIToolException
Run the tool's lifecycle given the input arguments.

Specified by:
run in interface CLITool
Parameters:
args - the cli arg vector
Throws:
CLIToolException

parseArgs

public org.apache.commons.cli.CommandLine parseArgs(java.lang.String[] args)
                                             throws CLIToolOptionsException
Parse the options, will apply this for each CLIToolOptions added to the tool. subclasses may override this but should call super

Specified by:
parseArgs in interface CLITool
Parameters:
args - the cli arg vector
Returns:
a new instance of CommandLine
Throws:
CLIToolOptionsException

validateOptions

public void validateOptions(org.apache.commons.cli.CommandLine cli,
                            java.lang.String[] args)
                     throws CLIToolOptionsException
Validate the values parsed by the options, will apply this for each CLIToolOptions added to the tool. subclasses may override this but should call super

Throws:
CLIToolOptionsException

go

protected abstract void go()
                    throws CLIToolException
Perform the actions for the tool

Throws:
CLIToolException

getCommandLine

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

getHelpString

public abstract java.lang.String getHelpString()
Return the help string used when -h option is specified.

Returns:

help

public void help()
Writes help message .

Specified by:
help in interface CLITool

exit

public void exit(int exitcode)
Calls the exit method

Specified by:
exit in interface CLITool
Parameters:
exitcode - return code to exit with

setShouldExit

protected void setShouldExit(boolean shouldExit)
Set whether the exit(int) method should call System.exit.

Parameters:
shouldExit -