org.tentackle.util
Class CommandLine

java.lang.Object
  extended by org.tentackle.util.CommandLine

public class CommandLine
extends Object

Command line arguments and options.

Scans an array of argument strings and parses options. Options start with two dashes, for example --enabled and can have a value like --timeout=30. All other strings are considered as standard args.

Author:
harald

Constructor Summary
CommandLine()
          Creates an empty command line.
CommandLine(String[] args)
          Creates a command line from console args.
 
Method Summary
 List<String> getArguments()
          Gets the list of non-option arguments
 Map<String,String> getOptions()
          Gets the options.
 Properties getOptionsAsProperties()
          Gets the options as properties.
 String getOptionValue(String option)
          Gets the value for an option "--opt=...".
 boolean isOptionSet(String option)
          Checks if an option has been set or not.
 void setArgs(String[] args)
          Sets the arguments.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandLine

public CommandLine(String[] args)
Creates a command line from console args.

Parameters:
args - the command line args (usually from main-method)

CommandLine

public CommandLine()
Creates an empty command line.

Method Detail

setArgs

public void setArgs(String[] args)
Sets the arguments.

Parameters:
args - the arguments (usually from commandline)

isOptionSet

public boolean isOptionSet(String option)
Checks if an option has been set or not.

Parameters:
option - the option name (without the leading --)
Returns:
true if option set

getOptionValue

public String getOptionValue(String option)
Gets the value for an option "--opt=...".

Parameters:
option - the option name
Returns:
the value or null if no such option or not a value option

getArguments

public List<String> getArguments()
Gets the list of non-option arguments

Returns:
the arguments. never null

getOptions

public Map<String,String> getOptions()
Gets the options.

Returns:
the options map, never null

getOptionsAsProperties

public Properties getOptionsAsProperties()
Gets the options as properties.

Returns:
the options, never null


Copyright © 2001-2008 Harald Krake, Bergstr. 48, 78098 Triberg, Germany, harald@krake.de