org.stanwood.media.cli
Class AbstractLauncher

java.lang.Object
  extended by org.stanwood.media.cli.BaseLauncher
      extended by org.stanwood.media.cli.AbstractLauncher
All Implemented Interfaces:
ICLICommand
Direct Known Subclasses:
CLICopyStoreToStore, CLICopyToMediaDir, CLIFixSeenDB, CLIImportMedia, CLIManageAddons, CLIMediaFileInformation, CLIMediaManager

public abstract class AbstractLauncher
extends BaseLauncher
implements ICLICommand

This class should be extended by classes that have a main method used to lauch them from the command line. It helps with adding command line parameters and add some default CLI options.


Constructor Summary
AbstractLauncher(java.lang.String name, java.util.List<org.apache.commons.cli.Option> options, IExitHandler exitHandler, java.io.PrintStream stdout, java.io.PrintStream stderr)
          Create a instance of the class
 
Method Summary
 Controller getController()
          Used to get the controller
protected  long parseLongOption(java.lang.String optionValue)
          Called to parse a java.util.Long option fropm the command line
protected abstract  boolean processOptions(java.lang.String[] args, org.apache.commons.cli.CommandLine cmd)
          This is called to validate the tools CLI options.
protected  boolean processOptionsInternal(java.lang.String[] args, org.apache.commons.cli.CommandLine cmd)
           
static void setConfig(ConfigReader configReader)
          Used by tests to set the config reader
 
Methods inherited from class org.stanwood.media.cli.BaseLauncher
addOption, checkSubCommand, displayHelp, doExit, fatal, fatal, getName, getOptions, getStderr, getStdout, handleBadSubCommandOption, info, init, launch, printOptions, printUsage, run, shouldDisplayHelp, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.stanwood.media.cli.ICLICommand
getName
 

Constructor Detail

AbstractLauncher

public AbstractLauncher(java.lang.String name,
                        java.util.List<org.apache.commons.cli.Option> options,
                        IExitHandler exitHandler,
                        java.io.PrintStream stdout,
                        java.io.PrintStream stderr)
Create a instance of the class

Parameters:
name - The name of the executable
options - The options that are to be added to the CLI
stdout - The standard output stream
stderr - The standard error stream
exitHandler - The exit handler
Method Detail

processOptions

protected abstract boolean processOptions(java.lang.String[] args,
                                          org.apache.commons.cli.CommandLine cmd)
This is called to validate the tools CLI options. When this is called, the default options added by AbstractLauncher will already have been validated sucesfully.

Parameters:
cmd - The command line options
Returns:
True, if the command line options verified successfully, otherwise false

processOptionsInternal

protected boolean processOptionsInternal(java.lang.String[] args,
                                         org.apache.commons.cli.CommandLine cmd)
Specified by:
processOptionsInternal in class BaseLauncher

getController

public Controller getController()
Used to get the controller

Returns:
the controller

parseLongOption

protected long parseLongOption(java.lang.String optionValue)
                        throws org.apache.commons.cli.ParseException
Called to parse a java.util.Long option fropm the command line

Parameters:
optionValue - The command line parameter value
Returns:
The long
Throws:
org.apache.commons.cli.ParseException - Thrown if it could not be parsed correctly

setConfig

public static void setConfig(ConfigReader configReader)
Used by tests to set the config reader

Parameters:
configReader - the config reader