import gnu.getopt.Getopt;
public class CommandLineParser {
public static void main(String[] args) {
Getopt getopt = new Getopt("myProgram", args, "ab:c:");
int option;
String arg;
while ((option = getopt.getopt()) != -1) {
switch (option) {
case 'a':
System.out.println("Option -a is set");
break;
case 'b':
arg = getopt.getOptarg();
System.out.println("Option -b is set with argument: " + arg);
break;
case 'c':
arg = getopt.getOptarg();
System.out.println("Option -c is set with argument: " + arg);
break;
case '?':
System.out.println("Invalid option");
break;
default:
System.out.println("Unrecognized option");
break;
}
}
}
}