org.metasyntactic.utilities
Class CommandLineArguments

java.lang.Object
  |
  +--org.metasyntactic.utilities.CommandLineArguments

public class CommandLineArguments
extends java.lang.Object

CommandLineArguments is a class that is attached to a program you have created. You fisrt instantiate the class and continue by adding Arguments to it. After doing this pass the array or arguments the user used to the method processArguments(String[]). The args will be tested to make sure that they comply with the Arguments you added to the this. If the user used improper args then the program will abort and will print a message eplaining proper usage and what the user did wrong (this message can be overridden if you choose).

Rules that are supported:
  1. Non-switch options must follow immediately after the programname! Otherwise it will be assumed that they belong to a following switch. The reason was this. Take this example:
    	   programname -f file1 file2 file3 file4
    	   programname -f file1 file2 program_option1 program_option2
    	
    In the above how do you determine that option1 and option2 aren't actually options of -f? There is simply no intelligent way to determine. However if you use my logic:
    	   programname -f file1 file2 file3 file4
    	   programname program_option1 program_option2 -f file1 file2
    	
    Then it is easy to determine what to do in the following cases. In the first case all four options belong to -f. In the second the first two options belong to the program, the second two options belong to -f. As far as I can tell this behaviour means that there is never any confusion about how to handle Arguments.
  2. A switch is a single character following a dash → - OR a name following a dash_dash → --
    If it's a dash then following args are seperated by spaces If it's a name then the name is followed by an equals sign and following options are seperated by commas. The following are equivalent:
    		   -p c:\ d:\ e:\ ↔ --prefix=c:\,d:\,e:\
    	
  3. Switches can be consolidated (-baz → -b -a -z) any following options belong to the last switch in the consolidation
    		  -baz foo bar ↔ -b -a -z foo bar
    	
  4. You can use abbreviations for the full names of switches. The only caveat is that you must provide as much of the name as necessary to distinguish it from other likely switchnames. So if you have the switches --verbose and --version, --vers would be valid (it is clearly short for --version) but --v is unacceptable (is it --version or -verbose?).
Example of valid Argument/Option structure:
programname file1 file2 --prefix=c:\,d:\,e:\ --verb --vers -blah arg1 arg2
TODO: --Argument=option1,options2 option3 <---- This should not be allowed!


Constructor Summary
CommandLineArguments()
           
CommandLineArguments(Argument[] arguments)
           
CommandLineArguments(java.util.Collection arguments)
           
 
Method Summary
 void addArgument(Argument argument)
           
 java.util.List getOptions(char symbol)
           
 java.util.List getOptions(java.lang.String name)
           
 java.util.List getProgramOptions()
           
static void main(java.lang.String[] args)
           
 void processArguments(java.lang.String[] args)
           
 boolean switchUsed(char symbol)
           
 boolean switchUsed(java.lang.String name)
           
 java.lang.String usage()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandLineArguments

public CommandLineArguments()

CommandLineArguments

public CommandLineArguments(java.util.Collection arguments)

CommandLineArguments

public CommandLineArguments(Argument[] arguments)
Method Detail

addArgument

public void addArgument(Argument argument)

processArguments

public void processArguments(java.lang.String[] args)

switchUsed

public boolean switchUsed(char symbol)

switchUsed

public boolean switchUsed(java.lang.String name)

getOptions

public java.util.List getOptions(char symbol)

getOptions

public java.util.List getOptions(java.lang.String name)

getProgramOptions

public java.util.List getProgramOptions()

usage

public java.lang.String usage()

main

public static void main(java.lang.String[] args)