org.sadun.util
Class BaseCommand

java.lang.Object
  extended byorg.sadun.util.BaseCommand

public abstract class BaseCommand
extends java.lang.Object

A base class for command-line based tools using CmdLineOptions.

Author:
Cristiano Sadun

Field Summary
protected  CmdLineOptions co
          The CmdLineOptions object, initialized at construction.
 
Constructor Summary
protected BaseCommand()
          Create an instance with the no tool description.
protected BaseCommand(java.lang.String commandDescription)
          Create an instance with the given tool description.
 
Method Summary
 boolean isHelpRequested()
          Return whether or not the user has specified the help option
protected  void main0(java.lang.String[] args)
          Can be invoked from the subclass static main(String args[]) method to automatically handle user errors.
protected  void postParse()
          This method is invoked by main0(String[]) after the options are parsed, but before the command is run.
protected  void preParse()
          Invoked after construction, but before parsing.
protected abstract  void run()
          This method must be overriden by subclasses to implement the command functionality.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

co

protected CmdLineOptions co
The CmdLineOptions object, initialized at construction.

Constructor Detail

BaseCommand

protected BaseCommand(java.lang.String commandDescription)
Create an instance with the given tool description.

The co member is created and initialized with an help option -help with aliases h and ?. Subclasses will add other options to the co member.

Parameters:
commandDescription - a textual description of the tool

BaseCommand

protected BaseCommand()
Create an instance with the no tool description.

The co member is created and initialized with an help option -help with aliases h and ?. Subclasses will add other options to the co member.

Method Detail

isHelpRequested

public boolean isHelpRequested()
Return whether or not the user has specified the help option

Returns:
whether or not the user has specified the help option

main0

protected void main0(java.lang.String[] args)
Can be invoked from the subclass static main(String args[]) method to automatically handle user errors.

A typical subclass Tool will contain a main() method like

  public static void main(String [] args) {
    new Tool().main0(args);
  }
  

Parameters:
args - the command line arguments

run

protected abstract void run()
This method must be overriden by subclasses to implement the command functionality.


preParse

protected void preParse()
Invoked after construction, but before parsing.


postParse

protected void postParse()
This method is invoked by main0(String[]) after the options are parsed, but before the command is run.

This implementation does nothing.



Copyright © 1999-2004 Cristiano Sadun. This software is released under GPL.