I wrote one that takes:
Code:
java theProg -a value_for_a -b "value for b" "and now the final variable"
below is current code:
Code:
int argc = args.length;
if(0 == argc){
show("Usage error: no arguments specified.\r\n" + usage);
return;
}
for(int k = 0; k < argc; k++){
char _switch;
if(args[k].length() == 2 && '-' == args[k].charAt(0)){
_switch = args[k].charAt(1);
} else { // final argument
if('"' == args[k].charAt(0)){
StringBuffer tmp = new StringBuffer();
tmp.append(args[k]);
while(k < argc && args[k].charAt(args[k].length() - 1) != '"')
tmp.append(" " + args[++k]);
/**
* Consider using StringBuffer.getChars(0, len, char[], 0);
*/
path = new String( tmp );
path = new String( path.toCharArray(), 1, path.length() - 2 );
} else
path = args[k];
break;
}
switch(_switch){
case 'm': /** Mode specifed */
if(++k >= argc){
show("Usage error: mode not specified.");
return;
}
char tmp_mode = args[k].charAt(0);
switch(tmp_mode){
case 's':
mode = MODE_SINGLE;
break;
case 'd':
flags = FLAG_DIR_ONLY;
/** Fall through */
case 'm':
mode = MODE_MULTI;
break;
default:
show("Usage error: unknown mode \"" + tmp_mode + "\".");
return;
}
break;
/** case 'm' ends */
case 'h': /** Help requested */
show(usage);
return;
/** case 'h' ends */
case 'o': /** Output path specified */
if(++k >= argc){
show("Usage error: output path not specified.");
return;
}
if('"' == args[k].charAt(0)){
StringBuffer tmp = new StringBuffer();
tmp.append(args[k]);
while(k < argc && args[k].charAt(args[k].length() - 1) != '"')
tmp.append(" " + args[++k]);
new_out_path = new String( tmp );
new_out_path = new String( new_out_path.toCharArray(), 1, new_out_path.length() - 2 );
} else
new_out_path = args[k];
break;
/** case 'o' ends */
case 's': /** Current output directories requested */
show("\tCurrent output directories:");
show("\t\tLocal: " + LOCAL);
show("\t\tMulti: " + DOCPATH);
return;
/** case 's' ends */
case 'v': /** Version requested */
show("TBCA Version: " + VERSION);
return;
/** case 'v' ends */
default:
show("Usage error: unknown switch \"" + _switch + "\".");
return;
/** default case ends */
}
}