org.stanwood.media.cli
Class BaseLauncher

java.lang.Object
  extended by org.stanwood.media.cli.BaseLauncher
All Implemented Interfaces:
ICLICommand
Direct Known Subclasses:
AbstractLauncher, AbstractSubCLICommand

public abstract class BaseLauncher
extends java.lang.Object
implements ICLICommand

This is the base class of all CLI command launchers


Constructor Summary
BaseLauncher(java.lang.String name, java.io.PrintStream stdout, java.io.PrintStream stderr, IExitHandler exitHandler)
          The constructor
 
Method Summary
protected  void addOption(org.apache.commons.cli.Option o)
           
protected  java.lang.String checkSubCommand(java.lang.String string)
           
 void displayHelp(org.apache.commons.cli.Options options, java.io.PrintStream stdout, java.io.PrintStream stderr)
          Called to display the commands help
 void doExit(int code)
          This will exit the application
protected  void fatal(java.lang.Exception e)
           
protected  void fatal(java.lang.String msg)
          Called to issue a fatal message and exit
 java.lang.String getName()
          Used to get the command name
 org.apache.commons.cli.Options getOptions()
          Used to get the options of the command
protected  java.io.PrintStream getStderr()
           
protected  java.io.PrintStream getStdout()
           
protected  void handleBadSubCommandOption(org.apache.commons.cli.Options options, java.lang.String arg)
           
protected  void info(java.lang.String msg)
          Called to issue a info message
 void init(Controller controller)
          Called to setup stuff that depends on the controller
 void launch(java.lang.String[] args)
          This should be called from the main method to launch the tool.
protected  void printOptions(org.apache.commons.cli.Options options, java.io.PrintStream stdout, java.io.PrintStream stderr)
           
protected  void printUsage(org.apache.commons.cli.Options options, java.io.PrintStream stdout, java.io.PrintStream stderr)
           
protected abstract  boolean processOptionsInternal(java.lang.String[] args, org.apache.commons.cli.CommandLine cmd)
           
protected abstract  boolean run()
          This is executed to make the tool perform its function and should be extended.
protected  boolean shouldDisplayHelp(java.lang.String[] args, org.apache.commons.cli.CommandLine cmd, java.lang.String subCommand)
           
protected  void warn(java.lang.String msg)
          Called to issue a warning message
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseLauncher

public BaseLauncher(java.lang.String name,
                    java.io.PrintStream stdout,
                    java.io.PrintStream stderr,
                    IExitHandler exitHandler)
The constructor

Parameters:
name - The name of the command
stdout - The standard output stream
stderr - The standard error stream
exitHandler - The exit handler
Method Detail

init

public void init(Controller controller)
Called to setup stuff that depends on the controller

Parameters:
controller - The controller

getOptions

public org.apache.commons.cli.Options getOptions()
Used to get the options of the command

Returns:
The options

addOption

protected void addOption(org.apache.commons.cli.Option o)

launch

public void launch(java.lang.String[] args)
This should be called from the main method to launch the tool.

Parameters:
args - The args passed from the CLI

handleBadSubCommandOption

protected void handleBadSubCommandOption(org.apache.commons.cli.Options options,
                                         java.lang.String arg)

shouldDisplayHelp

protected boolean shouldDisplayHelp(java.lang.String[] args,
                                    org.apache.commons.cli.CommandLine cmd,
                                    java.lang.String subCommand)

checkSubCommand

protected java.lang.String checkSubCommand(java.lang.String string)

doExit

public void doExit(int code)
This will exit the application

Parameters:
code - The exit code

warn

protected void warn(java.lang.String msg)
Called to issue a warning message

Parameters:
msg - The message

fatal

protected void fatal(java.lang.String msg)
Called to issue a fatal message and exit

Parameters:
msg - The message

fatal

protected void fatal(java.lang.Exception e)

info

protected void info(java.lang.String msg)
Called to issue a info message

Parameters:
msg - The message

getName

public java.lang.String getName()
Used to get the command name

Specified by:
getName in interface ICLICommand
Returns:
the command name

displayHelp

public void displayHelp(org.apache.commons.cli.Options options,
                        java.io.PrintStream stdout,
                        java.io.PrintStream stderr)
Called to display the commands help

Parameters:
options - The commands options
stdout - The standard output stream
stderr - The standard error stream

printUsage

protected void printUsage(org.apache.commons.cli.Options options,
                          java.io.PrintStream stdout,
                          java.io.PrintStream stderr)

printOptions

protected void printOptions(org.apache.commons.cli.Options options,
                            java.io.PrintStream stdout,
                            java.io.PrintStream stderr)

processOptionsInternal

protected abstract boolean processOptionsInternal(java.lang.String[] args,
                                                  org.apache.commons.cli.CommandLine cmd)

run

protected abstract boolean run()
This is executed to make the tool perform its function and should be extended.

Returns:
True if executed without problems, otherwise false

getStdout

protected java.io.PrintStream getStdout()

getStderr

protected java.io.PrintStream getStderr()