org.apache.muse.util
Class CommandLine

java.lang.Object
  extended by org.apache.muse.util.CommandLine

public class CommandLine
extends Object

CommandLine is a representation of the command line arguments passed to a Java class' main(String[]) method. It parses the arguments for flags (tokens prefixed with a dash ('-')), flag-value pairs, and an ordered list of argument values.

Author:
Dan Jemiolo (danj)

Constructor Summary
CommandLine()
           
 
Method Summary
 String[] getArguments()
           
 String getFlagValue(String flagName)
           
 int getNumberOfArguments()
           
 int getNumberOfFlags()
           
 boolean hasFlag(String flagName)
           
 void parse(String[] args)
          Reads through each argument in the given array, picking out the flags (and optionally,their values) from the regular arguments.
 void saveFlagValue(String flagName)
          Tells the command line parser to associate the given flag with the value that comes after it in the list of arguments (if the flag is found).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandLine

public CommandLine()
Method Detail

getArguments

public String[] getArguments()
Returns:
All of the values specified on the command line that were not a flag or associated with a flag.

getFlagValue

public String getFlagValue(String flagName)
Parameters:
flagName -
Returns:
The value that was specified after the flag, or null if the flag was not specified.
See Also:
hasFlag(String)

getNumberOfArguments

public int getNumberOfArguments()

getNumberOfFlags

public int getNumberOfFlags()

hasFlag

public boolean hasFlag(String flagName)
Parameters:
flagName -
Returns:
True if the flag was specified on the command line.

parse

public void parse(String[] args)
Reads through each argument in the given array, picking out the flags (and optionally,their values) from the regular arguments. Users should use the saveFlagValue(String) method before this one in order to have their command line parsed correctly.

Parameters:
args - The command line arguments given to the application.

saveFlagValue

public void saveFlagValue(String flagName)
Tells the command line parser to associate the given flag with the value that comes after it in the list of arguments (if the flag is found). This will allow the user to retrieve the flag-value pair later and prevent the flag value from being lumped in with the regular arguments.

Parameters:
flagName -


Copyright © 2005-2011 Apache Web Services - Muse. All Rights Reserved.