Image

Unix-like command options in Java

Hi - for this thing I'm working on, I want to have unix-like command options. For instance, you could run the program as follows:
Program -file file.txt -idf idffile.txt -weighting j -corpus


And the reason I want to do this instead of just saying args[0] is the file name, args[1] is the idf file, args[2] is the weighting type, etc, is because some of these things are optional. For instance, a user might not want to use idf at all. And the -corpus means it is the corpus-based version, whereas leaving that off would be the non-corpus-based version.

And you probably dont' know what half that stuff means, but it doesn't matter - the point is, I want to do unix-like options.

Have you ever done this? How did you do it? My friend thinks I should have a separate class for each option, for instance, have a "idffile" class, and if I see -idf then I instantiate that class and pass idffile.txt as a member. I think this is serious overkill.

Also, one of my options needs two uh... parameters? like -stop stopfile.txt 300 - meaning read the first 300 lines of stopfile.txt - this file has about 1000 lines and I want to run it with different number of lines used to see the different outcomes as a result of this. Is there any good way to do this? Should I have -stop stopfile.txt -numstop 300, and just require that whenever you see -stop you also need to see -numstop (or else, I suppose, just assume you read the whole file)?

I've never tried to do this before, I've always assumed the parameters passed to a program would be static, which is easier but obviously not as flexible, and in this case would lead to a lot of dummy values for parameters that aren't used in a given run.

Thanks a bunch if you read al this, and thanks even more for any help you are willing/able to give. I'm getting ready for bed, so I'll be checking replies for a while, but if I dont' reply until tomorrow, please don't be offended - I probably just fell asleep.