ds.ov2.util
Class Parse_commandline

java.lang.Object
  extended by ds.ov2.util.Parse_commandline

public class Parse_commandline
extends Object

Command line parsing. Invoke the options found on the command line and print a usage information and exit the program if one of the options -h, -help or --help was found or if one of the options was used incorrectly.

CPP Preprocessing
no cpp preprocessing needed
Execution Environment:
host
Author:
Hendrik Tews
Version:
$Revision: 1.1 $
Last Commit:
$Date: 2009-06-02 09:56:03 $ by $Author: tews $

Field Summary
private  String application_name
          Short application name for the usage.
private  Option[] options
          The options array.
 
Constructor Summary
Parse_commandline(Option[] options, String application_name)
          Construct an instance for parsing the command line.
 
Method Summary
 void format_option_description()
          Format option descriptions for the usage message to System.out.
private  String left_side(Option o)
          Return the option and argument string.
 void parse(String[] args)
          Parse a complete command line.
private  void usage()
          Print the usage message to System.out.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

options

private final Option[] options
The options array.


application_name

private final String application_name
Short application name for the usage.

Constructor Detail

Parse_commandline

public Parse_commandline(Option[] options,
                         String application_name)
Construct an instance for parsing the command line.

Parameters:
options - the options to parse
application_name - for the usage message
Method Detail

left_side

private String left_side(Option o)
Return the option and argument string. This is a small helper method for format_option_description().

Parameters:
o - option
Returns:
the option string concatenated with the argument, as needed for format_option_description()

format_option_description

public void format_option_description()
Format option descriptions for the usage message to System.out.


usage

private void usage()
Print the usage message to System.out. Prints one line of explanation for each option, similar to
    -h      print help
    -i n    int argument n
 
The explanations on the right hand side are nicely lined up.


parse

public void parse(String[] args)
Parse a complete command line. Constructs a Commandline instance from the arguments args, matches against the options and calls their Option.matched method as appropriate.

If one of -h, -help, --help or an unknow option is found or if one of the options is used inappropriately, a usage information is printed and the program is exited.

Parameters:
args - the command line arguments as received in main