getopt in Java, TDD-style

There are a lot of libraries out there that perform the functions of POSIX/GNU getopt()/getopt_long() for Java: Jakarta Commons CLI, JArgs, GNU Getopt transliterated to Java...many of them with some fairly gnarly code in their innards. I'm not convinced that parsing command line arguments is such a gnarly problem.

Ultimately the real answer for Java programs probably is to wrap JVM invocations in a bash script, Perl/Python/Ruby script, something that can already parse options and translate them into Java system properties (-Dproperty=value).

However, I thought I'd see where TDD would lead my own implementation. This is a work in progress, and is subject to change without notice...if deemed useful enough, I'll do something more "official" with it. But for now, check out the code and see if you like it better than other solutions out there. Perhaps you'll be moved to try TDD on your next project.

Written on February 23, 2004