| The CLIPParser implements a Command Line User Interface parser following
the iPlanet UI Style Project Guide 2.1.
It parses the command line arguments according to the CLIP full specification.
Refer to the CLIP specification for more details.
CLIPParser instances are thread-safe.
CLIPParser example with sub commands:
import com.iplanet.common.util. CLIPParser;
import com.iplanet.common.util. CLIPException;
public class CLIPParserTest {
public static void main(String[] args) throws CLIPException {
CLIPParser.Option[] options0 = new CLIPParser.Option[2];
options0[0] = new CLIPParser.Option("user","u",CLIPParser.REGULAR,null,"user name");
options0[1] = new CLIPParser.Option("password","p",CLIPParser.REGULAR,null,"user password");
CLIPParser.Option[] options1 = new CLIPParser.Option[4];
options1[0] = new CLIPParser.Option("user","u",CLIPParser.REGULAR,null,"user name");
options1[1] = new CLIPParser.Option("password","p",CLIPParser.REGULAR,null,"user password");
options1[3] = new CLIPParser.Option("owner","o",CLIPParser.REGULAR,"user","elements owner");
options1[2] = new CLIPParser.Option("verbose","v",CLIPParser.BOOLEAN,"false","echoes actions");
CLIPParser.Option[] options2 = new CLIPParser.Option[3];
options2[0] = new CLIPParser.Option("user","u",CLIPParser.REGULAR,null,"user name");
options2[1] = new CLIPParser.Option("password","p",CLIPParser.REGULAR,null,"user password");
options2[2] = new CLIPParser.Option("verbose","v",CLIPParser.BOOLEAN,"false","echos actions");
CLIPParser.SubCommand[] subCommands = new CLIPParser.SubCommand[3];
subCommands[0] = new CLIPParser.SubCommand("list",options0,0,0,"Lists current elements","");
subCommands[1] = new CLIPParser.SubCommand("add",options1,1,10000,"Adds new elements","elements to add");
subCommands[2] = new CLIPParser.SubCommand("remove",options2,1,1000,"Removes existing elements","elemenst to remove");
CLIPParser clip = new CLIPParser(subCommands,"Super command (w/ sub commands)");
clip.verifyArguments(args);
if (clip.needsHelp(args)) {
System.out.println(clip.getHelp(args));
}
else {
System.out.println(clip.toString(args));
}
}
}
author: Alejandro Abdelnur |